feat: probably improved single object S3 upload

pull/243/head
Josh Moore 1 year ago
parent b852a95dcd
commit 8487089209

@ -57,7 +57,7 @@ router.post('/', async (req, res) => {
// * Move the file
if (!s3) await fs.move(bbFile.file, destination);
else await uploadFileS3(await fs.readFile(bbFile.file), bbFile.mimetype, fileKey);
else await uploadFileS3(await fs.readFile(bbFile.file), fileKey, bbFile.mimetype, size, sha256);
// Build ass metadata
const assFile: AssFile = {

@ -53,12 +53,14 @@ const s3 = (): S3Client | null => {
/**
* Basic single file upload
*/
const doObjectUpload = (file: Buffer, mimetype: string, fileKey: string): Promise<PutObjectCommandOutput> =>
const doObjectUpload = (file: Buffer, fileKey: string, mimetype: string, size: number, sha256: string): Promise<PutObjectCommandOutput> =>
new Promise((resolve, reject) => s3()!.send(new PutObjectCommand({
Bucket: UserConfig.config.s3!.bucket,
Key: fileKey,
ContentType: mimetype,
Body: new Uint8Array(file)
ContentLength: size,
Body: new Uint8Array(file),
ChecksumSHA256: sha256
})).then(resolve).catch(reject));
/**
@ -129,12 +131,12 @@ const doMultipartUpload = (file: Buffer, mimetype: string, fileKey: string): Pro
/**
* Uploads a file to your configured S3 provider
*/
export const uploadFileS3 = (file: Buffer, mimetype: string, fileKey: string): Promise<void> => new Promise(async (resolve, reject) => {
export const uploadFileS3 = (file: Buffer, fileKey: string, mimetype: string, size: number, sha256: string): Promise<void> => new Promise(async (resolve, reject) => {
if (!s3readyCheck) return reject(NYR);
try {
// todo: determine when to do multipart uplloads
await doObjectUpload(file, mimetype, fileKey);
await doObjectUpload(file, fileKey, mimetype, size, sha256);
resolve(void 0);
} catch (err) {
log.error('Failed to upload object to S3', fileKey);

Loading…
Cancel
Save