|
|
|
@ -2,6 +2,9 @@ |
|
|
|
|
|
|
|
|
|
#[macro_use] extern crate rocket; |
|
|
|
|
|
|
|
|
|
use std::env; |
|
|
|
|
use std::path::Path; |
|
|
|
|
|
|
|
|
|
use std::process::Command; |
|
|
|
|
use rocket::request::Form; |
|
|
|
|
use rocket_contrib::serve::StaticFiles; |
|
|
|
@ -14,20 +17,32 @@ struct Video { |
|
|
|
|
|
|
|
|
|
#[post("/new", data = "<video>")] |
|
|
|
|
fn new(video: Form<Video>) -> Redirect { |
|
|
|
|
if video.link.starts_with("https://"){ |
|
|
|
|
Command::new("/bin/env") |
|
|
|
|
// .args(&[&video.link])
|
|
|
|
|
.args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&video.link).to_string()]) |
|
|
|
|
.output() |
|
|
|
|
.expect("Failed to execute command"); |
|
|
|
|
for part in video.link.split(" ") { |
|
|
|
|
if part.starts_with("https://"){ |
|
|
|
|
Command::new("/bin/env") |
|
|
|
|
// .args(&[&video.link])
|
|
|
|
|
.args(&["DISPLAY=:0", "bash", "-c", &format!("mpv {link}", link=&part).to_string()]) |
|
|
|
|
.output() |
|
|
|
|
.expect("Failed to execute command"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Redirect::to("/") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
|
rocket::ignite() |
|
|
|
|
.mount("/", routes![new]) |
|
|
|
|
.mount("/", StaticFiles::from("static")) |
|
|
|
|
.launch(); |
|
|
|
|
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() |
|
|
|
|
.mount("/", routes![new]) |
|
|
|
|
.mount("/", StaticFiles::from("static")) |
|
|
|
|
.launch(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|