multi-file update

This commit is contained in:
jason
2026-03-13 11:13:45 -05:00
parent 5e3ca19c83
commit b2df27cfc5
6 changed files with 52 additions and 13 deletions
+16 -10
View File
@@ -5,7 +5,7 @@ export const runtime = "nodejs";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { uploadToDrive, generateReportMarkdown } from "@/lib/google-drive";
import { uploadToDrive, updateDriveFile, generateReportMarkdown } from "@/lib/google-drive";
export async function POST(
req: Request,
@@ -46,17 +46,23 @@ export async function POST(
});
try {
const driveFile = await uploadToDrive(
account.access_token,
fileName,
markdown,
folderSetting?.value
);
// Update report status to SUBMITTED
let driveFile;
if (report.driveFileId) {
// Update the existing Drive file in place
driveFile = await updateDriveFile(account.access_token, report.driveFileId, markdown);
} else {
// First export — create a new Drive file and store its ID
driveFile = await uploadToDrive(account.access_token, fileName, markdown, folderSetting?.value);
await prisma.report.update({
where: { id },
data: { driveFileId: driveFile.id },
});
}
await prisma.report.update({
where: { id },
data: { status: 'SUBMITTED' }
data: { status: 'SUBMITTED' },
});
return NextResponse.json({ success: true, link: driveFile.webViewLink });