fix: stream FilePond uploads to S3 and proxy private file previews
Disk-based multer plus an authenticated content endpoint match the working Node.js uploader and avoid browser signed-URL failures on SeaweedFS.
This commit is contained in:
@@ -17,7 +17,11 @@ const BUCKET = 'documents';
|
||||
const withAccessUrl = async (doc) => {
|
||||
const item = typeof doc.toObject === 'function' ? doc.toObject() : { ...doc };
|
||||
item.fileUrl = item.fileUrl || null;
|
||||
item.signedUrl = await generatePresignedUrl(item.fileKey, item.bucket || config.S3_DOCUMENTS_BUCKET);
|
||||
try {
|
||||
item.signedUrl = await generatePresignedUrl(item.fileKey, item.bucket || config.S3_DOCUMENTS_BUCKET);
|
||||
} catch {
|
||||
item.signedUrl = null;
|
||||
}
|
||||
item.presignedUrl = item.signedUrl;
|
||||
item.url = item.fileUrl || item.signedUrl;
|
||||
return item;
|
||||
@@ -29,7 +33,7 @@ const createDocument = async (data, uploadedBy = null) => {
|
||||
if (!data.tempFileName) throw new AppError('FILE_REQUIRED');
|
||||
|
||||
const safeName = path.basename(data.tempFileName);
|
||||
const targetKey = `documents/doc-${Date.now()}-${safeName}`;
|
||||
const targetKey = `doc-${Date.now()}-${safeName}`;
|
||||
const { fileKey, bucket, fileUrl } = await commitTempFile(data.tempFileName, targetKey, BUCKET);
|
||||
|
||||
const document = await Document.create({
|
||||
@@ -87,7 +91,7 @@ const updateDocument = async (id, updateData) => {
|
||||
|
||||
if (updateData.tempFileName) {
|
||||
const safeName = path.basename(updateData.tempFileName);
|
||||
const targetKey = `documents/doc-${Date.now()}-${safeName}`;
|
||||
const targetKey = `doc-${Date.now()}-${safeName}`;
|
||||
const { fileKey, bucket, fileUrl } = await commitTempFile(updateData.tempFileName, targetKey, BUCKET);
|
||||
await deleteFromBucket(document.fileKey, document.bucket || config.S3_DOCUMENTS_BUCKET);
|
||||
document.fileKey = fileKey;
|
||||
|
||||
Reference in New Issue
Block a user