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:
2026-08-15 18:46:26 +03:30
parent 7ebf9409f0
commit 1ef54ad414
9 changed files with 173 additions and 30 deletions
@@ -15,7 +15,11 @@ const BUCKET = 'certificates';
const withAccessUrl = async (cert) => {
const item = typeof cert.toObject === 'function' ? cert.toObject() : { ...cert };
item.fileUrl = item.fileUrl || null;
item.signedUrl = await generatePresignedUrl(item.fileKey, item.bucket || config.S3_CERTIFICATES_BUCKET);
try {
item.signedUrl = await generatePresignedUrl(item.fileKey, item.bucket || config.S3_CERTIFICATES_BUCKET);
} catch {
item.signedUrl = null;
}
item.presignedUrl = item.signedUrl;
item.url = item.fileUrl || item.signedUrl;
return item;
@@ -27,7 +31,7 @@ const createCertificate = async (data) => {
if (!data.tempFileName) throw new AppError('FILE_REQUIRED');
const safeName = path.basename(data.tempFileName);
const targetKey = `certificates/cert-${Date.now()}-${safeName}`;
const targetKey = `cert-${Date.now()}-${safeName}`;
const { fileKey, bucket, fileUrl } = await commitTempFile(data.tempFileName, targetKey, BUCKET);
const fileName = data.originalName || data.fileName || safeName;
@@ -93,7 +97,7 @@ const updateCertificate = async (id, updateData) => {
if (updateData.tempFileName) {
const safeName = path.basename(updateData.tempFileName);
const targetKey = `certificates/cert-${Date.now()}-${safeName}`;
const targetKey = `cert-${Date.now()}-${safeName}`;
const { fileKey, bucket, fileUrl } = await commitTempFile(updateData.tempFileName, targetKey, BUCKET);
await deleteFromBucket(certificate.fileKey, certificate.bucket || config.S3_CERTIFICATES_BUCKET);
certificate.fileKey = fileKey;