+ Generally useful helper functions

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

No files matched your search

+32 -1
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 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
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
}