diff --git a/server/Cargo.toml b/server/Cargo.toml index 72a20fd..db3ccfd 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -26,7 +26,6 @@ sha2 = "0.10" jwt = "0.16" rand = "0.8.5" email_address = "0.2.9" -# Change back to crates.io version when https://github.com/lawliet89/rocket_cors/pull/108 is published memolanes_core = { git = "https://github.com/MemoLanes/MemoLanes.git", rev = "cee5400" } rocket_cors = "0.6.0" base64 = "0.22.1" diff --git a/server/src/main.rs b/server/src/main.rs index 5c171b9..db96168 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -22,6 +22,7 @@ use std::sync::Mutex; mod data_fetcher; mod file_storage; mod limit; +mod memolanes_archive_handler; mod misc_handler; mod pool; mod snapshot_handler; @@ -179,5 +180,6 @@ fn rocket() -> _ { .mount("/api/v1/snapshot_task", snapshot_task_handler::routes()) .mount("/api/v1/snapshot_log", snapshot_log_handler::routes()) .mount("/api/v1/snapshot", snapshot_handler::routes()) + .mount("/api/v1/memolanes_archive", memolanes_archive_handler::routes()) .mount("/api/v1/misc", misc_handler::routes()) } diff --git a/server/src/memolanes_archive_handler.rs b/server/src/memolanes_archive_handler.rs new file mode 100644 index 0000000..81594c4 --- /dev/null +++ b/server/src/memolanes_archive_handler.rs @@ -0,0 +1,20 @@ +use crate::misc_handler; +use crate::user_handler::User; +use crate::{APIResponse, ServerState}; +use rocket::http::Status; +use serde_json::json; + +#[get("/download_token")] +async fn get_download_token(server_state: &rocket::State, user: User) -> APIResponse { + let download_item = misc_handler::DownloadItem::MemolanesArchive { uid: user.uid }; + Ok(( + Status::Ok, + json!({ + "token": misc_handler::generate_download_token(server_state, download_item) + }), + )) +} + +pub fn routes() -> Vec { + routes![get_download_token] +} diff --git a/server/src/snapshot_handler.rs b/server/src/snapshot_handler.rs index 4c812c6..e1805b4 100644 --- a/server/src/snapshot_handler.rs +++ b/server/src/snapshot_handler.rs @@ -246,22 +246,8 @@ async fn delete(conn: Connection<'_, Db>, user: User, snapshot_id: i64) -> APIRe } } -#[get("/memoleanes_archive/download_token")] -async fn get_memoleanes_archive_download_token( - server_state: &rocket::State, - user: User, -) -> APIResponse { - let download_item = misc_handler::DownloadItem::MemolanesArchive { uid: user.uid }; - Ok(( - Status::Ok, - json!({ - "token": misc_handler::generate_download_token(server_state,download_item) - }), - )) -} - #[get("//download_token")] -async fn get_snapshot_download_token( +async fn get_download_token( conn: Connection<'_, Db>, server_state: &rocket::State, user: User, @@ -279,7 +265,7 @@ async fn get_snapshot_download_token( Ok(( Status::Ok, json!({ - "token": misc_handler::generate_download_token(server_state,download_item) + "token": misc_handler::generate_download_token(server_state, download_item) }), )) } else { @@ -362,8 +348,7 @@ pub fn routes() -> Vec { create, delete, update, - get_snapshot_download_token, - get_memoleanes_archive_download_token, + get_download_token, get_editor_view ] }