Minor changes
This commit is contained in:
parent
68ac241106
commit
0856fc209a
@ -1,6 +1,6 @@
|
||||
import AnimeNotifier from "../AnimeNotifier"
|
||||
import StatusMessage from "../StatusMessage"
|
||||
import { bytesHumanReadable, fetchWithProgress } from "../Utils"
|
||||
import { bytesHumanReadable, uploadWithProgress } from "../Utils"
|
||||
|
||||
// Select file
|
||||
export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
|
||||
@ -65,7 +65,7 @@ function uploadFile(file: File, fileType: string, endpoint: string, arn: AnimeNo
|
||||
arn.statusMessage.showInfo(`Preparing to upload ${fileType} (${bytesHumanReadable(fileSize)})`, -1)
|
||||
|
||||
try {
|
||||
let responseText = await fetchWithProgress(endpoint, {
|
||||
let responseText = await uploadWithProgress(endpoint, {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
headers: {
|
||||
|
@ -1,12 +1,15 @@
|
||||
export function fetchWithProgress(url, options: RequestInit, onProgress: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null): Promise<string> {
|
||||
export function uploadWithProgress(url, options: RequestInit, onProgress: ((ev: ProgressEvent) => any) | null): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
|
||||
xhr.addEventListener("load", e => resolve(xhr.responseText))
|
||||
xhr.addEventListener("error", reject)
|
||||
xhr.onload = e => resolve(xhr.responseText)
|
||||
xhr.onerror = reject
|
||||
|
||||
if(onProgress && xhr.upload) {
|
||||
xhr.upload.addEventListener("progress", onProgress)
|
||||
xhr.upload.onprogress = onProgress
|
||||
xhr.upload.onerror = reject
|
||||
} else {
|
||||
console.error("Could not attach progress event listener")
|
||||
}
|
||||
|
||||
xhr.open(options.method || "GET", url, true)
|
||||
|
Loading…
Reference in New Issue
Block a user