mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
assets and tier plans revamp
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
+33
-1
@@ -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,
|
||||
};
|
||||
Reference in New Issue
Block a user