Fix uploader not working because window.user was removed

This commit is contained in:
2026-07-30 21:33:45 +02:00
parent 609dfc906a
commit 263f959565
3 changed files with 14 additions and 13 deletions

View File

@@ -10,21 +10,23 @@
// on_error is called when the upload has failed. The parameters are the error // 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 { fs_path_url, type GenericResponse } from "lib/FilesystemAPI.svelte"
import { get_user } from "lib/NovaAPI"
// code and an error message // code and an error message
export const upload_file = ( export const upload_file = async (
file: Blob, file: Blob,
path: string, path: string,
on_progress: (loaded: number, total: number) => void, on_progress: (loaded: number, total: number) => void,
on_success: (id: string) => void, on_success: (id: string) => void,
on_error: (code: string, message: 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 // Check the file size limit. For free accounts it's 20 GB
if (window["user"].subscription.file_size_limit === 0) { if (user !== null && user.subscription.file_size_limit === 0) {
window["user"].subscription.file_size_limit = 20e9 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( on_error(
"file_too_large", "file_too_large",
"This file is too large. Check out the Pro subscription to increase the file size limit" "This file is too large. Check out the Pro subscription to increase the file size limit"

View File

@@ -21,7 +21,7 @@ let error_message = $state("")
let xhr: XMLHttpRequest = null let xhr: XMLHttpRequest = null
export const start = () => { export const start = () => {
xhr = upload_file( upload_file(
job.file, job.file,
job.path, job.path,
(prog_loaded, prog_total) => { (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 // We don't send the finished signal so the user can read the error
// messsage and manually dismiss it through the cancel button // messsage and manually dismiss it through the cancel button
}, },
) ).then(result => {
xhr = result
job.status = "uploading" job.status = "uploading"
})
} }
const cancel = () => { const cancel = () => {

View File

@@ -1,6 +1,8 @@
// Response types // Response types
// ============== // ==============
import { get_endpoint } from "./NovaAPI"
export type GenericResponse = { export type GenericResponse = {
value: string, value: string,
message: string, message: string,
@@ -320,11 +322,7 @@ export const fs_path_url = (path: string) => {
path = "/" + path path = "/" + path
} }
if (window["api_endpoint"] !== undefined) { return get_endpoint() + "/filesystem" + fs_encode_path(path)
return window["api_endpoint"] + "/filesystem" + fs_encode_path(path)
} else {
throw Error("fs_path_url: api_endpoint is undefined")
}
} }
export const fs_encode_path = (path: string) => { export const fs_encode_path = (path: string) => {