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,
|
metadata: metadata,
|
||||||
targetFilename: isDirectory ? path.basename(targetPath) : null,
|
targetFilename: isDirectory ? path.basename(targetPath) : null,
|
||||||
provider: s3Provider,
|
provider: s3Provider,
|
||||||
|
onProgress: onProgress,
|
||||||
})
|
})
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
@ -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,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user