mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-18 06:54:15 +00:00
handle progress of putObject s3
This commit is contained in:
parent
92051c4d3a
commit
efc309ed6a
@ -132,6 +132,7 @@ export default class Upload {
|
||||
metadata: metadata,
|
||||
targetFilename: isDirectory ? path.basename(targetPath) : null,
|
||||
provider: s3Provider,
|
||||
onProgress: onProgress,
|
||||
})
|
||||
|
||||
return result
|
||||
|
@ -8,6 +8,7 @@ export default async function putObject({
|
||||
metadata = {},
|
||||
targetFilename,
|
||||
onFinish,
|
||||
onProgress,
|
||||
provider = "standard",
|
||||
}) {
|
||||
const providerClass = global.storages[provider]
|
||||
@ -22,6 +23,18 @@ export default async function putObject({
|
||||
|
||||
if (isDirectory) {
|
||||
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) => {
|
||||
const newPath = path.join(filePath, file)
|
||||
@ -29,6 +42,8 @@ export default async function putObject({
|
||||
return {
|
||||
filePath: newPath,
|
||||
uploadPath: path.join(uploadPath, file),
|
||||
provider: provider,
|
||||
onFinish: handleProgress,
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user