chore: trivial improvements

This commit is contained in:
sigoden 2023-04-01 16:10:34 +08:00
parent 652f836c23
commit 3c6206849f
2 changed files with 11 additions and 7 deletions

View file

@ -216,7 +216,11 @@ Uploader.runQueue = async () => {
if (!uploader) return; if (!uploader) return;
if (!Uploader.auth) { if (!Uploader.auth) {
Uploader.auth = true; Uploader.auth = true;
await login(); try {
await login();
} catch {
Uploader.auth = false;
}
} }
uploader.ajax(); uploader.ajax();
} }
@ -643,6 +647,7 @@ async function saveChange() {
method: "PUT", method: "PUT",
body: $editor.value, body: $editor.value,
}); });
location.reload();
} catch (err) { } catch (err) {
alert(`Failed to save file, ${err.message}`); alert(`Failed to save file, ${err.message}`);
} }

View file

@ -12,9 +12,9 @@ use async_zip::{Compression, ZipDateTime, ZipEntryBuilder};
use chrono::{LocalResult, TimeZone, Utc}; use chrono::{LocalResult, TimeZone, Utc};
use futures::TryStreamExt; use futures::TryStreamExt;
use headers::{ use headers::{
AcceptRanges, AccessControlAllowCredentials, AccessControlAllowOrigin, Connection, AcceptRanges, AccessControlAllowCredentials, AccessControlAllowOrigin, ContentLength,
ContentLength, ContentType, ETag, HeaderMap, HeaderMapExt, IfModifiedSince, IfNoneMatch, ContentType, ETag, HeaderMap, HeaderMapExt, IfModifiedSince, IfNoneMatch, IfRange,
IfRange, LastModified, Range, LastModified, Range,
}; };
use hyper::header::{ use hyper::header::{
HeaderValue, AUTHORIZATION, CONTENT_DISPOSITION, CONTENT_LENGTH, CONTENT_RANGE, CONTENT_TYPE, HeaderValue, AUTHORIZATION, CONTENT_DISPOSITION, CONTENT_LENGTH, CONTENT_RANGE, CONTENT_TYPE,
@ -942,8 +942,8 @@ impl Server {
fn auth_reject(&self, res: &mut Response) -> Result<()> { fn auth_reject(&self, res: &mut Response) -> Result<()> {
let value = self.args.auth_method.www_auth(false)?; let value = self.args.auth_method.www_auth(false)?;
set_webdav_headers(res); set_webdav_headers(res);
res.headers_mut().typed_insert(Connection::close());
res.headers_mut().insert(WWW_AUTHENTICATE, value.parse()?); res.headers_mut().insert(WWW_AUTHENTICATE, value.parse()?);
// set 401 to make the browser pop up the login box
*res.status_mut() = StatusCode::UNAUTHORIZED; *res.status_mut() = StatusCode::UNAUTHORIZED;
Ok(()) Ok(())
} }
@ -973,8 +973,7 @@ impl Server {
self.args.auth_method.clone(), self.args.auth_method.clone(),
); );
if guard_type.is_reject() { if guard_type.is_reject() {
*res.status_mut() = StatusCode::FORBIDDEN; status_forbid(res);
*res.body_mut() = Body::from("Forbidden");
return None; return None;
} }