diff --git a/res/static/img/home/transfers.webp b/res/static/img/home/transfers.webp new file mode 100644 index 0000000..adb86c3 Binary files /dev/null and b/res/static/img/home/transfers.webp differ diff --git a/svelte/src/filesystem/filemanager/FilePicker.svelte b/svelte/src/filesystem/filemanager/FilePicker.svelte index a75695e..201277e 100644 --- a/svelte/src/filesystem/filemanager/FilePicker.svelte +++ b/svelte/src/filesystem/filemanager/FilePicker.svelte @@ -7,12 +7,14 @@ import Modal from "util/Modal.svelte"; import { FSNavigator, path_link } from "filesystem/FSNavigator"; import { fs_encode_path, type FSNode } from "lib/FilesystemAPI.svelte"; import { FileAction, type FileActionHandler } from "./FileManagerLib"; +import CreateDirectory from "./CreateDirectory.svelte"; let nav = $state(new FSNavigator(false)) let modal: Modal = $state() let directory_view = $state("") let large_icons = $state(false) let show_hidden = $state(false) +let creating_dir = $state(false) let { callback, @@ -26,6 +28,7 @@ let { } = $props(); export const open = (path: string) => { + creating_dir = false modal.show() nav.set_selecting(false) nav.navigate(path, false) @@ -113,6 +116,11 @@ onMount(() => { {/if} + {#if $nav.permissions.write} + + {/if} + + + {/if} + {#if form.editing} + + {/if} + +
+ + {#if form.step === 1} +
{ e.preventDefault(); form.step = 2 }}> + + +
+ + + +
+ + + + + + + +
+ {:else} +
+ + + + {#if form.backend === "s3"} + + +
+ {/if} + + {#each backends[form.backend].fields.filter(f => !f.advanced) as f (form.backend + f.name)} + {@render field(f)} + {/each} + {#if !backends[form.backend].path_advanced} + {@render path()} + {/if} + + {#if backends[form.backend].path_advanced || backends[form.backend].fields.some(f => f.advanced)} + + {#if form.advanced} + {#each backends[form.backend].fields.filter(f => f.advanced) as f (form.backend + f.name)} + {@render field(f)} + {/each} + {#if backends[form.backend].path_advanced} + {@render path()} + {/if} + {/if} + {/if} + + + + +
+ {/if} + + + form.dir = { id: nodes[0].id, path: nodes[0].path }} directories/> + + diff --git a/svelte/src/user_home/transfers/TransferLib.svelte.ts b/svelte/src/user_home/transfers/TransferLib.svelte.ts new file mode 100644 index 0000000..a152dec --- /dev/null +++ b/svelte/src/user_home/transfers/TransferLib.svelte.ts @@ -0,0 +1,245 @@ +import { get_endpoint } from "lib/NovaAPI"; + +export const nova_api = new URL(get_endpoint(), window.location.href).href + +// The fields are rclone's option names, the server only passes these on. +// Advanced fields are behind a toggle, their default is sent when left empty. +// Secret fields are credentials, which the server never sends back. help is +// HTML +export type Field = { + name: string + label: string + type?: "password" | "checkbox" | "textarea" + secret?: boolean + advanced?: boolean + default?: string + help?: string +} + +// type is the rclone backend, when it differs from the key. A path which is +// advanced is behind the toggle, a required one is a bucket +export const backends: { + [key: string]: { + name: string, type?: string, path: string, path_advanced?: boolean, path_required?: boolean, fields: Field[], + } +} = { + s3: { + name: "S3", path: "Bucket and path", path_required: true, fields: [ + { name: "provider", label: "Provider (AWS, Cloudflare, Wasabi, Other...)" }, + { name: "endpoint", label: "Endpoint, empty for AWS" }, + { name: "region", label: "Region" }, + { name: "access_key_id", label: "Access key ID" }, + { name: "secret_access_key", label: "Secret access key", type: "password", secret: true }, + ] + }, + b2: { + name: "Backblaze B2", path: "Bucket and path", path_required: true, fields: [ + { name: "account", label: "Application key ID" }, + { name: "key", label: "Application key", type: "password", secret: true }, + ] + }, + azureblob: { + name: "Azure Blob Storage", path: "Container and path", path_required: true, fields: [ + { name: "account", label: "Storage account name" }, + { name: "key", label: "Storage account key", type: "password", secret: true }, + ] + }, + sftp: { + name: "SFTP", path: "Path", fields: [ + { name: "host", label: "Host" }, + { name: "port", label: "Port, empty for 22" }, + { name: "user", label: "User" }, + { name: "pass", label: "Password", type: "password", secret: true }, + { name: "key_pem", label: "Private key (PEM), instead of a password", type: "textarea", secret: true }, + ] + }, + ftp: { + name: "FTP", path: "Path", fields: [ + { name: "host", label: "Host" }, + { name: "port", label: "Port, empty for 21" }, + { name: "user", label: "User" }, + { name: "pass", label: "Password", type: "password", secret: true }, + { name: "tls", label: "Implicit TLS", type: "checkbox" }, + { name: "explicit_tls", label: "Explicit TLS", type: "checkbox" }, + ] + }, + webdav: { + name: "WebDAV", path: "Path", fields: [ + { name: "url", label: "URL" }, + { name: "vendor", label: "Vendor (nextcloud, owncloud, other...)" }, + { name: "user", label: "User" }, + { name: "pass", label: "Password", type: "password", secret: true }, + ] + }, + // Nova has the API of pixeldrain, rclone's pixeldrain backend does both. The + // API keys are text fields: Firefox fills the account password into any + // password field on this site + nova: { + name: "Nova", + type: "pixeldrain", + path: "Path inside the directory", + path_advanced: true, + fields: [ + { + name: "root_folder_id", + label: "Directory ID", + default: "me", + help: "Open the directory in the other account, its Node ID is in the Details window. " + + "Leave it empty for the home directory of the key.", + }, { + // rclone checks the key with GET /user + name: "api_key", + label: "API key of remote account", + secret: true, + help: "Create one on the API keys page while you are logged in to " + + "that account. It needs the Account read permission.", + }, { + name: "api_url", + label: "API endpoint", + advanced: true, + default: nova_api + }, + ] + }, + pixeldrain: { + name: "Pixeldrain", path: "Path", fields: [ + { + name: "api_key", label: "API key", secret: true, + help: "Create one on the " + + "API keys page of pixeldrain.", + }, + { name: "api_url", label: "API endpoint", advanced: true, default: "https://pixeldrain.com/api" }, + { + name: "root_folder_id", label: "Directory ID, for a key which only works in one directory, or a shared directory", + advanced: true, default: "me", + }, + ] + }, +} + +// Common S3 services, from rclone's list of providers. A preset fills in its +// options, with {region} replaced by the chosen region. The region option is +// only set where rclone asks for it, and AWS finds the region of the bucket +// itself +export const s3_presets: { + name: string, options: { [name: string]: string }, regions?: { [region: string]: string }, +}[] = [ + { name: "Amazon S3", options: { provider: "AWS", endpoint: "", region: "" } }, + { + name: "Cloudflare R2", + options: { provider: "Cloudflare", endpoint: "https://ACCOUNT_ID.r2.cloudflarestorage.com", region: "auto" }, + }, + { name: "Google Cloud Storage", options: { provider: "GCS", endpoint: "https://storage.googleapis.com", region: "" } }, + { name: "Storj", options: { provider: "Storj", endpoint: "https://gateway.storjshare.io", region: "" } }, + { + name: "Wasabi", options: { provider: "Wasabi", endpoint: "https://s3.{region}.wasabisys.com", region: "" }, + regions: { + "us-east-1": "N. Virginia", "us-east-2": "N. Virginia", "us-central-1": "Texas", "us-west-1": "Oregon", + "ca-central-1": "Toronto", "eu-central-1": "Amsterdam", "eu-central-2": "Frankfurt", "eu-west-1": "London", + "eu-west-2": "Paris", "eu-south-1": "Milan", "ap-northeast-1": "Tokyo", "ap-northeast-2": "Osaka", + "ap-southeast-1": "Singapore", "ap-southeast-2": "Sydney", + }, + }, + { + name: "Hetzner", options: { provider: "Hetzner", endpoint: "https://{region}.your-objectstorage.com", region: "{region}" }, + regions: { fsn1: "Falkenstein", nbg1: "Nuremberg", hel1: "Helsinki" }, + }, + { + name: "Scaleway", options: { provider: "Scaleway", endpoint: "https://s3.{region}.scw.cloud", region: "{region}" }, + regions: { "nl-ams": "Amsterdam", "fr-par": "Paris", "pl-waw": "Warsaw" }, + }, + { + name: "OVHcloud", options: { provider: "OVHcloud", endpoint: "https://s3.{region}.io.cloud.ovh.net", region: "{region}" }, + regions: { + gra: "Gravelines", rbx: "Roubaix", sbg: "Strasbourg", "eu-west-par": "Paris", de: "Frankfurt", uk: "London", + waw: "Warsaw", bhs: "Beauharnois", "ca-east-tor": "Toronto", sgp: "Singapore", "ap-southeast-syd": "Sydney", + "ap-south-mum": "Mumbai", + }, + }, + { + name: "DigitalOcean Spaces", + options: { provider: "DigitalOcean", endpoint: "https://{region}.digitaloceanspaces.com", region: "" }, + regions: { + nyc3: "New York", sfo2: "San Francisco", sfo3: "San Francisco", tor1: "Toronto", ams3: "Amsterdam", + fra1: "Frankfurt", lon1: "London", blr1: "Bangalore", sgp1: "Singapore", syd1: "Sydney", + }, + }, +] + +export const secret_fields = (service: string) => backends[service].fields.filter(f => f.secret) + +export type Transfer = { + id: string + direction: string + sync: boolean + directory: string + // From the home directory, when the transfer started + directory_path: string + remote: string + // What a restart uses. The options never have the credentials + type: string + path: string + options: { [name: string]: string } + remember: boolean + status: string + error: string + started: string + // rclone's core/stats object + stats: { + bytes: number + totalBytes: number + speed: number + eta: number | null + transfers: number + totalTransfers: number + checks: number + totalChecks: number + } | null +} + +// The service of a transfer, Nova and pixeldrain both use rclone's pixeldrain +// backend. Empty for a transfer from before the settings were saved +export const service_of = (t: Transfer) => { + const service = t.type === "pixeldrain" && t.options.api_url === nova_api ? "nova" : t.type + return backends[service] === undefined ? "" : service +} + +// The form outlives the page, so an attempt which failed can be tried again +// without typing everything again. It's only kept in memory, so a reload clears +// the passwords in it +export const form = $state({ + step: 1, + // The transfer which is edited, empty for a new one + editing: "", + // The edited transfer has its credentials saved on the server + saved_secrets: false, + direction: "import", + dir: null as { id: string, path: string } | null, + backend: "s3", + // The options of one service mean nothing to another + options: Object.fromEntries(Object.keys(backends).map(k => [k, {}])) as + { [backend: string]: { [name: string]: string | boolean } }, + advanced: false, + paths: Object.fromEntries(Object.keys(backends).map(k => [k, ""])) as { [backend: string]: string }, + sync: false, + remember: false, +}) + +// edit_transfer loads a transfer into the form. Its credentials stay empty, the +// server never sends them, and leaving them empty keeps the saved ones +export const edit_transfer = (t: Transfer) => { + const service = service_of(t) + form.step = 1 + form.editing = t.id + form.saved_secrets = t.remember + form.direction = t.direction + form.sync = t.sync + form.dir = { id: t.directory, path: t.directory_path } + form.backend = service + form.options[service] = { ...t.options } + form.paths[service] = t.path + form.remember = t.remember + form.advanced = (backends[service].path_advanced && t.path !== "") || backends[service].fields.some(f => + f.advanced && t.options[f.name] !== undefined && t.options[f.name] !== f.default + ) +} diff --git a/svelte/src/user_home/transfers/Transfers.svelte b/svelte/src/user_home/transfers/Transfers.svelte new file mode 100644 index 0000000..976af62 --- /dev/null +++ b/svelte/src/user_home/transfers/Transfers.svelte @@ -0,0 +1,263 @@ + + +
+

Transfers

+

+ Copy files between Nova and another storage service. The transfer runs + on our servers, so you can close this page while it runs. A transfer + which stopped can be started again, files which are already there are + skipped. +

+ + {#if $user !== null && $user.subscription.id === ""} +

+ Transfers are available on paid plans. + + shopping_cart Upgrade + +

+ {:else} + + {/if} + + {#each transfers as t (t.id)} + {@const name = t.directory_path || t.directory} + {@const service = service_of(t)} +
+
+ + {t.direction === "import" ? "download" : "upload"} + {t.sync ? "Sync" : "Copy"} + {t.direction === "import" ? t.remote + " → " + name : name + " → " + t.remote} + +
+ {#if t.status === "running"} + + {:else} + {#if service !== ""} + + {/if} + + + {/if} +
+ + {#if t.stats} + +
+
+ Data copied + {formatDataVolume(t.stats.bytes, 3)} of {formatDataVolume(t.stats.totalBytes, 3)} +
+
+ Files copied + {t.stats.transfers} of {t.stats.totalTransfers} +
+
+ Files checked + {t.stats.checks} of {t.stats.totalChecks} +
+
+ Transfer rate + {formatDataVolume(t.stats.speed, 3)}/s +
+
+ Time left + + {t.status === "running" && t.stats.eta !== null + ? formatDuration(t.stats.eta * 1000, t.stats.eta < 60 ? 1 : 2) : "-"} +
+
+ {/if} + {#if t.error} +
{t.error}
+ {/if} + + {#if asking === t.id} +
{ e.preventDefault(); restart(t, { ...secrets, remember: remember_again }) }}> + + + {#each secret_fields(service) as f (f.name)} + + {#if f.type === "textarea"} + + {:else if f.type === "password"} + + {:else} + + {/if} + {/each} + +
+ + +
+
+ {/if} + +
+
+ Status + {t.status} +
+
+ Started + {t.started ? formatDate(t.started, true, true, false) : "-"} +
+
+ Credentials + {t.remember ? "Remembered" : "Not saved"} +
+
+
+ {/each} +
+ +