I hate javascript so much.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
<script lang="ts">
|
||||
<script>
|
||||
import { fs_encode_path } from "./FilesystemAPI";
|
||||
import { FSNavigator } from "./FSNavigator";
|
||||
|
||||
export let nav: FSNavigator
|
||||
export let nav
|
||||
</script>
|
||||
|
||||
<div class="breadcrumbs">
|
||||
|
@@ -9,17 +9,23 @@
|
||||
//
|
||||
// on_error is called when the upload has failed. The parameters are the error
|
||||
|
||||
import { fs_path_url } from "./../FilesystemAPI"
|
||||
import { fs_path_url, type GenericResponse } from "./../FilesystemAPI"
|
||||
|
||||
// code and an error message
|
||||
export const upload_file = (file, path, on_progress, on_success, on_error) => {
|
||||
export const upload_file = (
|
||||
file: Blob,
|
||||
path: string,
|
||||
on_progress: (loaded: number, total: number) => void,
|
||||
on_success: (id: string) => void,
|
||||
on_error: (code: string, message: string) => void,
|
||||
) => {
|
||||
// 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 (window["user"].subscription.file_size_limit === 0) {
|
||||
window["user"].subscription.file_size_limit = 20e9
|
||||
}
|
||||
|
||||
if (file.size > window.user.subscription.file_size_limit) {
|
||||
on_failure(
|
||||
if (file.size > window["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"
|
||||
)
|
||||
@@ -51,14 +57,14 @@ export const upload_file = (file, path, on_progress, on_success, on_error) => {
|
||||
// Request failed
|
||||
console.log("Upload error. status: " + xhr.status + " response: " + xhr.response);
|
||||
|
||||
let resp;
|
||||
let resp: GenericResponse
|
||||
if (xhr.status === 429) {
|
||||
resp = {
|
||||
value: "too_many_requests",
|
||||
message: "Too many requests. Please wait a few seconds",
|
||||
}
|
||||
} else {
|
||||
resp = JSON.parse(xhr.response)
|
||||
resp = JSON.parse(xhr.response) as GenericResponse
|
||||
}
|
||||
|
||||
on_error(resp.value, resp.message)
|
@@ -8,6 +8,7 @@ import Button from "../../layout/Button.svelte"
|
||||
let dispatch = createEventDispatcher()
|
||||
export let job = {
|
||||
file: null,
|
||||
path: "",
|
||||
name: "",
|
||||
status: "",
|
||||
}
|
||||
|
@@ -1,13 +1,13 @@
|
||||
<script>
|
||||
import { createEventDispatcher, tick } from "svelte";
|
||||
import { tick } from "svelte";
|
||||
import { fade } from "svelte/transition";
|
||||
import DropUpload from "./DropUpload.svelte";
|
||||
import UploadProgress from "./UploadProgress.svelte";
|
||||
|
||||
export let nav
|
||||
|
||||
let file_input_field;
|
||||
let file_input_change = e => {
|
||||
let file_input_field
|
||||
let file_input_change = (e) => {
|
||||
// Start uploading the files async
|
||||
upload_files(e.target.files)
|
||||
|
||||
@@ -116,17 +116,16 @@ const start_upload = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const finish_upload = (e) => {
|
||||
const finish_upload = () => {
|
||||
// Update the queue so the status updates are properly rendered
|
||||
upload_queue = upload_queue
|
||||
start_upload()
|
||||
}
|
||||
|
||||
const leave_confirmation = e => {
|
||||
const leave_confirmation = (e) => {
|
||||
if (state === "uploading") {
|
||||
e.preventDefault()
|
||||
e.returnValue = "If you close this page your files will stop uploading. Do you want to continue?"
|
||||
return e.returnValue
|
||||
return "If you close this page your files will stop uploading. Do you want to continue?"
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
@@ -138,7 +137,7 @@ const leave_confirmation = e => {
|
||||
<input
|
||||
bind:this={file_input_field}
|
||||
on:change={file_input_change}
|
||||
class="upload_input" type="file" name="file" multiple="multiple"
|
||||
class="upload_input" type="file" name="file" multiple
|
||||
/>
|
||||
|
||||
{#if visible}
|
||||
|
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"verbatimModuleSyntax": true,
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user