mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-07-24 07:42:47 +00:00
feat: file upload from UI, notification dismiss, audit false positive fix
Manual file upload:
- Upload dialog in STL page with drag-and-drop file picker
- Files saved to shared Docker volume (/data/uploads)
- Worker processes via pg_notify('manual_upload') channel
- Hashes, reads metadata, splits >2GB, uploads to Telegram
- Multiple files automatically grouped
- Status polling shows upload/processing/complete states
Notification fixes:
- Add dismiss (X) button on each notification
- Add "Clear" button to remove all notifications
- Fix false positive MISSING_PART alerts from legacy packages
(only flag when >1 destMessageIds stored but count wrong,
not when only 1 ID from backfill)
Infrastructure:
- ManualUpload + ManualUploadFile schema + migration
- Shared manual_uploads Docker volume between app and worker
- Upload API routes (POST /api/uploads, GET /api/uploads/[id])
- Worker manual-upload processor with full pipeline
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@ import { auth } from "@/lib/auth";
|
||||
import {
|
||||
markNotificationRead,
|
||||
markAllNotificationsRead,
|
||||
dismissNotification,
|
||||
clearAllNotifications,
|
||||
} from "@/data/notification.queries";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -15,8 +17,13 @@ export async function POST(request: Request) {
|
||||
|
||||
const body = await request.json().catch(() => ({}));
|
||||
const id = body.id as string | undefined;
|
||||
const action = (body.action as string) ?? "read";
|
||||
|
||||
if (id) {
|
||||
if (action === "dismiss" && id) {
|
||||
await dismissNotification(id);
|
||||
} else if (action === "clear") {
|
||||
await clearAllNotifications();
|
||||
} else if (id) {
|
||||
await markNotificationRead(id);
|
||||
} else {
|
||||
await markAllNotificationsRead();
|
||||
|
||||
43
src/app/api/uploads/[id]/route.ts
Normal file
43
src/app/api/uploads/[id]/route.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
_request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
const upload = await prisma.manualUpload.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
files: {
|
||||
select: { id: true, fileName: true, fileSize: true, packageId: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!upload || upload.userId !== session.user.id) {
|
||||
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
id: upload.id,
|
||||
status: upload.status,
|
||||
groupName: upload.groupName,
|
||||
errorMessage: upload.errorMessage,
|
||||
files: upload.files.map((f) => ({
|
||||
...f,
|
||||
fileSize: f.fileSize.toString(),
|
||||
})),
|
||||
createdAt: upload.createdAt.toISOString(),
|
||||
completedAt: upload.completedAt?.toISOString() ?? null,
|
||||
});
|
||||
}
|
||||
83
src/app/api/uploads/route.ts
Normal file
83
src/app/api/uploads/route.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { writeFile, mkdir } from "fs/promises";
|
||||
import path from "path";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const UPLOAD_DIR = process.env.UPLOAD_DIR ?? "/data/uploads";
|
||||
const MAX_FILE_SIZE = 4 * 1024 * 1024 * 1024; // 4GB per file
|
||||
|
||||
export async function POST(request: Request) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const formData = await request.formData();
|
||||
const files = formData.getAll("files") as File[];
|
||||
const groupName = formData.get("groupName") as string | null;
|
||||
|
||||
if (!files.length) {
|
||||
return NextResponse.json({ error: "No files provided" }, { status: 400 });
|
||||
}
|
||||
|
||||
// Create the upload record
|
||||
const upload = await prisma.manualUpload.create({
|
||||
data: {
|
||||
userId: session.user.id,
|
||||
groupName: groupName || (files.length > 1 ? files[0].name.replace(/\.[^.]+$/, "") : null),
|
||||
status: "PENDING",
|
||||
},
|
||||
});
|
||||
|
||||
// Save files to shared volume
|
||||
const uploadDir = path.join(UPLOAD_DIR, upload.id);
|
||||
await mkdir(uploadDir, { recursive: true });
|
||||
|
||||
for (const file of files) {
|
||||
if (file.size > MAX_FILE_SIZE) {
|
||||
return NextResponse.json(
|
||||
{ error: `File "${file.name}" exceeds 4GB limit` },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const filePath = path.join(uploadDir, file.name);
|
||||
const buffer = Buffer.from(await file.arrayBuffer());
|
||||
await writeFile(filePath, buffer);
|
||||
|
||||
await prisma.manualUploadFile.create({
|
||||
data: {
|
||||
uploadId: upload.id,
|
||||
fileName: file.name,
|
||||
filePath,
|
||||
fileSize: BigInt(file.size),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Notify worker
|
||||
try {
|
||||
await prisma.$queryRawUnsafe(
|
||||
`SELECT pg_notify('manual_upload', $1)`,
|
||||
upload.id
|
||||
);
|
||||
} catch {
|
||||
// Best-effort
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
uploadId: upload.id,
|
||||
fileCount: files.length,
|
||||
status: "PENDING",
|
||||
});
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{ error: err instanceof Error ? err.message : "Upload failed" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user