assets and tier plans revamp

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-08-01 17:44:25 +08:00
parent 39c3c4566b
commit cae958b5d5
41 changed files with 1271 additions and 165 deletions
+33 -1
View File
@@ -184,6 +184,38 @@ async function uploadFile({ buffer, originalname, mimetype, ownerType = "image",
};
}
// ─── uploadStream ─────────────────────────────────────────────────────────────
//
// Same as uploadFile(), but Body is a Node Readable stream instead of a
// Buffer — used by assetTranscode.service.js to push a remuxed video back to
// storage straight off local disk, without ever holding the whole (possibly
// multi-GB) file in this process's memory. Upload (lib-storage) auto-chunks
// a stream body into multipart the same way it does a large Buffer.
//
// input: { stream, originalname, mimetype, ownerType? }
// output: { url, uuid } ← uuid = the S3 key, stored as storage_key in DB
//
async function uploadStream({ stream, originalname, mimetype, ownerType = "video" }) {
if (!stream) {
throw Object.assign(new Error("A readable stream is required for S3 uploads."), { status: 400 });
}
const bucket = DEFAULT_BUCKET;
const key = buildKey(originalname, ownerType);
const uploader = new Upload({
client: s3,
params: { Bucket: bucket, Key: key, Body: stream, ContentType: mimetype },
});
await uploader.done();
return {
url: await buildPublicUrl(key, bucket),
uuid: key,
};
}
// ─── deleteFile ───────────────────────────────────────────────────────────────
//
// Matches chibisafe.service.js interface.
@@ -412,7 +444,7 @@ async function getFileMetadata(key) {
}
module.exports = {
uploadFile, deleteFile, getSignedDownloadUrl, getPublicUrl, getObjectStream,
uploadFile, uploadStream, deleteFile, getSignedDownloadUrl, getPublicUrl, getObjectStream,
presignUpload, completeMultipartUpload, abortMultipartUpload,
getFileMetadata, buildPublicUrl, ping,
};