mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
update deps
This commit is contained in:
parent
d50ba06a55
commit
5d4c25c413
@ -41,6 +41,7 @@
|
|||||||
"bear-react-carousel": "^4.0.10-alpha.0",
|
"bear-react-carousel": "^4.0.10-alpha.0",
|
||||||
"capacitor-music-controls-plugin-v3": "^1.1.0",
|
"capacitor-music-controls-plugin-v3": "^1.1.0",
|
||||||
"classnames": "2.3.1",
|
"classnames": "2.3.1",
|
||||||
|
"dashjs": "^4.7.4",
|
||||||
"dompurify": "^3.0.0",
|
"dompurify": "^3.0.0",
|
||||||
"fast-average-color": "^9.2.0",
|
"fast-average-color": "^9.2.0",
|
||||||
"framer-motion": "^10.12.17",
|
"framer-motion": "^10.12.17",
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { EventBus } from "@ragestudio/vessel"
|
import { EventBus } from "@ragestudio/vessel"
|
||||||
import { events, stream } from "fetch-event-stream"
|
|
||||||
|
|
||||||
export default class ChunkedUpload {
|
export default class ChunkedUpload {
|
||||||
constructor(params) {
|
constructor(params) {
|
||||||
@ -16,7 +15,7 @@ export default class ChunkedUpload {
|
|||||||
throw new Error("Missing endpoint")
|
throw new Error("Missing endpoint")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!file instanceof File) {
|
if ((!file) instanceof File) {
|
||||||
throw new Error("Invalid or missing file")
|
throw new Error("Invalid or missing file")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,8 +45,8 @@ export default class ChunkedUpload {
|
|||||||
"uploader-file-id": this.getFileUID(file),
|
"uploader-file-id": this.getFileUID(file),
|
||||||
"uploader-chunks-total": this.totalChunks,
|
"uploader-chunks-total": this.totalChunks,
|
||||||
"chunk-size": splitChunkSize,
|
"chunk-size": splitChunkSize,
|
||||||
"Connection": "keep-alive",
|
Connection: "keep-alive",
|
||||||
"Cache-Control": "no-cache"
|
"Cache-Control": "no-cache",
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setupListeners()
|
this.setupListeners()
|
||||||
@ -56,7 +55,7 @@ export default class ChunkedUpload {
|
|||||||
console.debug("[Uploader] Created", {
|
console.debug("[Uploader] Created", {
|
||||||
splitChunkSize: splitChunkSize,
|
splitChunkSize: splitChunkSize,
|
||||||
totalChunks: this.totalChunks,
|
totalChunks: this.totalChunks,
|
||||||
totalSize: file.size
|
totalSize: file.size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +63,27 @@ export default class ChunkedUpload {
|
|||||||
events = new EventBus()
|
events = new EventBus()
|
||||||
|
|
||||||
setupListeners() {
|
setupListeners() {
|
||||||
window.addEventListener("online", () => !this.offline && (this.offline = false, this.events.emit("online"), this.nextSend()))
|
window.addEventListener(
|
||||||
window.addEventListener("offline", () => (this.offline = true, this.events.emit("offline")))
|
"online",
|
||||||
|
() =>
|
||||||
|
!this.offline &&
|
||||||
|
((this.offline = false),
|
||||||
|
this.events.emit("online"),
|
||||||
|
this.nextSend()),
|
||||||
|
)
|
||||||
|
window.addEventListener(
|
||||||
|
"offline",
|
||||||
|
() => ((this.offline = true), this.events.emit("offline")),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
getFileUID(file) {
|
getFileUID(file) {
|
||||||
return Math.floor(Math.random() * 100000000) + Date.now() + file.size + "_tmp"
|
return (
|
||||||
|
Math.floor(Math.random() * 100000000) +
|
||||||
|
Date.now() +
|
||||||
|
file.size +
|
||||||
|
"_tmp"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
loadChunk() {
|
loadChunk() {
|
||||||
@ -77,7 +91,12 @@ export default class ChunkedUpload {
|
|||||||
const start = this.chunkCount * this.splitChunkSize
|
const start = this.chunkCount * this.splitChunkSize
|
||||||
const end = Math.min(start + this.splitChunkSize, this.file.size)
|
const end = Math.min(start + this.splitChunkSize, this.file.size)
|
||||||
|
|
||||||
this._reader.onload = () => resolve(new Blob([this._reader.result], { type: "application/octet-stream" }))
|
this._reader.onload = () =>
|
||||||
|
resolve(
|
||||||
|
new Blob([this._reader.result], {
|
||||||
|
type: "application/octet-stream",
|
||||||
|
}),
|
||||||
|
)
|
||||||
this._reader.readAsArrayBuffer(this.file.slice(start, end))
|
this._reader.readAsArrayBuffer(this.file.slice(start, end))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -95,14 +114,11 @@ export default class ChunkedUpload {
|
|||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(
|
const res = await fetch(this.endpoint, {
|
||||||
this.endpoint,
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: form,
|
body: form,
|
||||||
},
|
})
|
||||||
)
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -114,9 +130,15 @@ export default class ChunkedUpload {
|
|||||||
if (++this.retriesCount < this.maxRetries) {
|
if (++this.retriesCount < this.maxRetries) {
|
||||||
setTimeout(() => this.nextSend(), this.delayBeforeRetry * 1000)
|
setTimeout(() => this.nextSend(), this.delayBeforeRetry * 1000)
|
||||||
|
|
||||||
this.events.emit("fileRetry", { message: `Retrying chunk ${this.chunkCount}`, chunk: this.chunkCount, retriesLeft: this.retries - this.retriesCount })
|
this.events.emit("fileRetry", {
|
||||||
|
message: `Retrying chunk ${this.chunkCount}`,
|
||||||
|
chunk: this.chunkCount,
|
||||||
|
retriesLeft: this.retries - this.retriesCount,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
this.events.emit("error", { message: `No more retries for chunk ${this.chunkCount}` })
|
this.events.emit("error", {
|
||||||
|
message: `No more retries for chunk ${this.chunkCount}`,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +165,10 @@ export default class ChunkedUpload {
|
|||||||
// check if is the last chunk, if so, handle sse events
|
// check if is the last chunk, if so, handle sse events
|
||||||
if (this.chunkCount === this.totalChunks) {
|
if (this.chunkCount === this.totalChunks) {
|
||||||
if (data.eventChannelURL) {
|
if (data.eventChannelURL) {
|
||||||
console.log(`[UPLOADER] Connecting to SSE channel >`, data.eventChannelURL)
|
console.log(
|
||||||
|
`[UPLOADER] Connecting to SSE channel >`,
|
||||||
|
data.eventChannelURL,
|
||||||
|
)
|
||||||
|
|
||||||
const eventSource = new EventSource(data.eventChannelURL)
|
const eventSource = new EventSource(data.eventChannelURL)
|
||||||
|
|
||||||
@ -182,12 +207,16 @@ export default class ChunkedUpload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.events.emit("progress", {
|
this.events.emit("progress", {
|
||||||
percentProgress: Math.round((100 / this.totalChunks) * this.chunkCount)
|
percentProgress: Math.round(
|
||||||
|
(100 / this.totalChunks) * this.chunkCount,
|
||||||
|
),
|
||||||
})
|
})
|
||||||
} else if ([408, 502, 503, 504].includes(res.status)) {
|
} else if ([408, 502, 503, 504].includes(res.status)) {
|
||||||
this.manageRetries()
|
this.manageRetries()
|
||||||
} else {
|
} else {
|
||||||
this.events.emit("error", { message: `[${res.status}] ${data.error ?? data.message}` })
|
this.events.emit("error", {
|
||||||
|
message: `[${res.status}] ${data.error ?? data.message}`,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user