+ Generally useful helper functions
This commit is contained in:
parent
367c798320
commit
d56bd6b7cd
@ -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 rocket::serde::json::Json;
|
||||
|
||||
const FAIL: &'static str = "fail";
|
||||
const OK: &'static str = "fail";
|
||||
|
||||
|
||||
#[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
14
api/src/admin/util.rs
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user