#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; use std::env; use std::fmt; use std::path::Path; use rocket::request::FromFormValue; use rocket::http::RawStr; use rocket::http::uri::Absolute; use rocket::request::Form; use rocket::response::Redirect; use rocket_contrib::serve::StaticFiles; use std::process::Command; #[derive(Debug)] struct Link { uri: String } #[derive(FromForm)] struct Video { link: Link, } // Always use a limit to prevent DoS attacks. const LIMIT: u64 = 1024; impl fmt::Display for Link { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.uri) } } impl<'v> FromFormValue<'v> for Link { type Error = &'v RawStr; fn from_form_value(form_value: &'v RawStr) -> Result { // Decode form data into string let string = match form_value.url_decode() { Ok(string) => string, Err(_) => return Err(form_value) }; // Try to parse a hyperlink from the string let mut abs_uri: Option = None; for part in string.split(' ') { println!("{}", part); abs_uri = match Absolute::parse(part) { Ok(abs_uri) => Some(abs_uri), Err(_) => continue, }; break; } // Check for success let result = match abs_uri { Some(abs_uri) => Link{uri: abs_uri.to_string()}, _ => return Err(form_value) }; // Return successfully. Ok(result) } } #[post("/new", data = "