Fix uploader not working because window.user was removed
This commit is contained in:
@@ -10,21 +10,23 @@
|
||||
// on_error is called when the upload has failed. The parameters are the error
|
||||
|
||||
import { fs_path_url, type GenericResponse } from "lib/FilesystemAPI.svelte"
|
||||
import { get_user } from "lib/NovaAPI"
|
||||
|
||||
// code and an error message
|
||||
export const upload_file = (
|
||||
export const upload_file = async (
|
||||
file: Blob,
|
||||
path: string,
|
||||
on_progress: (loaded: number, total: number) => void,
|
||||
on_success: (id: string) => void,
|
||||
on_error: (code: string, message: string) => void,
|
||||
) => {
|
||||
const user = await get_user()
|
||||
// Check the file size limit. For free accounts it's 20 GB
|
||||
if (window["user"].subscription.file_size_limit === 0) {
|
||||
window["user"].subscription.file_size_limit = 20e9
|
||||
if (user !== null && user.subscription.file_size_limit === 0) {
|
||||
user.subscription.file_size_limit = 20e9
|
||||
}
|
||||
|
||||
if (file.size > window["user"].subscription.file_size_limit) {
|
||||
if (file.size > user.subscription.file_size_limit) {
|
||||
on_error(
|
||||
"file_too_large",
|
||||
"This file is too large. Check out the Pro subscription to increase the file size limit"
|
||||
|
||||
@@ -21,7 +21,7 @@ let error_message = $state("")
|
||||
let xhr: XMLHttpRequest = null
|
||||
|
||||
export const start = () => {
|
||||
xhr = upload_file(
|
||||
upload_file(
|
||||
job.file,
|
||||
job.path,
|
||||
(prog_loaded, prog_total) => {
|
||||
@@ -45,9 +45,10 @@ export const start = () => {
|
||||
// We don't send the finished signal so the user can read the error
|
||||
// messsage and manually dismiss it through the cancel button
|
||||
},
|
||||
)
|
||||
|
||||
job.status = "uploading"
|
||||
).then(result => {
|
||||
xhr = result
|
||||
job.status = "uploading"
|
||||
})
|
||||
}
|
||||
|
||||
const cancel = () => {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Response types
|
||||
// ==============
|
||||
|
||||
import { get_endpoint } from "./NovaAPI"
|
||||
|
||||
export type GenericResponse = {
|
||||
value: string,
|
||||
message: string,
|
||||
@@ -320,11 +322,7 @@ export const fs_path_url = (path: string) => {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
if (window["api_endpoint"] !== undefined) {
|
||||
return window["api_endpoint"] + "/filesystem" + fs_encode_path(path)
|
||||
} else {
|
||||
throw Error("fs_path_url: api_endpoint is undefined")
|
||||
}
|
||||
return get_endpoint() + "/filesystem" + fs_encode_path(path)
|
||||
}
|
||||
|
||||
export const fs_encode_path = (path: string) => {
|
||||
|
||||
Reference in New Issue
Block a user