2023-05-11 19:07:29 +02:00
|
|
|
<script>
|
2023-05-17 19:27:46 +02:00
|
|
|
import { fs_delete_all, fs_rename, fs_update } from "./FilesystemAPI";
|
2023-05-17 15:34:56 +02:00
|
|
|
import Modal from "../util/Modal.svelte";
|
2023-05-11 19:07:29 +02:00
|
|
|
|
|
|
|
|
export let bucket = ""
|
2023-05-17 22:46:27 +02:00
|
|
|
export let fs_navigator
|
2023-05-11 19:07:29 +02:00
|
|
|
let file = {
|
|
|
|
|
path: "",
|
|
|
|
|
name: "",
|
|
|
|
|
id: "",
|
|
|
|
|
mode_octal: "",
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-17 15:34:56 +02:00
|
|
|
export let visible
|
2023-05-25 14:47:36 +02:00
|
|
|
export const edit = (f, oae = false, t = "file") => {
|
|
|
|
|
file = f
|
|
|
|
|
open_after_edit = oae
|
2023-05-17 19:27:46 +02:00
|
|
|
tab = t
|
|
|
|
|
|
2023-05-25 14:47:36 +02:00
|
|
|
console.log("Editing file", file)
|
2023-05-11 19:07:29 +02:00
|
|
|
|
|
|
|
|
file_name = file.name
|
|
|
|
|
shared = !(file.id === undefined || file.id === "")
|
|
|
|
|
read_password = file.read_password ? file.read_password : ""
|
|
|
|
|
write_password = file.write_password ? file.write_password : ""
|
2023-05-17 15:34:56 +02:00
|
|
|
visible = true
|
2023-05-11 19:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-17 19:27:46 +02:00
|
|
|
let tab = "file"
|
2023-05-25 14:47:36 +02:00
|
|
|
let open_after_edit = false
|
2023-05-17 19:27:46 +02:00
|
|
|
|
2023-05-11 19:07:29 +02:00
|
|
|
let file_name = ""
|
|
|
|
|
let shared = false
|
|
|
|
|
let read_password = ""
|
|
|
|
|
let write_password = ""
|
|
|
|
|
|
|
|
|
|
const save = async () => {
|
2023-05-17 19:27:46 +02:00
|
|
|
console.debug("Saving file", file.path)
|
2023-05-11 19:07:29 +02:00
|
|
|
try {
|
|
|
|
|
await fs_update(
|
|
|
|
|
bucket,
|
|
|
|
|
file.path,
|
|
|
|
|
{
|
|
|
|
|
shared: shared,
|
|
|
|
|
read_password: read_password,
|
|
|
|
|
write_password: write_password,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if (file_name !== file.name) {
|
|
|
|
|
let parent = file.path.slice(0, -file.name.length)
|
|
|
|
|
console.log("Moving", file.path, "to", parent+file_name)
|
|
|
|
|
|
|
|
|
|
await fs_rename(bucket, file.path, parent+file_name)
|
2023-05-17 15:34:56 +02:00
|
|
|
file.path = parent+file_name
|
2023-05-11 19:07:29 +02:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err)
|
|
|
|
|
alert(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-25 14:47:36 +02:00
|
|
|
if (open_after_edit) {
|
|
|
|
|
fs_navigator.navigate(file.path, false)
|
|
|
|
|
} else {
|
|
|
|
|
fs_navigator.reload()
|
|
|
|
|
}
|
2023-05-17 19:27:46 +02:00
|
|
|
}
|
|
|
|
|
const delete_file = async () => {
|
|
|
|
|
try {
|
|
|
|
|
await fs_delete_all(bucket, file.path)
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error(err)
|
|
|
|
|
alert(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-05-11 19:07:29 +02:00
|
|
|
|
2023-05-25 14:47:36 +02:00
|
|
|
if (open_after_edit) {
|
|
|
|
|
fs_navigator.navigate(file.path, false)
|
|
|
|
|
} else {
|
|
|
|
|
fs_navigator.reload()
|
|
|
|
|
}
|
2023-05-17 15:34:56 +02:00
|
|
|
visible = false
|
|
|
|
|
}
|
2023-05-11 19:07:29 +02:00
|
|
|
</script>
|
|
|
|
|
|
2023-05-25 14:47:36 +02:00
|
|
|
<Modal bind:visible={visible} title="Edit {file.name}" width="600px" form="file_edit_form">
|
2023-05-17 19:27:46 +02:00
|
|
|
<div class="tab_bar">
|
|
|
|
|
<button class:button_highlight={tab === "file"} on:click={() => tab = "file"}>
|
|
|
|
|
<i class="icon">edit</i>
|
|
|
|
|
Edit file
|
|
|
|
|
</button>
|
|
|
|
|
<button class:button_highlight={tab === "share"} on:click={() => tab = "share"}>
|
|
|
|
|
<i class="icon">share</i>
|
|
|
|
|
Sharing settings
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<form id="file_edit_form" on:submit|preventDefault={save} style="display: flex; padding: 8px;">
|
|
|
|
|
{#if tab === "file"}
|
|
|
|
|
<div class="form">
|
|
|
|
|
<span class="header">File settings</span>
|
|
|
|
|
<label for="file_name">Name:</label>
|
|
|
|
|
<input bind:value={file_name} id="file_name" type="text" class="form_input"/>
|
|
|
|
|
<span class="header">Delete</span>
|
|
|
|
|
<p>
|
|
|
|
|
Delete this file or directory. If this is a directory then all
|
|
|
|
|
subfiles will be deleted as well. This action cannot be undone.
|
|
|
|
|
</p>
|
|
|
|
|
<button on:click|preventDefault={delete_file} class="button_red" style="align-self: flex-start;">
|
|
|
|
|
<i class="icon small">delete</i> Delete
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
{:else if tab === "share"}
|
|
|
|
|
<div class="form">
|
|
|
|
|
<span class="header">
|
|
|
|
|
Sharing settings
|
|
|
|
|
</span>
|
|
|
|
|
<p>
|
|
|
|
|
When a file or directory is shared it can be accessed
|
|
|
|
|
through a unique link. You can get the URL with the 'Copy
|
|
|
|
|
link' button on the toolbar, or share the link with the
|
|
|
|
|
'Share' button. If you share a directory all the files
|
|
|
|
|
within the directory are also accessible from the link.
|
|
|
|
|
</p>
|
|
|
|
|
<div>
|
|
|
|
|
<input bind:checked={shared} id="shared" type="checkbox" class="form_input"/>
|
|
|
|
|
<label for="shared">Share this file or directory</label>
|
|
|
|
|
</div>
|
|
|
|
|
<label for="read_password">Read password:</label>
|
|
|
|
|
<input bind:value={read_password} id="read_password" type="text" class="form_input"/>
|
|
|
|
|
<label for="write_password">Write password:</label>
|
|
|
|
|
<input bind:value={write_password} id="write_password" type="text" class="form_input"/>
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2023-05-11 19:07:29 +02:00
|
|
|
</form>
|
|
|
|
|
</Modal>
|
2023-05-17 19:27:46 +02:00
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.header {
|
2023-05-19 21:45:42 +02:00
|
|
|
margin-top: 1em;
|
2023-05-17 19:27:46 +02:00
|
|
|
font-size: 1.5em;
|
|
|
|
|
border-bottom: 1px var(--separator) solid;
|
|
|
|
|
}
|
|
|
|
|
.tab_bar {
|
|
|
|
|
border-bottom: 2px solid var(--separator);
|
|
|
|
|
}
|
|
|
|
|
</style>
|