diff --git a/main.go b/main.go index a0b6bdf..f68c341 100755 --- a/main.go +++ b/main.go @@ -34,6 +34,7 @@ var initPath = "" var css = `css_will_be_here` // js will be embedded here var jsTag = `js_will_be_here` // id. var units = [8]string{"k", "M", "G", "T", "P", "E", "Z", "Y"} +var icon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAHlBMVEUAAAAAAACAgIDAwMD///8AAIAAAP8A//+AgAD//wACp+eHAAAAAXRSTlMAQObYZgAAAAFiS0dEBI9o2VEAAAAHdElNRQfiBhoALCQijt0NAAAAuElEQVQ4y92TQRKCMAxF0w4HCC5c18oJxAMwDEfAK+g52OkN9LYqbTRJ6Uyd0Y1vU+DlT0kJAAED+oJAtYKqTAJUiqkwmUAoxiVhMoFnOS4LkwZ8YBVXR89tK9hvSGyl6EnYQeJJNDLQlgjPaLioGSMX6+ObQnH6nvh88z8RB4YQYhaKvnlGeA3Ndq3Rw/6qVNjdz8X5wcTunY0vfxlu14k6cRa6Kh7RLOi8ugrQxK5mQS0i+4FVz3dvYZO5KVb6VAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxOC0wNi0yNlQwMDo0NDozNi0wNDowMNQdHpQAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTgtMDYtMjZUMDA6NDQ6MzYtMDQ6MDClQKYoAAAAAElFTkSuQmCC" type rpcCall struct { Call string `json:"call"` @@ -95,16 +96,16 @@ func replyList(w http.ResponseWriter, path string) { ` + html.EscapeString(path) + ` - + +
Drop here to upload
+

.` + html.EscapeString(path) + `

` + extraFolder("/hols/aaa") + `
-
Drop here to upload
-

.` + html.EscapeString(path) + `

` _files, err := ioutil.ReadDir(initPath + path) @@ -132,23 +133,14 @@ func replyList(w http.ResponseWriter, path string) { } } - var resp = head + dirs + files + `
-
- -
Gossa 🎶
- ` - - w.Write([]byte(resp)) + w.Write([]byte(head + dirs + files + ` +
Gossa 🎶
+ + `)) } func doContent(w http.ResponseWriter, r *http.Request) { path := html.UnescapeString(r.URL.Path) - - if strings.Contains(path, "/favicon.ico") { - w.Write([]byte(" ")) - return - } - fullPath, errPath := checkPath(path) stat, errStat := os.Stat(fullPath) diff --git a/script.js b/script.js index a37c820..780c0c5 100755 --- a/script.js +++ b/script.js @@ -12,7 +12,6 @@ function rpcFs (call, args, cb) { // Prefix path with pwd if not absolute const decodedPath = decodeURI(location.pathname) args = args.map(a => a.startsWith('/') ? a : decodedPath + a) - // args = args.map(a => encodeURIComponent(a)) console.log('RPC', call, args) const xhr = new window.XMLHttpRequest() @@ -44,25 +43,6 @@ function warning (e) { return 'Leaving will interrupt transfer\nAre you sure you want to leave?' } -// File upload -function newBar (name) { - const id = Math.random().toString(36).substring(7) - - document.getElementById('progressBars').innerHTML += '\ -
\ - ' + name.split('/').pop() + ' \ -
1%
\ -
' - return id -} - -function updatePercent (id, percent) { - const el = document.getElementById(id).querySelectorAll('div.barForeground')[0] - const width = Math.floor(100 * percent).toString() + '%' - el.innerText = width - el.style.width = width -} - function shouldRefresh () { totalDone += 1 if (totalUploads === totalDone) { @@ -70,33 +50,52 @@ function shouldRefresh () { console.log('Done uploading ' + totalDone + ' files') totalDone = 0 totalUploads = 0 - document.getElementById('progressBars').innerHTML = '' + totalUploadsSize = 0 + totalUploadedSize = [] + barDiv.style.display = 'none' refresh() } } const checkDupes = test => allA.find(a => a.innerText.replace('/', '') === test) +const barName = document.getElementById('dlBarName') + +const barPc = document.getElementById('dlBarPc') + +const barDiv = document.getElementById('progress') + +let totalDone = 0 +let totalUploads = 0 +let totalUploadsSize = 0 +let totalUploadedSize = [] + +function updatePercent (ev) { + totalUploadedSize[ev.target.id] = ev.loaded + const ttlDone = totalUploadedSize.reduce((s, x) => s + x) + const pc = Math.floor(100 * ttlDone / totalUploadsSize) + '%' + barPc.innerText = pc + barPc.style.width = pc +} + function postFile (file, path) { - totalUploads += 1 + path = decodeURI(location.pathname).slice(0, -1) + path window.onbeforeunload = warning - const xhr = new window.XMLHttpRequest() - path = decodeURI(location.pathname).slice(0, -1) + path - - xhr.open('POST', location.origin + '/post') - xhr.setRequestHeader('gossa-path', encodeURIComponent(path)) - xhr.upload.id = newBar(path) + barDiv.style.display = 'block' + totalUploads += 1 + totalUploadsSize += file.size + barName.innerText = totalUploads > 1 ? totalUploads + ' files' : file.name const formData = new window.FormData() formData.append(file.name, file) - xhr.upload.addEventListener('progress', a => { - updatePercent(a.target.id, a.loaded / a.total) - }) - + const xhr = new window.XMLHttpRequest() + xhr.open('POST', location.origin + '/post') + xhr.setRequestHeader('gossa-path', encodeURIComponent(path)) xhr.upload.addEventListener('load', shouldRefresh) - + xhr.upload.addEventListener('progress', updatePercent) + xhr.upload.id = totalUploads xhr.send(formData) } @@ -190,9 +189,6 @@ document.ondrop = (e) => { return false } -let totalUploads = 0 -let totalDone = 0 - const getArrowSelected = () => document.querySelectorAll('i.arrow-selected')[0] function getASelected () { @@ -218,7 +214,7 @@ function restoreCursorPos () { if (!a) { if (allA[0].innerText === '../') { - a = allA[1] + a = allA[1] || allA[0] } else { a = allA[0] } diff --git a/style.css b/style.css index 353e863..11af5eb 100755 --- a/style.css +++ b/style.css @@ -34,12 +34,16 @@ td.display-name { width: 100%; } - +h1 { + display: inline-block; + margin-top: 10px; +} .icHolder { - position: fixed; - right: 20px; - top: 20px; + display: inline-block; + right: 15px; + top: 25px; + position: absolute; } .ic { @@ -69,7 +73,7 @@ td.display-name { zoom: 1 !important; } -#progressBars { +#progress { background-color: white; width: 99%; left: 0.5%; @@ -80,18 +84,14 @@ td.display-name { max-height: 50%; overflow-y: scroll; overflow-x: hidden; - } - -#progressBars::-webkit-scrollbar { - display: none; } -.barBackground { +#dlBarName { width: 100%; margin-top: 15px; } -.barForeground { +#dlBarPc { width: 1%; height: 30px; text-align: center;