Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
CaviarChen committed Oct 21, 2024
1 parent 64fdaac commit 591f82f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
1 change: 0 additions & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
}
20 changes: 20 additions & 0 deletions server/src/memolanes_archive_handler.rs
Original file line number Diff line number Diff line change
@@ -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<ServerState>, 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<rocket::Route> {
routes![get_download_token]
}
21 changes: 3 additions & 18 deletions server/src/snapshot_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerState>,
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("/<snapshot_id>/download_token")]
async fn get_snapshot_download_token(
async fn get_download_token(
conn: Connection<'_, Db>,
server_state: &rocket::State<ServerState>,
user: User,
Expand All @@ -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 {
Expand Down Expand Up @@ -362,8 +348,7 @@ pub fn routes() -> Vec<rocket::Route> {
create,
delete,
update,
get_snapshot_download_token,
get_memoleanes_archive_download_token,
get_download_token,
get_editor_view
]
}

0 comments on commit 591f82f

Please sign in to comment.