Add data sync form
This commit is contained in:
1 parent
ebb72c7f24
commit
1956790dde
7 files changed
+760
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
@@ -7,12 +7,14 @@ import Modal from "util/Modal.svelte";
|
|||||||
import { FSNavigator, path_link } from "filesystem/FSNavigator";
|
import { FSNavigator, path_link } from "filesystem/FSNavigator";
|
||||||
import { fs_encode_path, type FSNode } from "lib/FilesystemAPI.svelte";
|
import { fs_encode_path, type FSNode } from "lib/FilesystemAPI.svelte";
|
||||||
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
import { FileAction, type FileActionHandler } from "./FileManagerLib";
|
||||||
|
import CreateDirectory from "./CreateDirectory.svelte";
|
||||||
|
|
||||||
let nav = $state(new FSNavigator(false))
|
let nav = $state(new FSNavigator(false))
|
||||||
let modal: Modal = $state()
|
let modal: Modal = $state()
|
||||||
let directory_view = $state("")
|
let directory_view = $state("")
|
||||||
let large_icons = $state(false)
|
let large_icons = $state(false)
|
||||||
let show_hidden = $state(false)
|
let show_hidden = $state(false)
|
||||||
|
let creating_dir = $state(false)
|
||||||
|
|
||||||
let {
|
let {
|
||||||
callback,
|
callback,
|
||||||
@@ -26,6 +28,7 @@ let {
|
|||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
export const open = (path: string) => {
|
export const open = (path: string) => {
|
||||||
|
creating_dir = false
|
||||||
modal.show()
|
modal.show()
|
||||||
nav.set_selecting(false)
|
nav.set_selecting(false)
|
||||||
nav.navigate(path, false)
|
nav.navigate(path, false)
|
||||||
@@ -113,6 +116,11 @@ onMount(() => {
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if $nav.permissions.write}
|
||||||
|
<button onclick={() => creating_dir = !creating_dir} class:button_highlight={creating_dir} title="Make folder">
|
||||||
|
<i class="icon">create_new_folder</i>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
<button onclick={() => {show_hidden = !show_hidden}} title="Toggle hidden files">
|
<button onclick={() => {show_hidden = !show_hidden}} title="Toggle hidden files">
|
||||||
{#if show_hidden}
|
{#if show_hidden}
|
||||||
<i class="icon">visibility_off</i>
|
<i class="icon">visibility_off</i>
|
||||||
@@ -154,6 +162,10 @@ onMount(() => {
|
|||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
|
|
||||||
|
{#if creating_dir}
|
||||||
|
<CreateDirectory nav={nav}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if directory_view === "list"}
|
{#if directory_view === "list"}
|
||||||
<ListView
|
<ListView
|
||||||
nav={nav}
|
nav={nav}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ const slides = [
|
|||||||
title: "Statistics",
|
title: "Statistics",
|
||||||
text: `Follow the downloads and data transfer of every file, from the
|
text: `Follow the downloads and data transfer of every file, from the
|
||||||
last day up to five years back.`,
|
last day up to five years back.`,
|
||||||
|
}, {
|
||||||
|
image: "transfers",
|
||||||
|
title: "Transfers",
|
||||||
|
text: `Import from or export to S3, Backblaze B2, Azure, SFTP, FTP,
|
||||||
|
WebDAV or pixeldrain. Transfers run on our servers, so you can close the
|
||||||
|
page while they run.`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { get_user, type User } from "lib/NovaAPI";
|
|||||||
import SharingSettings from "./SharingSettings.svelte";
|
import SharingSettings from "./SharingSettings.svelte";
|
||||||
import SubscriptionManage from "./SubscriptionManage.svelte";
|
import SubscriptionManage from "./SubscriptionManage.svelte";
|
||||||
import SubscriptionUsage from "./SubscriptionUsage.svelte";
|
import SubscriptionUsage from "./SubscriptionUsage.svelte";
|
||||||
|
import Transfers from "./transfers/Transfers.svelte";
|
||||||
|
|
||||||
let pages: Tab[] = [
|
let pages: Tab[] = [
|
||||||
{
|
{
|
||||||
@@ -52,6 +53,11 @@ let pages: Tab[] = [
|
|||||||
title: "Sharing settings",
|
title: "Sharing settings",
|
||||||
icon: "share",
|
icon: "share",
|
||||||
component: SharingSettings,
|
component: SharingSettings,
|
||||||
|
}, {
|
||||||
|
path: "/user/transfers",
|
||||||
|
title: "Transfers",
|
||||||
|
icon: "sync_alt",
|
||||||
|
component: Transfers,
|
||||||
}, {
|
}, {
|
||||||
path: "/user/connect_app",
|
path: "/user/connect_app",
|
||||||
title: "Apps",
|
title: "Apps",
|
||||||
|
|||||||
@@ -0,0 +1,228 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { loading_run } from "lib/Loading";
|
||||||
|
import { check_response, dict_to_form, get_endpoint } from "lib/NovaAPI";
|
||||||
|
import FilePicker from "filesystem/filemanager/FilePicker.svelte";
|
||||||
|
import { backends, form, s3_presets, type Field } from "./TransferLib.svelte";
|
||||||
|
|
||||||
|
// Called after a transfer was started or saved
|
||||||
|
let { onsaved }: { onsaved: () => void } = $props()
|
||||||
|
|
||||||
|
let picker: FilePicker = $state()
|
||||||
|
|
||||||
|
// The value of a preset option is its index and region
|
||||||
|
const use_preset = (value: string) => {
|
||||||
|
const [i, region] = value.split(" ")
|
||||||
|
for (const [name, v] of Object.entries(s3_presets[+i].options)) {
|
||||||
|
form.options.s3[name] = v.replace("{region}", region)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const placeholder = (f: Field) =>
|
||||||
|
f.secret && form.editing && form.saved_secrets ? "Saved, leave empty to keep it" : f.default ?? ""
|
||||||
|
|
||||||
|
const submit = async (e: SubmitEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
const b = backends[form.backend]
|
||||||
|
const fields = {}
|
||||||
|
for (const f of b.fields) {
|
||||||
|
const value = form.options[form.backend][f.name] || f.default
|
||||||
|
if (value) {
|
||||||
|
fields[f.name] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await loading_run(async () => check_response(
|
||||||
|
await fetch(get_endpoint() + "/user/transfer" + (form.editing ? "/" + form.editing : ""), {
|
||||||
|
method: form.editing ? "PUT" : "POST",
|
||||||
|
body: dict_to_form({
|
||||||
|
direction: form.direction, sync: form.sync, remember: form.remember, directory: form.dir.id,
|
||||||
|
type: b.type ?? form.backend, path: form.paths[form.backend], ...fields,
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
))
|
||||||
|
} catch (err) {
|
||||||
|
alert("Failed to " + (form.editing ? "save" : "start") + " the transfer: " + (err.message ?? err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
form.editing = ""
|
||||||
|
form.step = 1
|
||||||
|
onsaved()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#snippet field(f: Field)}
|
||||||
|
{#if f.type === "checkbox"}
|
||||||
|
<label><input type="checkbox" bind:checked={form.options[form.backend][f.name]}/> {f.label}</label>
|
||||||
|
{:else}
|
||||||
|
<label for={"transfer_" + f.name}>{f.label}</label>
|
||||||
|
{#if f.type === "textarea"}
|
||||||
|
<textarea id={"transfer_" + f.name} bind:value={form.options[form.backend][f.name]}></textarea>
|
||||||
|
{:else if f.type === "password"}
|
||||||
|
<input
|
||||||
|
id={"transfer_" + f.name}
|
||||||
|
type="password"
|
||||||
|
autocomplete="off"
|
||||||
|
placeholder={placeholder(f)}
|
||||||
|
bind:value={form.options[form.backend][f.name]}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<input id={"transfer_" + f.name} type="text" autocomplete="off" placeholder={placeholder(f)} bind:value={form.options[form.backend][f.name]}/>
|
||||||
|
{/if}
|
||||||
|
{#if f.help}
|
||||||
|
<small>{@html f.help}</small>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
<hr/>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
{#snippet path()}
|
||||||
|
<label for="transfer_path">{backends[form.backend].path}</label>
|
||||||
|
<input id="transfer_path" type="text" bind:value={form.paths[form.backend]} required={backends[form.backend].path_required}/>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
|
<div id="transfer_form" class="highlight_border">
|
||||||
|
<div class="navbar">
|
||||||
|
<b>{form.editing ? "Edit transfer" : "New transfer"}</b>
|
||||||
|
{#if form.step === 2}
|
||||||
|
<button onclick={() => form.step = 1}>
|
||||||
|
{form.direction === "import" ? "Import into" : "Export from"} {form.dir.path}
|
||||||
|
</button>
|
||||||
|
<button onclick={() => form.step = 1}>{form.sync ? "Sync" : "Copy"}</button>
|
||||||
|
<button onclick={() => form.step = 1}>Service: {backends[form.backend].name}</button>
|
||||||
|
{/if}
|
||||||
|
{#if form.editing}
|
||||||
|
<button onclick={() => { form.editing = ""; form.step = 1 }}>
|
||||||
|
<i class="icon">close</i> Stop editing
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
<hr/>
|
||||||
|
|
||||||
|
{#if form.step === 1}
|
||||||
|
<form class="form" onsubmit={e => { e.preventDefault(); form.step = 2 }}>
|
||||||
|
<label class="radio_label">
|
||||||
|
<input type="radio" bind:group={form.direction} value="import"/>
|
||||||
|
Import into Nova
|
||||||
|
</label>
|
||||||
|
<label class="radio_label">
|
||||||
|
<input type="radio" bind:group={form.direction} value="export"/>
|
||||||
|
Export from Nova
|
||||||
|
</label>
|
||||||
|
<hr/>
|
||||||
|
<label class="radio_label">
|
||||||
|
<input type="radio" bind:group={form.sync} value={true}/>
|
||||||
|
Sync: Delete files at the destination which do not exist at
|
||||||
|
the source
|
||||||
|
</label>
|
||||||
|
<label class="radio_label">
|
||||||
|
<input type="radio" bind:group={form.sync} value={false}/>
|
||||||
|
Copy: Only copy files from the source to the destination
|
||||||
|
without removing anything
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
<label for="transfer_dir">Local directory</label>
|
||||||
|
<button id="transfer_dir" type="button" onclick={() => picker.open("/me")}>
|
||||||
|
<i class="icon">folder</i>
|
||||||
|
{form.dir ? form.dir.path : "Choose a directory"}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<label for="transfer_backend">Remote service</label>
|
||||||
|
<select id="transfer_backend" bind:value={form.backend}>
|
||||||
|
{#each Object.entries(backends) as [type, b]}
|
||||||
|
<option value={type}>{b.name}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<button class="button_highlight" type="submit" disabled={!form.dir}>
|
||||||
|
Next <i class="icon">arrow_forward</i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{:else}
|
||||||
|
<form class="form" onsubmit={submit}>
|
||||||
|
<!-- Firefox fills the account's login into a form with a password
|
||||||
|
field, unless the form has a username field of its own -->
|
||||||
|
<input type="text" autocomplete="username" value={"Transfer " + backends[form.backend].name} style="display: none;"/>
|
||||||
|
|
||||||
|
{#if form.backend === "s3"}
|
||||||
|
<label for="transfer_preset">Preset</label>
|
||||||
|
<select id="transfer_preset" onchange={e => use_preset(e.currentTarget.value)}>
|
||||||
|
<option value="" disabled selected>Choose a service to fill in the fields below</option>
|
||||||
|
{#each s3_presets as p, i}
|
||||||
|
{#if p.regions}
|
||||||
|
<optgroup label={p.name}>
|
||||||
|
{#each Object.entries(p.regions) as [region, city]}
|
||||||
|
<option value={i + " " + region}>{p.name} {city} ({region})</option>
|
||||||
|
{/each}
|
||||||
|
</optgroup>
|
||||||
|
{:else}
|
||||||
|
<option value={i + " "}>{p.name}</option>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
<hr/>
|
||||||
|
{/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)}
|
||||||
|
<label><input type="checkbox" bind:checked={form.advanced}/> Advanced options</label>
|
||||||
|
{#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}
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" bind:checked={form.remember}/>
|
||||||
|
Remember the credentials, so a restart doesn't ask for them again
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button class="button_highlight" type="submit">
|
||||||
|
{#if form.editing}
|
||||||
|
<i class="icon">save</i> Save
|
||||||
|
{:else}
|
||||||
|
<i class="icon">sync_alt</i> Start transfer
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FilePicker bind:this={picker} callback={nodes => form.dir = { id: nodes[0].id, path: nodes[0].path }} directories/>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Edit scrolls here, clear of the page's sticky header */
|
||||||
|
#transfer_form {
|
||||||
|
scroll-margin-top: 3.5em;
|
||||||
|
}
|
||||||
|
/* The choices of the first step, like the checkout widget */
|
||||||
|
.navbar {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.25em;
|
||||||
|
}
|
||||||
|
.radio_picker {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.radio_label {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 0.5em;
|
||||||
|
margin: 0.2em 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -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 <a href=\"/user/api_keys\">API keys page</a> 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 <a href=\"https://pixeldrain.com/user/api_keys\" target=\"_blank\">" +
|
||||||
|
"API keys page</a> 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
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
import { loading_run } from "lib/Loading";
|
||||||
|
import { check_response, dict_to_form, get_endpoint } from "lib/NovaAPI";
|
||||||
|
import ProgressBar from "util/ProgressBar.svelte";
|
||||||
|
import { formatDataVolume, formatDate, formatDuration } from "util/Formatting";
|
||||||
|
import { user } from "lib/UserStore";
|
||||||
|
import TransferForm from "./TransferForm.svelte";
|
||||||
|
import { edit_transfer, form, secret_fields, service_of, type Transfer } from "./TransferLib.svelte";
|
||||||
|
|
||||||
|
let transfers: Transfer[] = $state([])
|
||||||
|
|
||||||
|
// Polls every second while a transfer runs, the server saves the
|
||||||
|
// progress that often
|
||||||
|
let mounted = true
|
||||||
|
let timeout: ReturnType<typeof setTimeout>
|
||||||
|
const load = async () => {
|
||||||
|
clearTimeout(timeout)
|
||||||
|
try {
|
||||||
|
transfers = await check_response(await fetch(get_endpoint() + "/user/transfer"))
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Failed to load transfers:", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mounted && transfers.some(t => t.status === "running")) {
|
||||||
|
timeout = setTimeout(load, 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
load()
|
||||||
|
return () => {
|
||||||
|
mounted = false
|
||||||
|
clearTimeout(timeout)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const edit = (t: Transfer) => {
|
||||||
|
edit_transfer(t)
|
||||||
|
document.getElementById("transfer_form")?.scrollIntoView({ behavior: "smooth" })
|
||||||
|
}
|
||||||
|
|
||||||
|
const restart = async (t: Transfer, body = {}) => {
|
||||||
|
try {
|
||||||
|
await loading_run(async () => check_response(
|
||||||
|
await fetch(get_endpoint() + "/user/transfer/" + t.id + "/restart", {
|
||||||
|
method: "POST",
|
||||||
|
body: dict_to_form(body),
|
||||||
|
})
|
||||||
|
))
|
||||||
|
} catch (err) {
|
||||||
|
alert("Failed to restart the transfer: " + (err.message ?? err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
asking = ""
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
|
||||||
|
// A transfer without remembered credentials asks for them again. What the form
|
||||||
|
// still has for that service is filled in
|
||||||
|
let asking = $state("")
|
||||||
|
let secrets: { [name: string]: string } = $state({})
|
||||||
|
let remember_again = $state(false)
|
||||||
|
const ask = (t: Transfer) => {
|
||||||
|
const service = service_of(t)
|
||||||
|
secrets = Object.fromEntries(secret_fields(service).map(f =>
|
||||||
|
[f.name, (form.options[service][f.name] as string) ?? ""]
|
||||||
|
))
|
||||||
|
remember_again = false
|
||||||
|
asking = t.id
|
||||||
|
}
|
||||||
|
|
||||||
|
const remove = async (t: Transfer) => {
|
||||||
|
try {
|
||||||
|
await loading_run(async () => check_response(
|
||||||
|
await fetch(get_endpoint() + "/user/transfer/" + t.id, { method: "DELETE" })
|
||||||
|
))
|
||||||
|
} catch (err) {
|
||||||
|
alert("Failed to remove the transfer: " + (err.message ?? err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
load()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h2>Transfers</h2>
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{#if $user !== null && $user.subscription.id === ""}
|
||||||
|
<p>
|
||||||
|
Transfers are available on paid plans.
|
||||||
|
<a class="button button_highlight" href="/user/subscription/manage">
|
||||||
|
<i class="icon">shopping_cart</i> Upgrade
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
{:else}
|
||||||
|
<TransferForm onsaved={load}/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#each transfers as t (t.id)}
|
||||||
|
{@const name = t.directory_path || t.directory}
|
||||||
|
{@const service = service_of(t)}
|
||||||
|
<div class="transfer" class:running={t.status === "running"} class:editing={form.editing === t.id}>
|
||||||
|
<div class="row">
|
||||||
|
<span class="title">
|
||||||
|
<i class="icon">{t.direction === "import" ? "download" : "upload"}</i>
|
||||||
|
<span class="badge">{t.sync ? "Sync" : "Copy"}</span>
|
||||||
|
{t.direction === "import" ? t.remote + " → " + name : name + " → " + t.remote}
|
||||||
|
</span>
|
||||||
|
<div class="toolbar_spacer"></div>
|
||||||
|
{#if t.status === "running"}
|
||||||
|
<button onclick={() => remove(t)}>
|
||||||
|
<i class="icon">cancel</i> Abort
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
{#if service !== ""}
|
||||||
|
<button onclick={() => edit(t)}>
|
||||||
|
<i class="icon">edit</i> Edit
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
<button onclick={() => t.remember || service === "" ? restart(t) : ask(t)}>
|
||||||
|
<i class="icon">restart_alt</i> Restart
|
||||||
|
</button>
|
||||||
|
<button class="button_red" onclick={() => remove(t)}>
|
||||||
|
<i class="icon">delete</i> Remove
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if t.stats}
|
||||||
|
<ProgressBar total={t.stats.totalBytes} used={t.stats.bytes} speed={1000} animation="linear"/>
|
||||||
|
<div class="details">
|
||||||
|
<div>
|
||||||
|
<span>Data copied</span>
|
||||||
|
{formatDataVolume(t.stats.bytes, 3)} of {formatDataVolume(t.stats.totalBytes, 3)}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Files copied</span>
|
||||||
|
{t.stats.transfers} of {t.stats.totalTransfers}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Files checked</span>
|
||||||
|
{t.stats.checks} of {t.stats.totalChecks}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Transfer rate</span>
|
||||||
|
{formatDataVolume(t.stats.speed, 3)}/s
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Time left</span>
|
||||||
|
<!-- Below a minute the second unit would be milliseconds -->
|
||||||
|
{t.status === "running" && t.stats.eta !== null
|
||||||
|
? formatDuration(t.stats.eta * 1000, t.stats.eta < 60 ? 1 : 2) : "-"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#if t.error}
|
||||||
|
<div class="highlight_red">{t.error}</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if asking === t.id}
|
||||||
|
<form class="form" onsubmit={e => { e.preventDefault(); restart(t, { ...secrets, remember: remember_again }) }}>
|
||||||
|
<!-- Keeps Firefox from filling in the account's login, see TransferForm -->
|
||||||
|
<input type="text" autocomplete="username" value={"Transfer " + t.remote} style="display: none;"/>
|
||||||
|
{#each secret_fields(service) as f (f.name)}
|
||||||
|
<label for={"restart_" + f.name}>{f.label}</label>
|
||||||
|
{#if f.type === "textarea"}
|
||||||
|
<textarea id={"restart_" + f.name} bind:value={secrets[f.name]}></textarea>
|
||||||
|
{:else if f.type === "password"}
|
||||||
|
<input id={"restart_" + f.name} type="password" autocomplete="off" bind:value={secrets[f.name]}/>
|
||||||
|
{:else}
|
||||||
|
<input id={"restart_" + f.name} type="text" autocomplete="off" bind:value={secrets[f.name]}/>
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" bind:checked={remember_again}/>
|
||||||
|
Remember the credentials
|
||||||
|
</label>
|
||||||
|
<div class="row">
|
||||||
|
<button type="button" onclick={() => asking = ""}>Cancel</button>
|
||||||
|
<button class="button_highlight" type="submit">
|
||||||
|
<i class="icon">restart_alt</i> Restart
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="details">
|
||||||
|
<div>
|
||||||
|
<span>Status</span>
|
||||||
|
{t.status}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Started</span>
|
||||||
|
{t.started ? formatDate(t.started, true, true, false) : "-"}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span>Credentials</span>
|
||||||
|
{t.remember ? "Remembered" : "Not saved"}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* The cards of the API keys page */
|
||||||
|
.transfer {
|
||||||
|
margin: 0.8em 0;
|
||||||
|
padding: 0.4em 0.6em;
|
||||||
|
border-radius: 8px;
|
||||||
|
border-left: 3px solid var(--separator);
|
||||||
|
background: var(--card_color);
|
||||||
|
}
|
||||||
|
.transfer.running,
|
||||||
|
.transfer.editing {
|
||||||
|
border-left-color: var(--accent_color);
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.2em 0.5em;
|
||||||
|
margin: 0.3em 0;
|
||||||
|
}
|
||||||
|
.toolbar_spacer {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
.title {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.3em;
|
||||||
|
font-size: 1.1em;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
.badge {
|
||||||
|
padding: 0 0.6em;
|
||||||
|
border-radius: 1em;
|
||||||
|
color: var(--link_color);
|
||||||
|
background: var(--accent_shade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Each detail is a label with its value below it */
|
||||||
|
.details {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.2em 1.5em;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
.details > div {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
.details span {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in new issue
Block a user