+ Rust docs where needed
There may be more changes that could be added to improve documentation however this is meant to be a good start. !+ There is also a new redirect endpoint for /admin/dashboard This just a convenience thing so that people don't have to remember the '/dashboard' part of the admin route.
This commit is contained in:
@@ -12,12 +12,18 @@ use std::path::{Path, PathBuf};
|
||||
use rocket::data::{Data, ToByteUnit};
|
||||
use rocket::serde::json::Json;
|
||||
use rocket_dyn_templates::Template;
|
||||
use rocket::response::Redirect;
|
||||
use response::{bad_request, ok};
|
||||
|
||||
use apikey::ApiKey;
|
||||
use response::ActionResponse;
|
||||
use crate::common::get_clips_dir;
|
||||
|
||||
#[get("/")]
|
||||
pub async fn login_dashboard_redirect() -> Redirect {
|
||||
Redirect::to("/admin/dashboard")
|
||||
}
|
||||
|
||||
#[get("/dashboard")]
|
||||
pub async fn login_dashboard() -> Template {
|
||||
// This page is basically just a login form
|
||||
@@ -37,9 +43,11 @@ pub async fn dashboard(_key: ApiKey) -> Json<ActionResponse> {
|
||||
#[post("/upload-video/<category>/<filename>", data = "<data>")]
|
||||
pub async fn updload_video(_key: ApiKey, category: PathBuf, filename: PathBuf, data: Data<'_>)
|
||||
-> Result<Json<ActionResponse>> {
|
||||
// filenames must have a basename .len of at least 1 + '.' + extension
|
||||
// Valid file extensions are mkv|mp4|webm
|
||||
|
||||
/*
|
||||
* Uploads must have BOTH a valid filename and a category
|
||||
* Without the category the server will simply not find
|
||||
* the correct endpoint to reach and thus will 404
|
||||
*/
|
||||
if util::valid_filename(&filename) == false {
|
||||
return Ok(bad_request(Some("Invalid filename(s)")));
|
||||
}
|
||||
@@ -47,8 +55,14 @@ pub async fn updload_video(_key: ApiKey, category: PathBuf, filename: PathBuf, d
|
||||
let clips = get_clips_dir();
|
||||
fs::create_dir_all(Path::new(&clips).join(&category))?;
|
||||
|
||||
/*
|
||||
* We allow up to 200 Megaytes per upload as most short
|
||||
* clips are not going to be very large anyway and this
|
||||
* should be a reasonably high limit for those that want
|
||||
* to upload "large" clips
|
||||
* */
|
||||
let filepath = Path::new(&clips).join(category).join(filename);
|
||||
data.open(200.megabytes()).into_file(filepath).await?;
|
||||
data.open(250.megabytes()).into_file(filepath).await?;
|
||||
Ok(ok())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user