multi-file update
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user