Made Ladybird browser fallback to chunked

This commit is contained in:
G2-Games 2025-03-06 00:54:33 -06:00
parent db07d75fa7
commit 710552fc1f
7 changed files with 20 additions and 10 deletions

View file

@ -35,6 +35,7 @@ pub fn home(settings: &State<Settings>) -> Markup {
center { center {
h1 { "Confetti-Box 🎉" } h1 { "Confetti-Box 🎉" }
h2 { "Files up to " (settings.max_filesize.bytes()) " in size are allowed!" } h2 { "Files up to " (settings.max_filesize.bytes()) " in size are allowed!" }
noscript { "Javascript must be enabled for this site to function!" }
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)" }

View file

@ -68,7 +68,8 @@ async fn main() {
confetti_box::home, confetti_box::home,
pages::api_info, pages::api_info,
pages::about, pages::about,
resources::favicon, resources::favicon_svg,
resources::favicon_ico,
resources::form_handler_js, resources::form_handler_js,
resources::stylesheet, resources::stylesheet,
resources::font_static, resources::font_static,

View file

@ -9,7 +9,7 @@ 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="/resources/main.css";
link rel="preload" href="/resources/fonts/Roboto.woff2" as="font" type="font/woff2" crossorigin; link rel="preload" href="/resources/fonts/Roboto.woff2" as="font" type="font/woff2" crossorigin;
link rel="preload" href="/resources/fonts/FiraCode.woff2" as="font" type="font/woff2" crossorigin; link rel="preload" href="/resources/fonts/FiraCode.woff2" as="font" type="font/woff2" crossorigin;

View file

@ -31,7 +31,12 @@ pub 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")]
pub fn favicon() -> (ContentType, &'static str) { pub fn favicon_svg() -> (ContentType, &'static str) {
(ContentType::SVG, include_str!("../web/favicon.svg")) (ContentType::SVG, include_str!("../web/favicon.svg"))
} }
#[get("/favicon.ico")]
pub fn favicon_ico() -> (ContentType, &'static [u8]) {
(ContentType::Icon, include_bytes!("../web/favicon.ico"))
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

@ -3,6 +3,8 @@
const TOO_LARGE_TEXT = "Too large!"; const TOO_LARGE_TEXT = "Too large!";
const ZERO_TEXT = "File is blank!"; const ZERO_TEXT = "File is blank!";
const ERROR_TEXT = "Error!"; const ERROR_TEXT = "Error!";
const USERAGENT = navigator.userAgent;
const USE_CHUNKS_COMPAT = /Ladybird/.test(USERAGENT);
async function formSubmit() { async function formSubmit() {
const form = document.getElementById("uploadForm"); const form = document.getElementById("uploadForm");
@ -63,27 +65,28 @@ async function pasteSubmit(evt) {
} }
async function sendFiles(files, duration, maxSize) { async function sendFiles(files, duration, maxSize) {
if (USE_CHUNKS_COMPAT) {
console.warn("This browser is known to have problems with WebSockets, falling back to chunked upload");
}
const inProgressUploads = new Set(); const inProgressUploads = new Set();
const concurrencyLimit = 10; const concurrencyLimit = 10;
// Create a reference for the Wake Lock. // Try to get a wake-lock
let wakeLock = null; let wakeLock = null;
// create an async function to request a wake lock
try { try {
wakeLock = await navigator.wakeLock.request("screen"); wakeLock = await navigator.wakeLock.request("screen");
} catch (err) { } catch (err) {
console.warn("Failed to set wake-lock!"); console.warn("Failed to set wake-lock!");
} }
let start = performance.now(); let start = performance.now();
for (const file of files) { for (const file of files) {
console.log("Started upload for", file.name); console.log("Started upload for", file.name);
// Start the upload and add it to the set of in-progress uploads // Start the upload and add it to the set of in-progress uploads
let uploadPromise; let uploadPromise;
if ('WebSocket' in window && window.WebSocket.CLOSING === 2) { if ('WebSocket' in window && window.WebSocket.CLOSING === 2 && !USE_CHUNKS_COMPAT) {
console.log("Uploading file using Websockets"); console.log("Uploading file using Websockets");
uploadPromise = uploadFileWebsocket(file, duration, maxSize); uploadPromise = uploadFileWebsocket(file, duration, maxSize);
} else { } else {
@ -230,7 +233,7 @@ async function uploadFileWebsocket(file, duration, maxSize) {
socket.send(""); socket.send("");
}); });
return new Promise(function(resolve, reject) { return new Promise(function(resolve, _reject) {
socket.addEventListener("message", (event) => { socket.addEventListener("message", (event) => {
const response = JSON.parse(event.data); const response = JSON.parse(event.data);
if (response.mmid == null) { if (response.mmid == null) {