+ Generally useful helper functions

This commit is contained in:
shockrah 2022-03-22 22:09:43 -07:00
parent 367c798320
commit d56bd6b7cd
2 changed files with 46 additions and 1 deletions

View File

@ -1,4 +1,35 @@
/*
* Module handles general responses for the admin feature
* Primarily these are responses for Admin related actions
* like fetching video's, updating videos and deleting them
* as well
*/
use serde::Serialize; use serde::Serialize;
use rocket::serde::json::Json;
const FAIL: &'static str = "fail";
const OK: &'static str = "fail";
#[derive(Serialize)] #[derive(Serialize)]
pub struct ActionResponse(pub &'static str); pub struct ActionResponse {
status: &'static str,
code: i32,
details: Option<&'static str>
}
pub fn ok() -> Json<ActionResponse> {
Json(ActionResponse {
status: OK,
code: 200,
details: None
})
}
pub fn bad_request(text: Option<&'static str>) -> Json<ActionResponse> {
Json(ActionResponse {
status: FAIL,
code: 400,
details: text
})
}

14
api/src/admin/util.rs Normal file
View File

@ -0,0 +1,14 @@
use std::path::PathBuf;
pub fn valid_filename(p: &PathBuf) -> bool {
// Checks if a given filename is actually valid or not
let mut valid = false;
let s = p.file_name().unwrap_or_default().to_string_lossy();
for e in [".mp4", ".webm", ".mkv"] {
if s.ends_with(e) {
valid = true;
break;
}
}
valid
}