From 3c6206849fb5c9d9ef75d26d8667f0340749aae5 Mon Sep 17 00:00:00 2001 From: sigoden Date: Sat, 1 Apr 2023 16:10:34 +0800 Subject: [PATCH] chore: trivial improvements --- assets/index.js | 7 ++++++- src/server.rs | 11 +++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/assets/index.js b/assets/index.js index 9f10fc4..7b99784 100644 --- a/assets/index.js +++ b/assets/index.js @@ -216,7 +216,11 @@ Uploader.runQueue = async () => { if (!uploader) return; if (!Uploader.auth) { Uploader.auth = true; - await login(); + try { + await login(); + } catch { + Uploader.auth = false; + } } uploader.ajax(); } @@ -643,6 +647,7 @@ async function saveChange() { method: "PUT", body: $editor.value, }); + location.reload(); } catch (err) { alert(`Failed to save file, ${err.message}`); } diff --git a/src/server.rs b/src/server.rs index f6e712a..ec3dcfa 100644 --- a/src/server.rs +++ b/src/server.rs @@ -12,9 +12,9 @@ use async_zip::{Compression, ZipDateTime, ZipEntryBuilder}; use chrono::{LocalResult, TimeZone, Utc}; use futures::TryStreamExt; use headers::{ - AcceptRanges, AccessControlAllowCredentials, AccessControlAllowOrigin, Connection, - ContentLength, ContentType, ETag, HeaderMap, HeaderMapExt, IfModifiedSince, IfNoneMatch, - IfRange, LastModified, Range, + AcceptRanges, AccessControlAllowCredentials, AccessControlAllowOrigin, ContentLength, + ContentType, ETag, HeaderMap, HeaderMapExt, IfModifiedSince, IfNoneMatch, IfRange, + LastModified, Range, }; use hyper::header::{ HeaderValue, AUTHORIZATION, CONTENT_DISPOSITION, CONTENT_LENGTH, CONTENT_RANGE, CONTENT_TYPE, @@ -942,8 +942,8 @@ impl Server { fn auth_reject(&self, res: &mut Response) -> Result<()> { let value = self.args.auth_method.www_auth(false)?; set_webdav_headers(res); - res.headers_mut().typed_insert(Connection::close()); res.headers_mut().insert(WWW_AUTHENTICATE, value.parse()?); + // set 401 to make the browser pop up the login box *res.status_mut() = StatusCode::UNAUTHORIZED; Ok(()) } @@ -973,8 +973,7 @@ impl Server { self.args.auth_method.clone(), ); if guard_type.is_reject() { - *res.status_mut() = StatusCode::FORBIDDEN; - *res.body_mut() = Body::from("Forbidden"); + status_forbid(res); return None; }