Compare commits

..

No commits in common. "37b6838866cb58146e4215b88ecbae9660c66f19" and "0f780d027d629eeecc15ed674b9e6b3f76d0142a" have entirely different histories.

4 changed files with 19 additions and 33 deletions

View file

@ -25,18 +25,18 @@ use utils::hash_file;
use uuid::Uuid;
/// Stylesheet
#[get("/resources/main.css")]
#[get("/main.css")]
fn stylesheet() -> RawCss<&'static str> {
RawCss(include_str!("../web/main.css"))
}
/// Upload handler javascript
#[get("/resources/request.js")]
#[get("/request.js")]
fn form_handler_js() -> RawJavaScript<&'static str> {
RawJavaScript(include_str!("../web/request.js"))
}
#[get("/resources/favicon.svg")]
#[get("/favicon.svg")]
fn favicon() -> (ContentType, &'static str) {
(ContentType::SVG, include_str!("../web/favicon.svg"))
}
@ -45,7 +45,7 @@ fn favicon() -> (ContentType, &'static str) {
fn home(settings: &State<Settings>) -> Markup {
html! {
(head("Confetti-Box"))
script src="/resources/request.js" { }
script src="./request.js" { }
center {
h1 { "Confetti-Box 🎉" }
@ -53,7 +53,7 @@ fn home(settings: &State<Settings>) -> Markup {
hr;
button.main_file_upload #fileButton onclick="document.getElementById('fileInput').click()" {
h4 { "Upload File(s)" }
p { "Click, Paste, or Drag and Drop" }
p { "Click or Drag and Drop" }
}
h3 { "Expire after:" }
div id="durationBox" {

View file

@ -9,8 +9,8 @@ pub fn head(page_title: &str) -> Markup {
meta charset="UTF-8";
meta name="viewport" content="width=device-width, initial-scale=1";
title { (page_title) }
link rel="icon" type="image/svg+xml" href="/resources/favicon.svg";
link rel="stylesheet" href="/resources/main.css";
link rel="icon" type="image/svg+xml" href="favicon.svg";
link rel="stylesheet" href="./main.css";
}
}

View file

@ -81,7 +81,7 @@ pre {
background-color: #161b22;
font-size: 11pt;
padding: 10px;
overflow: auto;
overflow: scroll;
tab-size: 4;
}

View file

@ -10,7 +10,7 @@ async function formSubmit() {
const duration = form.elements.duration.value;
const maxSize = form.elements.fileUpload.dataset.maxFilesize;
await sendFile(files, duration, maxSize);
await fileSend(files, duration, maxSize);
// Reset the form file data since we've successfully submitted it
form.elements.fileUpload.value = "";
@ -20,6 +20,12 @@ async function dragDropSubmit(evt) {
const form = document.getElementById("uploadForm");
const duration = form.elements.duration.value;
const files = getDroppedFiles(evt);
await fileSend(files, duration);
}
function getDroppedFiles(evt) {
evt.preventDefault();
const files = [];
@ -38,25 +44,10 @@ async function dragDropSubmit(evt) {
});
}
await sendFile(files, duration);
return files;
}
async function pasteSubmit(evt) {
const form = document.getElementById("uploadForm");
const duration = form.elements.duration.value;
evt.preventDefault();
const files = [];
[...evt.clipboardData.files].forEach((file, _) => {
// If dropped items aren't files, reject them
files.push(file);
});
await sendFile(files, duration);
}
async function sendFile(files, duration, maxSize) {
async function fileSend(files, duration, maxSize) {
for (const file of files) {
const [linkRow, progressBar, progressText] = addNewToList(file.name);
if (file.size > maxSize) {
@ -101,6 +92,7 @@ function makeErrored(progressBar, progressText, linkRow, errorMessage) {
function makeFinished(progressBar, progressText, linkRow, response) {
progressText.textContent = "";
const _name = encodeURIComponent(response.name);
const link = progressText.appendChild(document.createElement("a"));
link.textContent = response.mmid;
link.href = "/f/" + response.mmid;
@ -199,17 +191,11 @@ async function initEverything() {
// This is the entrypoint for everything basically
document.addEventListener("DOMContentLoaded", function(_event) {
// Respond to form submissions
const form = document.getElementById("uploadForm");
form.addEventListener("submit", formSubmit);
// Respond to file paste events
window.addEventListener("paste", (event) => {pasteSubmit(event)});
// Respond to drag and drop stuff
let fileButton = document.getElementById("fileButton");
document.addEventListener("drop", (e) => {e.preventDefault();}, false);
document.addEventListener("dragover", (e) => {e.preventDefault()}, false);
fileButton.addEventListener("dragover", (e) => {e.preventDefault();}, false);
fileButton.addEventListener("drop", dragDropSubmit, false);