-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Heng-Bian/dev
optimize the ui and README
- Loading branch information
Showing
6 changed files
with
132 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ body { | |
margin-right: 10px; | ||
} | ||
|
||
label { | ||
.sub-div { | ||
display: flex; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,90 @@ | ||
function read() { | ||
let remoteUrl = document.getElementById("url-input").value | ||
let charset = document.getElementById("encoding-input").value | ||
try { | ||
new URL(remoteUrl) | ||
let queryParams = new URLSearchParams() | ||
queryParams.set("charset", charset) | ||
queryParams.set("url", remoteUrl) | ||
fetch("/list" + "?" + queryParams.toString()) | ||
.then(res => { | ||
if (res.status == 500) { | ||
res.text().then(message => { | ||
alert(message) | ||
}) | ||
} else { | ||
res.json().then( | ||
json => { | ||
files = json["Files"] | ||
let entries = document.getElementById("download-entries"); | ||
entries.innerHTML = "" | ||
for (let i in files) { | ||
let option = document.createElement("option") | ||
option.appendChild(document.createTextNode(files[i])); | ||
option.setAttribute("value", files[i]); | ||
entries.appendChild(option); | ||
(() => { | ||
const remoteUrl = document.getElementById("url-input") | ||
const charset = document.getElementById("encoding-input") | ||
const entries = document.getElementById("download-entries") | ||
|
||
const readButton = document.getElementById("read") | ||
const downloadButton = document.getElementById("download") | ||
const urlInput = document.getElementById("url-input") | ||
|
||
function read() { | ||
try { | ||
new URL(remoteUrl.value) | ||
let queryParams = new URLSearchParams() | ||
queryParams.set("charset", charset.value) | ||
queryParams.set("url", remoteUrl.value) | ||
fetch("/list" + "?" + queryParams.toString()) | ||
.then(res => { | ||
if (res.status == 500) { | ||
res.text().then(message => { | ||
alert(message) | ||
}) | ||
} else { | ||
res.json().then( | ||
json => { | ||
files = json["Files"] | ||
let entries = document.getElementById("download-entries"); | ||
entries.innerHTML = "" | ||
for (let i in files) { | ||
let option = document.createElement("option") | ||
option.appendChild(document.createTextNode(files[i])); | ||
option.setAttribute("value", files[i]); | ||
entries.appendChild(option); | ||
} | ||
} | ||
} | ||
) | ||
} | ||
}) | ||
} catch (error) { | ||
alert(error) | ||
) | ||
} | ||
}) | ||
} catch (error) { | ||
alert(errovaluer) | ||
} | ||
} | ||
} | ||
|
||
function download() { | ||
let remoteUrl = document.getElementById("url-input").value | ||
let charset = document.getElementById("encoding-input").value | ||
let options = document.getElementById("download-entries").options | ||
let files = [] | ||
for (let i in options) { | ||
if (options[i].selected) { | ||
files.push(options[i].value) | ||
function download() { | ||
let files = [] | ||
let options = entries.options | ||
for (let i in options) { | ||
if (options[i].selected) { | ||
files.push(options[i].value) | ||
} | ||
} | ||
if (files.length == 0) { | ||
alert("no seleted files!") | ||
return | ||
} | ||
let queryParams = new URLSearchParams() | ||
queryParams.set("charset", charset.value) | ||
queryParams.set("url", remoteUrl.value) | ||
fetch("/pack" + "?" + queryParams.toString(), { | ||
method: 'POST', | ||
body: JSON.stringify(files), | ||
}).then(res => { | ||
if (res.status == 500) { | ||
res.text().then(message => { | ||
alert(message) | ||
}) | ||
} else { | ||
const fileStream = streamSaver.createWriteStream("package.zip") | ||
const readableStream = res.body; | ||
if (window.WritableStream && readableStream.pipeTo) { | ||
return readableStream.pipeTo(fileStream).then(() => { | ||
|
||
}) | ||
} | ||
window.writer = fileStream.getWriter(); | ||
const reader = res.body.getReader(); | ||
const pump = () => reader.read().then(res => res.done ? window.writer.close() : window.writer.write(res.value).then(pump)) | ||
pump() | ||
} | ||
}) | ||
} | ||
if (files.length == 0) { | ||
alert("no seleted files!") | ||
return | ||
|
||
function clearFiles() { | ||
entries.innerHTML = "" | ||
} | ||
let queryParams = new URLSearchParams() | ||
queryParams.set("charset", charset) | ||
queryParams.set("url", remoteUrl) | ||
fetch("/pack" + "?" + queryParams.toString(), { | ||
method: 'POST', | ||
body: JSON.stringify(files), | ||
}).then(res => { | ||
if (res.status == 500) { | ||
res.text().then(message => { | ||
alert(message) | ||
}) | ||
} else { | ||
const fileStream = streamSaver.createWriteStream("pack.zip") | ||
const readableStream = res.body; | ||
if (window.WritableStream && readableStream.pipeTo) { | ||
return readableStream.pipeTo(fileStream).then(() => { | ||
|
||
}) | ||
} | ||
window.writer = fileStream.getWriter(); | ||
const reader = res.body.getReader(); | ||
const pump = () => reader.read().then(res => res.done ? window.writer.close() : window.writer.write(res.value).then(pump)) | ||
pump() | ||
} | ||
}) | ||
} | ||
readButton.addEventListener("click", read) | ||
downloadButton.addEventListener("click", download) | ||
urlInput.addEventListener("change", clearFiles) | ||
})() | ||
|
||
function clearFiles() { | ||
document.getElementById("download-entries").innerHTML = "" | ||
} |