Add get_wup Admin API routes

This commit is contained in:
BloxerHD 2026-04-23 17:19:49 +01:00
commit 4d5436bca9
5 changed files with 56 additions and 3 deletions

View file

@ -11,7 +11,7 @@ sqlx = { version = "0.8.3", features = [ "postgres", "runtime-tokio", "macros",
serde = { version = "1.0", features = [ "derive" ] } serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1" serde_json = "1"
quick-xml = { version = "0.31", features = [ "serialize" ] } quick-xml = { version = "0.31", features = [ "serialize" ] }
chrono = "0.4" chrono = { version = "0.4", features = [ "serde" ] }
sha1 = "0.10" sha1 = "0.10"
sha2 = "0.10" sha2 = "0.10"
hex = "0.4" hex = "0.4"

50
src/api/get_files_wup.rs Normal file
View file

@ -0,0 +1,50 @@
use rocket::{State, http::Status, serde::json::Json};
use serde::Deserialize;
use crate::Pool;
use crate::auth::Auth;
use crate::database::{get_wup_task_file_by_data_id, get_wup_task_files};
use crate::models::file_wup::FileWUP;
#[derive(Deserialize)]
pub struct GetFilesWUPOptions {
pub allow_deleted: bool,
pub boss_app_id: String,
pub task_id: String,
pub country: Option<String>,
pub language: Option<String>,
pub any: Option<bool>,
}
#[rocket::get("/api/v1/get_wup", data = "<input>")]
pub async fn get_files_wup(
pool: &State<Pool>,
input: Json<GetFilesWUPOptions>,
_auth: Auth,
) -> Json<Vec<FileWUP>> {
let data = input.into_inner();
let files = get_wup_task_files(
pool,
data.allow_deleted,
data.boss_app_id,
data.task_id,
data.country,
data.language,
data.any,
).await;
return Json(files);
}
#[rocket::get("/api/v1/get_wup/<id>")]
pub async fn get_file_wup_by_data_id(
pool: &State<Pool>,
id: i64,
_auth: Auth,
) -> Result<Json<FileWUP>, Status> {
if let Some(file) = get_wup_task_file_by_data_id(pool, id).await {
return Ok(Json(file));
} else {
return Err(Status::NotFound);
}
}

View file

@ -1,2 +1,3 @@
pub mod upload_file_wup; pub mod upload_file_wup;
pub mod get_files_wup;
pub mod add_task; pub mod add_task;

View file

@ -82,6 +82,8 @@ async fn launch() -> _ {
services::npdi::data, services::npdi::data,
api::upload_file_wup::upload_file_wup, api::upload_file_wup::upload_file_wup,
api::add_task::add_task, api::add_task::add_task,
api::get_files_wup::get_files_wup,
api::get_files_wup::get_file_wup_by_data_id,
]) ])
.register("/", catchers![not_found]) .register("/", catchers![not_found])
} }

View file

@ -71,7 +71,7 @@ pub struct FileWUPAttributes {
pub description: String, pub description: String,
} }
#[derive(FromRow, Clone)] #[derive(FromRow, Clone, Serialize)]
pub struct FileWUP { pub struct FileWUP {
pub deleted: bool, pub deleted: bool,
pub file_key: String, pub file_key: String,
@ -92,4 +92,4 @@ pub struct FileWUP {
pub auto_delete: bool, pub auto_delete: bool,
pub created: NaiveDateTime, pub created: NaiveDateTime,
pub updated: NaiveDateTime, pub updated: NaiveDateTime,
} }