mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
improve handler
This commit is contained in:
parent
7c193e885b
commit
09c349f66e
@ -18,6 +18,7 @@ export default async ({
|
|||||||
transmux,
|
transmux,
|
||||||
transmuxOptions,
|
transmuxOptions,
|
||||||
isDirectory,
|
isDirectory,
|
||||||
|
onProgress,
|
||||||
}) => {
|
}) => {
|
||||||
if (!source) {
|
if (!source) {
|
||||||
throw new OperationError(500, "source is required")
|
throw new OperationError(500, "source is required")
|
||||||
@ -36,6 +37,12 @@ export default async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (useCompression) {
|
if (useCompression) {
|
||||||
|
if (typeof onProgress === "function") {
|
||||||
|
onProgress(10, {
|
||||||
|
event: "post_processing",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const processOutput = await PostProcess({
|
const processOutput = await PostProcess({
|
||||||
filepath: source,
|
filepath: source,
|
||||||
@ -54,12 +61,18 @@ export default async ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (transmux) {
|
if (transmux) {
|
||||||
|
if (typeof onProgress === "function") {
|
||||||
|
onProgress(30, {
|
||||||
|
event: "transmuxing",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const processOutput = await Transmux({
|
const processOutput = await Transmux({
|
||||||
transmuxer: transmux,
|
transmuxer: transmux,
|
||||||
transmuxOptions: transmuxOptions,
|
transmuxOptions: transmuxOptions,
|
||||||
filepath: source,
|
filepath: source,
|
||||||
cachePath: cachePath
|
cachePath: cachePath,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (processOutput) {
|
if (processOutput) {
|
||||||
@ -80,7 +93,14 @@ export default async ({
|
|||||||
const type = mimeTypes.lookup(path.basename(source))
|
const type = mimeTypes.lookup(path.basename(source))
|
||||||
const hash = await getFileHash(fs.createReadStream(source))
|
const hash = await getFileHash(fs.createReadStream(source))
|
||||||
|
|
||||||
const remotePath = path.join(parentDir, hash)
|
let fileId = `${hash}`
|
||||||
|
|
||||||
|
// FIXME: This is a walkaround to avoid to hashing the entire directories
|
||||||
|
if (isDirectory) {
|
||||||
|
fileId = global.nanoid()
|
||||||
|
}
|
||||||
|
|
||||||
|
let remotePath = path.join(parentDir, fileId)
|
||||||
|
|
||||||
let result = {}
|
let result = {}
|
||||||
|
|
||||||
@ -89,11 +109,21 @@ export default async ({
|
|||||||
"File-Hash": hash,
|
"File-Hash": hash,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof onProgress === "function") {
|
||||||
|
onProgress(80, {
|
||||||
|
event: "uploading_s3",
|
||||||
|
service: service,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (service) {
|
switch (service) {
|
||||||
case "b2":
|
case "b2":
|
||||||
if (!global.b2Storage) {
|
if (!global.b2Storage) {
|
||||||
throw new OperationError(500, "B2 storage not configured on environment, unsupported service. Please use `standard` service.")
|
throw new OperationError(
|
||||||
|
500,
|
||||||
|
"B2 storage not configured on environment, unsupported service. Please use `standard` service.",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
result = await B2Upload({
|
result = await B2Upload({
|
||||||
@ -121,5 +151,12 @@ export default async ({
|
|||||||
throw new OperationError(500, "Failed to upload to storage")
|
throw new OperationError(500, "Failed to upload to storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof onProgress === "function") {
|
||||||
|
onProgress(100, {
|
||||||
|
event: "done",
|
||||||
|
result: result,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user