tokenize video link, force setting config path via env

master
CptCaptain 4 years ago
parent e976c3d1a3
commit d2ae892a70
  1. 35
      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,20 +17,32 @@ 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(" ") {
Command::new("/bin/env") if part.starts_with("https://"){
// .args(&[&video.link]) Command::new("/bin/env")
.args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&video.link).to_string()]) // .args(&[&video.link])
.output() .args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&part).to_string()])
.expect("Failed to execute command"); .output()
.expect("Failed to execute command");
}
} }
Redirect::to("/") Redirect::to("/")
} }
fn main() { fn main() {
rocket::ignite() let env_config_path = match env::var("CONFIG_PATH") {
.mount("/", routes![new]) Ok(val) => val,
.mount("/", StaticFiles::from("static")) Err(_e) => panic!("Please provide a config path via the CONFIG_PATH env variable!"),
.launch(); };
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()
.mount("/", routes![new])
.mount("/", StaticFiles::from("static"))
.launch();
} }

Loading…
Cancel
Save