Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pages/api/report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ import { authOptions } from "../auth/[...nextauth]";
import { connectToDatabase } from "../../../lib/mongodb";
import DSReport from "../../../models/DSReport";

const ALLOWED_DOMAINS = ["zmcdsc.vercel.app", "dscs.ziggymc.me"];
const ALLOWED_DOMAINS = ["dscs.ziggymc.me", "invs.ziggymc.me", "ds.ziggymc.me", "d.ziggymc.me"];

export const config = {
api: {
bodyParser: {
sizeLimit: "6mb",
},
},
};
Comment on lines +8 to +14

export default async function handler(req, res) {
if (req.method !== "POST") {
Expand Down
29 changes: 15 additions & 14 deletions pages/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { authOptions } from "./api/auth/[...nextauth]";
import Layout from "../components/Layout";
import styles from "../styles/Report.module.css";

const ALLOWED_DOMAINS = ["zmcdsc.vercel.app", "dscs.ziggymc.me"];
const ALLOWED_DOMAINS = ["dscs.ziggymc.me", "invs.ziggymc.me", "ds.ziggymc.me", "d.ziggymc.me"];

export async function getServerSideProps({ req, res }) {
const session = await getServerSession(req, res, authOptions);
Expand Down Expand Up @@ -70,19 +70,20 @@ export default function ReportPage({ user }) {
try {
let imageUrl = null;

// Upload image if provided (base64 via FormData)
// Convert image to base64 data URL if provided (max 4 MB)
if (imageFile) {
const formData = new FormData();
formData.append("image", imageFile);
const uploadRes = await fetch("/api/report/upload", {
method: "POST",
body: formData,
});
if (uploadRes.ok) {
const uploadData = await uploadRes.json();
imageUrl = uploadData.url;
const MAX_IMAGE_BYTES = 4 * 1024 * 1024;
if (imageFile.size > MAX_IMAGE_BYTES) {
setError("Image must be 4 MB or smaller.");
setLoading(false);
return;
}
// If upload fails, proceed without image
imageUrl = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = () => reject(new Error("Failed to read image file."));
reader.readAsDataURL(imageFile);
});
Comment on lines +75 to +86
}

const res = await fetch("/api/report", {
Expand Down Expand Up @@ -162,7 +163,7 @@ export default function ReportPage({ user }) {
setReportedLink(e.target.value);
setError("");
}}
placeholder={`https://dscs.ziggymc.me/abc123`}
placeholder={`https://ds.ziggymc.me/abc123`}
className={styles.input}
required
/>
Expand Down Expand Up @@ -190,7 +191,7 @@ export default function ReportPage({ user }) {
{/* Optional image */}
<div className={styles.fieldGroup}>
<label className={styles.fieldLabel} htmlFor="image-upload">
Supporting image (optional)
Supporting image (optional, max 4 MB)
</label>
<input
id="image-upload"
Expand Down
Loading