tokenize video link, force setting config path via env

master
CptCaptain 4 years ago
parent e976c3d1a3
commit d2ae892a70
  1. 19
      src/main.rs

@ -2,6 +2,9 @@
#[macro_use] extern crate rocket; #[macro_use] extern crate rocket;
use std::env;
use std::path::Path;
use std::process::Command; use std::process::Command;
use rocket::request::Form; use rocket::request::Form;
use rocket_contrib::serve::StaticFiles; use rocket_contrib::serve::StaticFiles;
@ -14,17 +17,29 @@ struct Video {
#[post("/new", data = "<video>")] #[post("/new", data = "<video>")]
fn new(video: Form<Video>) -> Redirect { fn new(video: Form<Video>) -> Redirect {
if video.link.starts_with("https://"){ for part in video.link.split(" ") {
if part.starts_with("https://"){
Command::new("/bin/env") Command::new("/bin/env")
// .args(&[&video.link]) // .args(&[&video.link])
.args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&video.link).to_string()]) .args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&part).to_string()])
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");
} }
}
Redirect::to("/") Redirect::to("/")
} }
fn main() { fn main() {
let env_config_path = match env::var("CONFIG_PATH") {
Ok(val) => val,
Err(_e) => panic!("Please provide a config path via the CONFIG_PATH env variable!"),
};
let config_path = Path::new(&env_config_path);
match env::set_current_dir(&config_path).is_ok() {
true => println!("Config path set"),
false => panic!("Config path could not be set!"),
};
rocket::ignite() rocket::ignite()
.mount("/", routes![new]) .mount("/", routes![new])
.mount("/", StaticFiles::from("static")) .mount("/", StaticFiles::from("static"))

Loading…
Cancel
Save