Remove unused buckets and directory_upload pages
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { formatDate, formatDataVolume, formatThousands } from '../util/Formatting.svelte'
|
||||
import { fs_get_file_url, fs_get_node } from './FilesystemAPI.svelte'
|
||||
import { fs_get_file_url, fs_get_node } from './FilesystemAPI.js'
|
||||
import Sharebar from './Sharebar.svelte'
|
||||
import Modal from '../util/Modal.svelte'
|
||||
import FileManager from './filemanager/FileManager.svelte';
|
||||
|
84
svelte/src/filesystem/FilesystemAPI.js
Normal file
84
svelte/src/filesystem/FilesystemAPI.js
Normal file
@@ -0,0 +1,84 @@
|
||||
const path_url = (bucket, path) => {
|
||||
return window.api_endpoint + "/filesystem/" + bucket + encodeURIComponent(path)
|
||||
}
|
||||
|
||||
export const fs_get_file_url = (bucket, path) => {
|
||||
return path_url(bucket, path)
|
||||
}
|
||||
|
||||
export const fs_mkdir = async (bucket, path, opts = null) => {
|
||||
const form = new FormData()
|
||||
form.append("action", "mkdir")
|
||||
|
||||
if (opts && opts.mode) {
|
||||
form.append("mode", opts.mode)
|
||||
}
|
||||
|
||||
const resp = await fetch(path_url(bucket, path), { method: "POST", body: form });
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
export const fs_get_node = async (bucket, path) => {
|
||||
const resp = await fetch(path_url(bucket, path) + "?stat");
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
// Updates a node's parameters. Available options are:
|
||||
// - created, Date object
|
||||
// - modified, Date object
|
||||
// - mode, file mode formatted as octal string
|
||||
// - shared, boolean. If true the node will receive a public ID
|
||||
//
|
||||
// Returns the modified filesystem node object
|
||||
export const fs_update = async (bucket, path, opts) => {
|
||||
const form = new FormData()
|
||||
form.append("action", "update")
|
||||
|
||||
if (opts.created) {
|
||||
form.append("created", opts.created.toISOString())
|
||||
}
|
||||
if (opts.modified) {
|
||||
form.append("modified", opts.modified.toISOString())
|
||||
}
|
||||
if (opts.mode) {
|
||||
form.append("mode", opts.mode)
|
||||
}
|
||||
if (opts.shared) {
|
||||
form.append("shared", opts.shared)
|
||||
}
|
||||
|
||||
const resp = await fetch(path_url(bucket, path), { method: "POST", body: form })
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
export const fs_rename = async (bucket, old_path, new_path) => {
|
||||
const form = new FormData()
|
||||
form.append("action", "rename")
|
||||
form.append("target", new_path)
|
||||
|
||||
const resp = await fetch(path_url(bucket, old_path), { method: "POST", body: form })
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
export const fs_delete = async (bucket, path) => {
|
||||
const resp = await fetch(path_url(bucket, path), { method: "DELETE" });
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
||||
export const fs_delete_all = async (bucket, path) => {
|
||||
const resp = await fetch(path_url(bucket, path) + "?recursive", { method: "DELETE" });
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
<script context="module">
|
||||
|
||||
export const fs_create_bucket = async (name = "", read_pw = "", write_pw = "") => {
|
||||
const form = new FormData()
|
||||
form.append("name", name)
|
||||
form.append("read_password", read_pw)
|
||||
form.append("write_password", write_pw)
|
||||
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem",
|
||||
{ method: "POST", body: form }
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(await resp.text());
|
||||
}
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
export const fs_get_buckets = async () => {
|
||||
const resp = await fetch(window.api_endpoint+"/filesystem");
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(await resp.text());
|
||||
}
|
||||
return resp.json();
|
||||
}
|
||||
|
||||
export const fs_delete_bucket = async (id, recursive) => {
|
||||
let uri = window.api_endpoint+"/filesystem/"+encodeURIComponent(id)
|
||||
if (recursive) {
|
||||
uri += "?recursive"
|
||||
}
|
||||
|
||||
const resp = await fetch(uri, { method: "DELETE" });
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(await resp.text());
|
||||
}
|
||||
}
|
||||
|
||||
export const fs_create_directory = async (bucket, path, dir_name) => {
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
const form = new FormData()
|
||||
form.append("type", "dir")
|
||||
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path+"/"+dir_name),
|
||||
{ method: "POST", body: form }
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
export const fs_get_node = async (bucket, path) => {
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path)+"?stat"
|
||||
);
|
||||
if(resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
return resp.json()
|
||||
}
|
||||
|
||||
export const fs_get_file_url = (bucket, path) => {
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path
|
||||
}
|
||||
return window.api_endpoint + "/filesystem/" + bucket + encodeURIComponent(path)
|
||||
}
|
||||
|
||||
export const fs_rename_node = async (bucket, old_path, new_path) => {
|
||||
if (!old_path.startsWith("/")) { old_path = "/" + old_path }
|
||||
if (!new_path.startsWith("/")) { new_path = "/" + new_path }
|
||||
|
||||
const form = new FormData()
|
||||
form.append("move_to", new_path)
|
||||
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(old_path),
|
||||
{ method: "PUT", body: form }
|
||||
)
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
export const fs_delete_node = async (bucket, path) => {
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path
|
||||
}
|
||||
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/filesystem/"+bucket+encodeURIComponent(path)+"?recursive",
|
||||
{ method: "DELETE" }
|
||||
);
|
||||
if (resp.status >= 400) {
|
||||
throw new Error(await resp.text())
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
@@ -1,21 +1,21 @@
|
||||
<script>
|
||||
import { onMount, createEventDispatcher } from "svelte";
|
||||
import { fs_create_directory } from "../FilesystemAPI.svelte";
|
||||
import { fs_mkdir } from "../FilesystemAPI.js";
|
||||
let dispatch = createEventDispatcher()
|
||||
|
||||
export let state;
|
||||
let name_input;
|
||||
let create_dir_name = ""
|
||||
let new_dir_name = ""
|
||||
let create_dir = () => {
|
||||
dispatch("loading", true)
|
||||
|
||||
let form = new FormData()
|
||||
form.append("type", "dir")
|
||||
|
||||
fs_create_directory(
|
||||
state.root.id, state.base.path, create_dir_name,
|
||||
fs_mkdir(
|
||||
state.root.id, state.base.path+"/"+new_dir_name,
|
||||
).then(resp => {
|
||||
create_dir_name = "" // Clear input field
|
||||
new_dir_name = "" // Clear input field
|
||||
}).catch(err => {
|
||||
alert("Error: "+err)
|
||||
}).finally(() => {
|
||||
@@ -28,7 +28,7 @@ onMount(() => { name_input.focus() })
|
||||
|
||||
<form class="create_dir highlight_shaded" on:submit|preventDefault={create_dir}>
|
||||
<img src="/res/img/mime/folder.png" class="icon" alt="icon"/>
|
||||
<input class="dirname" type="text" style="width: 100%;" bind:this={name_input} bind:value={create_dir_name} />
|
||||
<input class="dirname" type="text" style="width: 100%;" bind:this={name_input} bind:value={new_dir_name} />
|
||||
<input class="submit" type="submit" value="create"/>
|
||||
</form>
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { fs_delete_node } from './../FilesystemAPI.svelte'
|
||||
import { fs_delete } from './../FilesystemAPI.js'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import CreateDirectory from './CreateDirectory.svelte'
|
||||
import FileUploader from './FileUploader.svelte'
|
||||
@@ -67,7 +67,7 @@ const delete_selected = () => {
|
||||
let promises = []
|
||||
state.children.forEach(child => {
|
||||
if (!child.fm_selected) { return }
|
||||
promises.push(fs_delete_node(state.root.id, child.path))
|
||||
promises.push(fs_delete(state.root.id, child.path))
|
||||
})
|
||||
|
||||
// Wait for all the promises to finish
|
||||
|
@@ -67,17 +67,13 @@ const upload_file = () => {
|
||||
|
||||
console.log(job);
|
||||
|
||||
let form = new FormData();
|
||||
form.append("type", "file");
|
||||
form.append("file", job.file);
|
||||
|
||||
let url = window.api_endpoint+"/filesystem/"+bucket_id+encodeURIComponent(job.target_dir + "/" + job.file.name)
|
||||
if (write_password) {
|
||||
url += "?write_password="+write_password
|
||||
}
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", url, true);
|
||||
xhr.open("PUT", url, true);
|
||||
xhr.timeout = 21600000; // 6 hours, to account for slow connections
|
||||
|
||||
// Report progress updates back to the caller
|
||||
@@ -147,7 +143,8 @@ const upload_file = () => {
|
||||
|
||||
upload_jobs = upload_jobs;
|
||||
};
|
||||
xhr.send(form);
|
||||
|
||||
xhr.send(job.file);
|
||||
};
|
||||
|
||||
// File input dialog handling
|
||||
|
@@ -49,8 +49,9 @@ const node_icon = node => {
|
||||
<div class="directory">
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>name</td>
|
||||
<td>size</td>
|
||||
<td>Name</td>
|
||||
<td>Size</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{#each state.children as child, index (child.path)}
|
||||
<a
|
||||
@@ -71,6 +72,13 @@ const node_icon = node => {
|
||||
{formatDataVolume(child.file_size, 3)}
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
{#if child.id}
|
||||
<a href="/d/{child.id}" on:click|stopPropagation>
|
||||
<i class="icon" title="This file / directory is shared. Click to open public link">share</i>
|
||||
</a>
|
||||
{/if}
|
||||
</td>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { fs_get_file_url } from "../FilesystemAPI.svelte";
|
||||
import { fs_get_file_url } from "../FilesystemAPI.js";
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
let dispatch = createEventDispatcher()
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { fs_get_file_url } from "../FilesystemAPI.svelte";
|
||||
import { fs_get_file_url } from "../FilesystemAPI.js";
|
||||
|
||||
|
||||
export let state
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { fs_get_file_url } from "../FilesystemAPI.svelte";
|
||||
import { fs_get_file_url } from "../FilesystemAPI.js";
|
||||
export let state
|
||||
</script>
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import { fs_get_file_url } from "../FilesystemAPI.svelte";
|
||||
import { fs_get_file_url } from "../FilesystemAPI.js";
|
||||
import { createEventDispatcher, onMount } from 'svelte'
|
||||
let dispatch = createEventDispatcher()
|
||||
|
||||
|
Reference in New Issue
Block a user