-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
571d7c5
commit f7a64ef
Showing
9 changed files
with
310 additions
and
288 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,15 @@ authors = ["Johann Rekowski <[email protected]>"] | |
repository = "https://github.com/HitomiTenshi/dekinai.git" | ||
license = "MIT" | ||
edition = "2021" | ||
rust-version = "1.59" | ||
rust-version = "1.64" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
actix-multipart = "0.4" | ||
actix-web = { version = "4", default-features = false, features = ["macros"] } | ||
async-recursion = "1" | ||
clap = { version = "3", features = ["cargo", "env", "wrap_help"] } | ||
clap = { version = "4", features = ["cargo", "env", "wrap_help"] } | ||
derive_more = { version = "0.99", default-features = false, features = ["display", "error"] } | ||
futures-util = { version = "0.3", default-features = false } | ||
num_cpus = "1" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,27 +27,24 @@ For more information try `--help`: | |
``` | ||
$ dekinai.exe --help | ||
dekinai 1.1.0 | ||
Johann Rekowski <[email protected]> | ||
Dekinai is a simple and minimalistic file uploading API. | ||
It provides the bare minimum feature set for file hosting services, while also being fast and portable. | ||
USAGE: | ||
dekinai.exe [OPTIONS] <OUTPUT_DIR> | ||
ARGS: | ||
<OUTPUT_DIR> Sets the directory for uploaded files | ||
OPTIONS: | ||
-b, --blacklist <FILE_EXTENSIONS>... Sets a list of disallowed file extensions | ||
Usage: --blacklist asp html php | ||
-d, --database <DATABASE_DIR> Sets the directory for the SQLite database [default: ./] | ||
--disable-port Disables port listening (Unix only) | ||
-h, --help Print help information | ||
-p, --port <NUMBER> Sets the port number to listen on [default: 54298] | ||
--password <TEXT> Sets a password for API requests [env: DEKINAI_PASSWORD=] | ||
-u, --unix <FILE> Sets the unix socket to listen on (Unix only) | ||
-V, --version Print version information | ||
Usage: dekinai.exe [OPTIONS] <OUTPUT_DIRECTORY> | ||
Arguments: | ||
<OUTPUT_DIRECTORY> Sets the directory for uploaded files | ||
Options: | ||
-p, --port [<NUMBER>] Sets the port number to listen on [default: 54298] | ||
-u, --unix [<FILE>] Sets the unix socket to listen on (Unix only) | ||
-d, --database [<DIRECTORY>] Sets the directory for the SQLite database [default: ./] | ||
--password [<TEXT>] Sets a password for API requests [env: DEKINAI_PASSWORD=] | ||
-b, --blacklist <FILE_EXTENSIONS>... Sets a list of disallowed file extensions | ||
Usage: --blacklist asp html php | ||
--disable-port Disables port listening (Unix only) | ||
-h, --help Print help information | ||
-V, --version Print version information | ||
``` | ||
|
||
## API | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,32 @@ | ||
use clap::{arg, command, ArgMatches}; | ||
use std::ops::RangeInclusive; | ||
use std::path::Path; | ||
|
||
const PORT_RANGE: RangeInclusive<usize> = 1..=65535; | ||
use clap::{arg, command, value_parser, ArgAction, ArgMatches}; | ||
use std::path::PathBuf; | ||
|
||
pub fn get_matches() -> ArgMatches { | ||
command!() | ||
.arg(arg!(output: <OUTPUT_DIR> "Sets the directory for uploaded files").validator(validate_dir)) | ||
.arg( | ||
arg!(-p --port <NUMBER> "Sets the port number to listen on") | ||
.required(false) | ||
.default_value("54298") | ||
.validator(|value| { | ||
value | ||
.parse::<usize>() | ||
.map(|port| PORT_RANGE.contains(&port)) | ||
.map_err(|err| err.to_string()) | ||
.and_then(|result| if result { Ok(()) } else { Err(format!( | ||
"Port needs to be a number between {} and {}", | ||
PORT_RANGE.start(), | ||
PORT_RANGE.end() | ||
)) }) | ||
}), | ||
) | ||
.arg(arg!(-u --unix <FILE> "Sets the unix socket to listen on (Unix only)").required(false)) | ||
.arg( | ||
arg!(-d --database <DATABASE_DIR> "Sets the directory for the SQLite database") | ||
.required(false) | ||
.default_value("./") | ||
.validator(validate_dir) | ||
) | ||
.arg(arg!(--password <TEXT> "Sets a password for API requests").required(false).env("DEKINAI_PASSWORD").validator(|value| { | ||
if value.is_ascii() { | ||
Ok(()) | ||
} else { | ||
Err("Password needs to contain only ASCII characters") | ||
} | ||
})) | ||
.arg(arg!(-b --blacklist <FILE_EXTENSIONS> "Sets a list of disallowed file extensions\nUsage: --blacklist asp html php").required(false).multiple_values(true)) | ||
.arg(arg!(--"disable-port" "Disables port listening (Unix only)").required(false).requires("unix").conflicts_with("port")) | ||
.arg(arg!(output: <OUTPUT_DIRECTORY> "Sets the directory for uploaded files").value_parser(validate_dir)) | ||
.arg(arg!(-p --port [NUMBER] "Sets the port number to listen on").default_value("54298").value_parser(value_parser!(u16).range(1..))) | ||
.arg(arg!(-u --unix [FILE] "Sets the unix socket to listen on (Unix only)").value_parser(value_parser!(PathBuf))) | ||
.arg(arg!(-d --database [DIRECTORY] "Sets the directory for the SQLite database").default_value("./").value_parser(validate_dir)) | ||
.arg(arg!(--password [TEXT] "Sets a password for API requests").env("DEKINAI_PASSWORD").value_parser(validate_password)) | ||
.arg(arg!(-b --blacklist [FILE_EXTENSIONS] ... "Sets a list of disallowed file extensions\nUsage: --blacklist asp html php").num_args(1..)) | ||
.arg(arg!(--"disable-port" "Disables port listening (Unix only)").requires("unix").conflicts_with("port").action(ArgAction::SetTrue)) | ||
.get_matches() | ||
} | ||
|
||
fn validate_dir(path: &str) -> Result<(), String> { | ||
if Path::new(path).is_dir() { | ||
Ok(()) | ||
fn validate_dir(value: &str) -> Result<PathBuf, String> { | ||
let path = PathBuf::from(value); | ||
|
||
if path.is_dir() { | ||
Ok(path) | ||
} else { | ||
Err(format!("Cannot access directory \"{}\"", value)) | ||
} | ||
} | ||
|
||
fn validate_password(value: &str) -> Result<String, String> { | ||
if value.is_ascii() { | ||
Ok(value.to_owned()) | ||
} else { | ||
Err(format!("Cannot access directory \"{}\"", path)) | ||
Err("Password needs to contain only ASCII characters".to_owned()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.