feat: support new file (#180)
This commit is contained in:
parent
6625c4d3d0
commit
a61fda6e80
2 changed files with 35 additions and 4 deletions
|
@ -53,10 +53,18 @@
|
||||||
d="M13.5 10a.5.5 0 0 1 .5.5V12h1.5a.5.5 0 1 1 0 1H14v1.5a.5.5 0 1 1-1 0V13h-1.5a.5.5 0 0 1 0-1H13v-1.5a.5.5 0 0 1 .5-.5z" />
|
d="M13.5 10a.5.5 0 0 1 .5.5V12h1.5a.5.5 0 1 1 0 1H14v1.5a.5.5 0 1 1-1 0V13h-1.5a.5.5 0 0 1 0-1H13v-1.5a.5.5 0 0 1 .5-.5z" />
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control new-file hidden" title="New File">
|
||||||
|
<svg width="16" height="16" viewBox="0 0 16 16">
|
||||||
|
<path
|
||||||
|
d="M8 6.5a.5.5 0 0 1 .5.5v1.5H10a.5.5 0 0 1 0 1H8.5V11a.5.5 0 0 1-1 0V9.5H6a.5.5 0 0 1 0-1h1.5V7a.5.5 0 0 1 .5-.5z" />
|
||||||
|
<path
|
||||||
|
d="M14 4.5V14a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2h5.5L14 4.5zm-3 0A1.5 1.5 0 0 1 9.5 3V1H4a1 1 0 0 0-1 1v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1V4.5h-2z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form class="searchbar hidden">
|
<form class="searchbar hidden">
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<svg width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
<svg width="16" height="16" viewBox="0 0 16 16">
|
||||||
<path
|
<path
|
||||||
d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" />
|
d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z" />
|
||||||
</svg>
|
</svg>
|
||||||
|
|
|
@ -84,7 +84,6 @@ function ready() {
|
||||||
|
|
||||||
if (DATA.kind == "Index") {
|
if (DATA.kind == "Index") {
|
||||||
document.title = `Index of ${DATA.href} - Dufs`;
|
document.title = `Index of ${DATA.href} - Dufs`;
|
||||||
|
|
||||||
document.querySelector(".index-page").classList.remove("hidden");
|
document.querySelector(".index-page").classList.remove("hidden");
|
||||||
|
|
||||||
if (DATA.allow_search) {
|
if (DATA.allow_search) {
|
||||||
|
@ -101,9 +100,12 @@ function ready() {
|
||||||
if (DATA.allow_upload) {
|
if (DATA.allow_upload) {
|
||||||
dropzone();
|
dropzone();
|
||||||
setupUpload();
|
setupUpload();
|
||||||
|
setupNewFile();
|
||||||
}
|
}
|
||||||
} else if (DATA.kind == "Edit") {
|
} else if (DATA.kind == "Edit") {
|
||||||
document.title = `Edit of ${DATA.href} - Dufs`;
|
document.title = `Edit of ${DATA.href} - Dufs`;
|
||||||
|
document.querySelector(".editor-page").classList.remove("hidden");;
|
||||||
|
|
||||||
|
|
||||||
setupEditor();
|
setupEditor();
|
||||||
}
|
}
|
||||||
|
@ -497,9 +499,16 @@ function setupUpload() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupEditor() {
|
function setupNewFile() {
|
||||||
document.querySelector(".editor-page").classList.remove("hidden");;
|
const $newFile = document.querySelector(".new-file");
|
||||||
|
$newFile.classList.remove("hidden");
|
||||||
|
$newFile.addEventListener("click", () => {
|
||||||
|
const name = prompt("Enter file name");
|
||||||
|
if (name) createFile(name);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupEditor() {
|
||||||
const $download = document.querySelector(".download")
|
const $download = document.querySelector(".download")
|
||||||
$download.classList.remove("hidden");
|
$download.classList.remove("hidden");
|
||||||
$download.href = baseUrl()
|
$download.href = baseUrl()
|
||||||
|
@ -557,6 +566,20 @@ async function createFolder(name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createFile(name) {
|
||||||
|
const url = newUrl(name);
|
||||||
|
try {
|
||||||
|
const res = await fetch(url, {
|
||||||
|
method: "PUT",
|
||||||
|
body: "",
|
||||||
|
});
|
||||||
|
await assertFetch(res);
|
||||||
|
location.href = url + "?edit";
|
||||||
|
} catch (err) {
|
||||||
|
alert(`Cannot create file \`${name}\`, ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function addFileEntries(entries, dirs) {
|
async function addFileEntries(entries, dirs) {
|
||||||
for (const entry of entries) {
|
for (const entry of entries) {
|
||||||
if (entry.isFile) {
|
if (entry.isFile) {
|
||||||
|
|
Loading…
Reference in a new issue