copy text and other small changes
This commit is contained in:
@ -45,8 +45,10 @@ async fn upload_file(mut upload: FileStream) -> Result<String, HttpError> {
|
||||
}
|
||||
};
|
||||
|
||||
if upload.size().unwrap() > UPLOAD_SIZE_LIMIT {
|
||||
return HttpError::payload_too_large("this file is too large");
|
||||
if let Some(size) = upload.size() {
|
||||
if size > UPLOAD_SIZE_LIMIT {
|
||||
return HttpError::payload_too_large("this file is too large");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +62,7 @@ async fn upload_file(mut upload: FileStream) -> Result<String, HttpError> {
|
||||
Ok(bytes) => {
|
||||
total_len += bytes.len() as u64;
|
||||
if total_len > UPLOAD_SIZE_LIMIT {
|
||||
error = Some("Uploaded file to large");
|
||||
error = Some("Uploaded file too large");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -97,7 +99,11 @@ pub fn build_table(files: Vec<(String, String, Option<Result<String, HttpError>>
|
||||
td { class: "px-2",
|
||||
match &file.2 {
|
||||
Some(res) => { match res {
|
||||
Ok(file_id) => { rsx! { input { type:"button" , "/upload/dl/{file_id}"} } },
|
||||
Ok(file_url) => {let url = file_url.clone(); rsx! { input {
|
||||
type:"button",
|
||||
onclick: move |_| { web_sys::window().unwrap().navigator().clipboard().write_text(&url); },
|
||||
value: "{file_url}"
|
||||
} } },
|
||||
Err(e) => {
|
||||
let msg = e.message.clone().unwrap();
|
||||
rsx! { p { "Upload failed, reason : {msg}" } }
|
||||
@ -144,7 +150,13 @@ pub fn Upload() -> Element {
|
||||
return ;
|
||||
}
|
||||
|
||||
let res = upload_file(file.clone().into()).await;
|
||||
let res = match upload_file(file.clone().into()).await {
|
||||
Ok(file_id) => {
|
||||
let host = web_sys::window().unwrap().location().host().expect("unknown_host");
|
||||
Ok(host + "/upload/" + &file_id)
|
||||
},
|
||||
Err(err) => { Err(err) }
|
||||
};
|
||||
selected.with_mut(|files| { files[idx].2 = Some(res) });
|
||||
}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user