handle progress of putObject s3

This commit is contained in:
SrGooglo 2025-06-16 20:39:49 +00:00
parent 92051c4d3a
commit efc309ed6a
2 changed files with 16 additions and 0 deletions

View File

@ -132,6 +132,7 @@ export default class Upload {
metadata: metadata, metadata: metadata,
targetFilename: isDirectory ? path.basename(targetPath) : null, targetFilename: isDirectory ? path.basename(targetPath) : null,
provider: s3Provider, provider: s3Provider,
onProgress: onProgress,
}) })
return result return result

View File

@ -8,6 +8,7 @@ export default async function putObject({
metadata = {}, metadata = {},
targetFilename, targetFilename,
onFinish, onFinish,
onProgress,
provider = "standard", provider = "standard",
}) { }) {
const providerClass = global.storages[provider] const providerClass = global.storages[provider]
@ -22,6 +23,18 @@ export default async function putObject({
if (isDirectory) { if (isDirectory) {
let files = await fs.promises.readdir(filePath) let files = await fs.promises.readdir(filePath)
let count = 0
const handleProgress = () => {
if (typeof onProgress === "function") {
count = count + 1
onProgress({
percent: Math.round((count / files.length) * 100),
state: "uploading_s3",
})
}
}
files = files.map((file) => { files = files.map((file) => {
const newPath = path.join(filePath, file) const newPath = path.join(filePath, file)
@ -29,6 +42,8 @@ export default async function putObject({
return { return {
filePath: newPath, filePath: newPath,
uploadPath: path.join(uploadPath, file), uploadPath: path.join(uploadPath, file),
provider: provider,
onFinish: handleProgress,
} }
}) })