IO-2433 Basic completion webhook, S3 upload, audit trail.
This commit is contained in:
@@ -94,6 +94,47 @@ const generateSignedUploadUrls = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Upload a file buffer directly to S3.
|
||||
* Accepts either `req.file.buffer` (e.g. from multer) or `req.body.buffer` (base64 string).
|
||||
*/
|
||||
const uploadFileBuffer = async ({ key, contentType, buffer }) => {
|
||||
try {
|
||||
|
||||
|
||||
if (!key) {
|
||||
throw new Error("key is required");
|
||||
}
|
||||
if (!buffer) {
|
||||
throw new Error("buffer is required");
|
||||
}
|
||||
|
||||
const isPdf = key.toLowerCase().endsWith(".pdf");
|
||||
const client = new S3Client({ region: InstanceRegion() });
|
||||
|
||||
const putParams = {
|
||||
Bucket: imgproxyDestinationBucket,
|
||||
Key: key,
|
||||
Body: buffer,
|
||||
StorageClass: "INTELLIGENT_TIERING"
|
||||
};
|
||||
|
||||
if (contentType) {
|
||||
putParams.ContentType = contentType;
|
||||
} else if (isPdf) {
|
||||
putParams.ContentType = "application/pdf";
|
||||
}
|
||||
|
||||
await client.send(new PutObjectCommand(putParams));
|
||||
|
||||
|
||||
return ({ success: true, key, bucket: imgproxyDestinationBucket });
|
||||
} catch (error) {
|
||||
|
||||
return { success: false, message: error.message, stack: error.stack };
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get Thumbnail URLS
|
||||
* @param req
|
||||
@@ -500,6 +541,7 @@ const keyStandardize = (doc) => {
|
||||
|
||||
module.exports = {
|
||||
generateSignedUploadUrls,
|
||||
uploadFileBuffer,
|
||||
getThumbnailUrls,
|
||||
getOriginalImageByDocumentId,
|
||||
downloadFiles,
|
||||
|
||||
Reference in New Issue
Block a user