aboutsummaryrefslogtreecommitdiff
path: root/static/main.js
diff options
context:
space:
mode:
authorJoris2024-06-02 14:38:13 +0200
committerJoris2024-06-02 14:38:22 +0200
commit1019ea1ed341e3a7769c046aa0be5764789360b6 (patch)
tree1a0d8a4f00cff252d661c42fc23ed4c19795da6f /static/main.js
parente8da9790dc6d55cd2e8883322cdf9a7bf5b4f5b7 (diff)
Migrate to Rust and Hyper
With sanic, downloading a file locally is around ten times slower than with Rust and hyper. Maybe `pypy` could have helped, but I didn’t succeed to set it up quickly with the dependencies.
Diffstat (limited to 'static/main.js')
-rw-r--r--static/main.js48
1 files changed, 0 insertions, 48 deletions
diff --git a/static/main.js b/static/main.js
deleted file mode 100644
index 1729d38..0000000
--- a/static/main.js
+++ /dev/null
@@ -1,48 +0,0 @@
-window.onload = function() {
- const form = document.querySelector('form')
-
- if (form !== null) {
- const submit = document.querySelector('input[type="submit"]')
- const loading = document.querySelector('.g-Loading')
- const error = document.querySelector('.g-Error')
-
- function showError(msg) {
- loading.style.display = 'none'
- submit.disabled = false
- error.innerText = msg
- error.style.display = 'block'
- }
-
- form.onsubmit = function(event) {
- event.preventDefault()
-
- loading.style.display = 'flex'
- submit.disabled = true
- error.style.display = 'none'
-
- const key = document.querySelector('input[name="key"]').value
- const expiration = document.querySelector('select[name="expiration"]').value
- const file = document.querySelector('input[name="file"]').files[0]
-
- // Wait a bit to prevent showing the loader too briefly
- setTimeout(function() {
- const xhr = new XMLHttpRequest()
- xhr.open('POST', '/', true)
- xhr.onload = function () {
- if (xhr.status === 200) {
- window.location = `/${xhr.responseText}`
- } else {
- showError(`Error uploading: ${xhr.status}`)
- }
- }
- xhr.onerror = function () {
- showError('Upload error')
- }
- xhr.setRequestHeader('X-FileName', file.name)
- xhr.setRequestHeader('X-Expiration', expiration)
- xhr.setRequestHeader('X-Key', key)
- xhr.send(file)
- }, 500)
- }
- }
-}