feat: add bulk file upload endpoints

This commit is contained in:
2025-12-04 16:00:24 +05:30
parent 7eabb1c473
commit c4b8d464f1
5 changed files with 98 additions and 2 deletions

View File

@@ -14,10 +14,13 @@ import {
getFile,
updateFile,
uploadDone,
uploadDoneBatch,
} from "./file.service";
import {
CreateFileInput,
CreateFilesBatch,
UpdateFileInput,
UploadDoneBatchInput,
UploadMultiPartCompleteRequest,
} from "./file.schema";
@@ -43,6 +46,31 @@ export async function createFileHandler(
}
}
export async function createFileBatchHandler(
req: FastifyRequest,
res: FastifyReply
) {
const input = req.body as CreateFilesBatch;
const resObj = [];
try {
for (const file of input.files) {
const newFile = (await createFile(file, req.user)).toObject();
if (newFile.mimeType != "folder") {
const signedUrl = await getUploadUrl(newFile.pid);
newFile["signedUrl"] = signedUrl;
}
resObj.push({ ...newFile });
}
return res.code(201).send(resObj);
} catch (err) {
return err;
}
}
export async function uploadDoneHandler(
req: FastifyRequest,
res: FastifyReply
@@ -57,6 +85,20 @@ export async function uploadDoneHandler(
}
}
export async function uploadDoneBatchHandler(
req: FastifyRequest,
res: FastifyReply
) {
const input = req.body as UploadDoneBatchInput;
try {
const updateRes = await uploadDoneBatch(input, req.user);
return res.code(200).send();
} catch (err) {
return err;
}
}
export async function getFileHandler(req: FastifyRequest, res: FastifyReply) {
const { fileId } = req.params as { fileId: string };