Compare commits
2 commits
489c6ea8bf
...
12b0feba96
Author | SHA1 | Date | |
---|---|---|---|
12b0feba96 | |||
a9d4bc8b09 |
1 changed files with 16 additions and 10 deletions
|
@ -4,7 +4,7 @@ use askama::Template;
|
||||||
use async_zip::{base::write::ZipFileWriter, Compression, ZipEntryBuilder};
|
use async_zip::{base::write::ZipFileWriter, Compression, ZipEntryBuilder};
|
||||||
use axum::{
|
use axum::{
|
||||||
extract::{DefaultBodyLimit, Multipart, State},
|
extract::{DefaultBodyLimit, Multipart, State},
|
||||||
http::Response,
|
response::{IntoResponse, Response},
|
||||||
routing::post,
|
routing::post,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ pub fn get_upload_router() -> Router<AppState> {
|
||||||
async fn upload_to_zip(
|
async fn upload_to_zip(
|
||||||
State(state): State<AppState>,
|
State(state): State<AppState>,
|
||||||
mut body: Multipart,
|
mut body: Multipart,
|
||||||
) -> Result<Response<String>, (StatusCode, String)> {
|
) -> Result<Response, (StatusCode, String)> {
|
||||||
tracing::debug!("{:?}", *state.records.lock().await);
|
tracing::debug!("{:?}", *state.records.lock().await);
|
||||||
|
|
||||||
let cache_name = util::get_random_name(10);
|
let cache_name = util::get_random_name(10);
|
||||||
|
@ -78,19 +78,25 @@ async fn upload_to_zip(
|
||||||
let record = UploadRecord::new(archive_path);
|
let record = UploadRecord::new(archive_path);
|
||||||
records.insert(cache_name.clone(), record.clone());
|
records.insert(cache_name.clone(), record.clone());
|
||||||
|
|
||||||
cache::write_to_cache(&records)
|
let records_cache = records.clone();
|
||||||
|
// Manually drop the records mutex guard
|
||||||
|
drop(records);
|
||||||
|
|
||||||
|
cache::write_to_cache(&records_cache)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?;
|
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?;
|
||||||
|
|
||||||
writer.close().await.unwrap();
|
writer.close().await.unwrap();
|
||||||
|
|
||||||
let id = cache_name;
|
let id = cache_name;
|
||||||
let response = Response::builder()
|
let impl_response = (
|
||||||
.status(200)
|
StatusCode::OK,
|
||||||
.header("Content-Type", "text/html")
|
[
|
||||||
.header("HX-Push-Url", format!("/link/{}", &id))
|
("Content-Type", "text/html"),
|
||||||
.body(DownloadLinkFragment { id, record }.render().unwrap())
|
("HX-Push-Url", &format!("/link/{}", &id)),
|
||||||
.unwrap();
|
],
|
||||||
|
DownloadLinkFragment { id, record },
|
||||||
|
);
|
||||||
|
|
||||||
Ok(response)
|
Ok(impl_response.into_response())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue