sync
This commit is contained in:
parent
d8a77905f9
commit
ad9cf01d90
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -331,6 +331,7 @@ name = "fastcloud"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"rand 0.8.5",
|
||||||
"rocket",
|
"rocket",
|
||||||
"rocket_contrib",
|
"rocket_contrib",
|
||||||
"rocket_upload",
|
"rocket_upload",
|
||||||
|
|
|
@ -11,3 +11,4 @@ rocket_upload = "0.1.0"
|
||||||
rocket_contrib = { version = "0.4.10", default-features = false, features = ["handlebars_templates"] }
|
rocket_contrib = { version = "0.4.10", default-features = false, features = ["handlebars_templates"] }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
rand = "0.8.5"
|
||||||
|
|
9
Dockerfile
Normal file
9
Dockerfile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FROM rustlang/rust:nightly
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
COPY Cargo.toml ./
|
||||||
|
COPY src ./src
|
||||||
|
COPY templates ./templates
|
||||||
|
|
||||||
|
|
||||||
|
RUN cargo build --release
|
|
@ -1 +0,0 @@
|
||||||
abcde
|
|
49
src/main.rs
49
src/main.rs
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#![feature(proc_macro_hygiene, decl_macro)]
|
#![feature(proc_macro_hygiene, decl_macro)]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -6,17 +5,16 @@ extern crate rocket;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
use std::path::{PathBuf, Path};
|
use std::path::{PathBuf, Path};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use rocket::response::NamedFile;
|
use rocket::response::{NamedFile, Redirect};
|
||||||
use rocket::http::ContentType;
|
use rocket::http::ContentType;
|
||||||
use rocket_contrib::templates::Template;
|
use rocket_contrib::templates::Template;
|
||||||
use rocket_upload::MultipartDatas;
|
use rocket_upload::MultipartDatas;
|
||||||
use serde::Serialize;
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct DirPath {
|
struct DirPath {
|
||||||
|
@ -25,10 +23,20 @@ struct DirPath {
|
||||||
name: String,
|
name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(FromForm, Deserialize)]
|
||||||
|
struct LoginInfo {
|
||||||
|
key: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref DIR: PathBuf = Path::new(env::var("FASTCLOUD_DIR").unwrap_or_else(|_| String::from("")).as_str()).to_path_buf();
|
static ref DIR: PathBuf = Path::new(env::var("FASTCLOUD_DIR").unwrap_or_else(|_| String::from("")).as_str()).to_path_buf();
|
||||||
|
static ref ADMIN_KEY: PathBuf = Path::new(env::var("FASTCLOUD_ADMIN_KEY").unwrap_or_else(|_| String::from("")).as_str()).to_path_buf();
|
||||||
|
static ref USER_KEY: PathBuf = Path::new(env::var("FASTCLOUD_USER_KEY").unwrap_or_else(|_| String::from("")).as_str()).to_path_buf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[get("/serve")]
|
#[get("/serve")]
|
||||||
fn get_root() -> Template {
|
fn get_root() -> Template {
|
||||||
let path = DIR.as_path().to_str().unwrap_or("");
|
let path = DIR.as_path().to_str().unwrap_or("");
|
||||||
|
@ -49,13 +57,15 @@ fn create_dir(path: PathBuf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/del/<path..>")]
|
#[post("/del/<path..>")]
|
||||||
fn delete(path: PathBuf) {
|
fn delete(path: PathBuf) -> Redirect {
|
||||||
let dir = DIR.as_path().join(path);
|
let dir = DIR.as_path().join(path.clone());
|
||||||
if dir.is_file() {
|
if dir.is_file() {
|
||||||
fs::remove_dir_all(dir).unwrap();
|
|
||||||
} else {
|
|
||||||
fs::remove_file(dir).unwrap();
|
fs::remove_file(dir).unwrap();
|
||||||
|
} else {
|
||||||
|
fs::remove_dir_all(dir).unwrap();
|
||||||
}
|
}
|
||||||
|
let npath = path.parent().unwrap().to_path_buf();
|
||||||
|
Redirect::to(uri!(get_dir_entry: npath))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn directory_structure(path: String) -> HashMap<&'static str, HashMap<i32, DirPath>> {
|
fn directory_structure(path: String) -> HashMap<&'static str, HashMap<i32, DirPath>> {
|
||||||
|
@ -75,10 +85,19 @@ fn directory_structure(path: String) -> HashMap<&'static str, HashMap<i32, DirPa
|
||||||
path: dir.strip_prefix(DIR.clone().into_os_string().into_string().unwrap()).unwrap().parent().unwrap_or_else(|| Path::new("")).to_str().unwrap().to_string(),
|
path: dir.strip_prefix(DIR.clone().into_os_string().into_string().unwrap()).unwrap().parent().unwrap_or_else(|| Path::new("")).to_str().unwrap().to_string(),
|
||||||
name: dir.parent().unwrap().file_name().unwrap_or_else(|| OsStr::new("")).to_str().unwrap().to_string(),
|
name: dir.parent().unwrap().file_name().unwrap_or_else(|| OsStr::new("")).to_str().unwrap().to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let current = DirPath {
|
||||||
|
is_file: false,
|
||||||
|
path: dir.strip_prefix(DIR.clone().into_os_string().into_string().unwrap()).unwrap_or_else(|_| Path::new("")).to_str().unwrap().to_string(),
|
||||||
|
name: dir.file_name().unwrap_or_else(|| OsStr::new("")).to_str().unwrap().to_string(),
|
||||||
|
};
|
||||||
let mut pt = HashMap::new();
|
let mut pt = HashMap::new();
|
||||||
pt.insert(0, parent);
|
pt.insert(0, parent);
|
||||||
context.insert("ctx", paths);
|
|
||||||
context.insert("parent", pt);
|
context.insert("parent", pt);
|
||||||
|
let mut pt = HashMap::new();
|
||||||
|
pt.insert(0, current);
|
||||||
|
context.insert("current", pt);
|
||||||
|
context.insert("ctx", paths);
|
||||||
context
|
context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,8 +109,8 @@ fn file_get(path: PathBuf) -> Option<NamedFile> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/upload/<path..>", data = "<data>")]
|
#[post("/upload/<path..>", data = "<data>")]
|
||||||
fn upload_file(path: PathBuf, _content_type: &ContentType, data:MultipartDatas) {
|
fn upload_file(path: PathBuf, _content_type: &ContentType, data:MultipartDatas) -> Redirect {
|
||||||
let dir = DIR.as_path().join(path);
|
let dir = DIR.as_path().join(path.clone());
|
||||||
for f in data.files {
|
for f in data.files {
|
||||||
if !Path::new(&format!("{}/{}", dir.to_str().unwrap(), f.filename)).exists() {
|
if !Path::new(&format!("{}/{}", dir.to_str().unwrap(), f.filename)).exists() {
|
||||||
f.persist(&dir);
|
f.persist(&dir);
|
||||||
|
@ -103,8 +122,16 @@ fn upload_file(path: PathBuf, _content_type: &ContentType, data:MultipartDatas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Redirect::to(uri!(get_dir_entry: path))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: move files
|
||||||
|
// TODO: rename files
|
||||||
|
// TODO: rewrite frontend
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
{{! vim: set ft=html: }}
|
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||||
|
@ -10,6 +8,10 @@
|
||||||
<div class="vstack gap-3">
|
<div class="vstack gap-3">
|
||||||
<div class="bg-light border rounded-3 p-2">
|
<div class="bg-light border rounded-3 p-2">
|
||||||
<div class="d-grid gap-2">
|
<div class="d-grid gap-2">
|
||||||
|
<form action="/upload/{{current.0.path}}" method="post" enctype="multipart/form-data">
|
||||||
|
<input type="file" id="file" name="upload"/>
|
||||||
|
<input type="submit" value="Upload"/>
|
||||||
|
</form>
|
||||||
<a type="button" class="btn btn-outline-secondary text-start col-sm-1" href="/serve/{{parent.0.path}}" role="button">
|
<a type="button" class="btn btn-outline-secondary text-start col-sm-1" href="/serve/{{parent.0.path}}" role="button">
|
||||||
..
|
..
|
||||||
</a>
|
</a>
|
||||||
|
@ -26,9 +28,11 @@
|
||||||
{{name}}
|
{{name}}
|
||||||
</a>
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<!-- <a type="button" class="btn btn-outline-danger text-start col-sm-1 ms-1 me-1" href="/del/{{path}}", role="button">
|
<form action="/del/{{path}}" method="post">
|
||||||
<i class="bi bi-trash"></i>
|
<button class="btn btn-outline-danger text-start ms-1 me-1">
|
||||||
</a> -->
|
<i class="bi bi-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user