Skip to content
Snippets Groups Projects
Unverified Commit c132792f authored by Louis's avatar Louis :fire:
Browse files

Fix all cargo check issues

parent 7fecc3cf
No related branches found
No related tags found
1 merge request!2Scripting
......@@ -7,7 +7,6 @@ use std::default::Default;
use serde::{Deserialize, Deserializer, de};
use std::fmt;
use serde_yaml as yaml;
use std::collections::HashMap;
use cli;
#[derive(Debug, Copy, Clone)]
......
use rocket::{Data, State};
use formdata::{read_formdata, FilePart};
use routing::request::ConvertedHeaders;
use hyper::header::{Headers, ContentDisposition, DispositionParam};
use rocket::request::FromRequest;
use std::io::{Read, Write, copy};
use std::io::{BufReader, BufWriter};
use hyper::header::{ContentDisposition, DispositionParam};
use std::io::{copy};
use std::fs::{OpenOptions, File, create_dir};
use cli::{HandlerMethod, SwerveConfig};
use std::path::{Path, PathBuf};
use std::path::{PathBuf};
use std::collections::HashMap;
use rand::{Rng, StdRng};
#[post(path = "/", data = "<upload>")]
pub fn to_file(headers: ConvertedHeaders, conf: State<SwerveConfig>, upload: Data) -> Result<String, String> {
......@@ -21,7 +18,12 @@ pub fn to_file(headers: ConvertedHeaders, conf: State<SwerveConfig>, upload: Dat
HandlerMethod::File => println!("{:?}", fields),
}
create_dir("uploads");
match create_dir("uploads") {
Ok(_) => {},
Err(err) => {
return Err(format!("Could not create uploads directory:\n{}", err));
}
}
for file in data.files {
match conf.file_handling {
......@@ -49,17 +51,17 @@ type Upload = (String, FilePart);
fn upload_file(file: Upload) {
let (name, value) = file;
let content_disposition = value.headers.get::<ContentDisposition>().unwrap();
let file_name = filename_from_disposition(content_disposition);
let file_name = filename_from_disposition(content_disposition).unwrap_or(name);
let mut input = File::open(value.path.clone()).unwrap();
let mut output = OpenOptions::new()
.write(true)
.create(true)
.open(PathBuf::from("uploads").join(file_name.clone().unwrap_or(String::from("upload_data"))))
.open(PathBuf::from("uploads").join(file_name.clone()))
.unwrap();
copy(&mut input, &mut output).unwrap();
println!("File written to {}", file_name.unwrap());
println!("File written to {}", file_name);
}
fn log_file(file: Upload) {
......
......@@ -2,7 +2,7 @@ use rocket::{self, Outcome, http, Response};
use rocket::request::{FromRequest, Request};
use rocket::http::ContentType;
use hyper::header::Headers;
use std::path::{Path, PathBuf, Component};
use std::path::{Path, PathBuf};
use std::io::BufReader;
use std::fs::File;
......
use scripting::run_script;
use std::path::PathBuf;
use routing::request;
use server::LuaRuntime;
use rlua::{Lua};
#[get("/__testing__/run-script")]
pub fn route_script(path: request::RequestPath, runtime: LuaRuntime) -> String {
let lua: Lua = runtime.into();
let _lua: Lua = runtime.into(); //todo: Use This
let doowap = path.0;
let foo = request::path::MatchablePath(String::from("/inspection/@id"));
let foo = request::path::MatchablePath(String::from(doowap));
let matches = foo.matches(String::from("/inspection/123"));
println!("{:?}", matches);
let path = PathBuf::from("example/.swerve/get_user_by_id.rhai");
run_script(path).unwrap_or(String::from("No script"))
String::from("Yes")
}
\ No newline at end of file
use std::convert::AsRef;
use std::path::Path;
use std::fs::File;
use std::sync::Arc;
use std::io::Read;
use std::collections::HashMap;
pub fn run_script<P: AsRef<Path>>(path: P) -> Option<String> {
let mut file = File::open(&path).unwrap();
let mut buf = String::new();
file.read_to_string(&mut buf);
match file.read_to_string(&mut buf) {
Ok(_) => {},
Err(_) => return None,
}
Some(buf)
}
\ No newline at end of file
use rlua::{Lua};
use rocket::{self, Outcome, http, Response};
use rocket::{Outcome, http};
use rocket::request::{FromRequest, Request};
use std::convert::{Into, AsRef, AsMut};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment