fix upload queue

This commit is contained in:
SrGooglo 2023-07-05 19:02:04 +00:00
parent 76267ef0e6
commit a5ffd235fd

View File

@ -9,6 +9,7 @@ class ChunkedUpload {
this.headers = params.headers || {} this.headers = params.headers || {}
this.postParams = params.postParams this.postParams = params.postParams
this.chunkSize = params.chunkSize || 1000000 this.chunkSize = params.chunkSize || 1000000
this.service = params.service ?? "default"
this.retries = params.retries ?? app.cores.settings.get("uploader.retries") ?? 3 this.retries = params.retries ?? app.cores.settings.get("uploader.retries") ?? 3
this.delayBeforeRetry = params.delayBeforeRetry || 5 this.delayBeforeRetry = params.delayBeforeRetry || 5
@ -24,6 +25,7 @@ class ChunkedUpload {
this.headers["uploader-original-name"] = encodeURIComponent(this.file.name) this.headers["uploader-original-name"] = encodeURIComponent(this.file.name)
this.headers["uploader-file-id"] = this.uniqid(this.file) this.headers["uploader-file-id"] = this.uniqid(this.file)
this.headers["uploader-chunks-total"] = this.totalChunks this.headers["uploader-chunks-total"] = this.totalChunks
this.headers["provider-type"] = this.service
this._reader = new FileReader() this._reader = new FileReader()
this.eventBus = new EventBus() this.eventBus = new EventBus()
@ -188,6 +190,7 @@ export default class RemoteStorage extends Core {
onProgress = () => { }, onProgress = () => { },
onFinish = () => { }, onFinish = () => { },
onError = () => { }, onError = () => { },
service = "default",
} = {}, } = {},
) { ) {
const apiEndpoint = app.cores.api.instance().instances.files.getUri() const apiEndpoint = app.cores.api.instance().instances.files.getUri()
@ -195,12 +198,13 @@ export default class RemoteStorage extends Core {
// TODO: get value from settings // TODO: get value from settings
const chunkSize = 2 * 1000 * 1000 // 10MB const chunkSize = 2 * 1000 * 1000 // 10MB
return new Promise((resolve, reject) => { return new Promise((_resolve, _reject) => {
app.cores.tasksQueue.appendToQueue(`upload_${file.name}`, async () => { const fn = async () => new Promise((resolve, reject) => {
const uploader = new ChunkedUpload({ const uploader = new ChunkedUpload({
endpoint: `${apiEndpoint}/upload/chunk`, endpoint: `${apiEndpoint}/upload/chunk`,
chunkSize: chunkSize, chunkSize: chunkSize,
file: file, file: file,
service: service,
}) })
uploader.on("error", ({ message }) => { uploader.on("error", ({ message }) => {
@ -211,6 +215,7 @@ export default class RemoteStorage extends Core {
} }
reject(message) reject(message)
_reject(message)
}) })
uploader.on("progress", ({ percentProgress }) => { uploader.on("progress", ({ percentProgress }) => {
@ -229,8 +234,11 @@ export default class RemoteStorage extends Core {
} }
resolve(data) resolve(data)
_resolve(data)
}) })
}) })
app.cores.tasksQueue.appendToQueue(`upload_${file.name}`, fn)
}) })
} }
} }