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

View file

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

View file

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

View file

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