namespace all our variables
This commit is contained in:
parent
14508183ab
commit
458f791fe3
13
README.md
13
README.md
|
@ -21,9 +21,14 @@
|
|||
## configuration
|
||||
|
||||
transbeam is configured with the following environment variables:
|
||||
- `STORAGE_DIR`: path where uploaded files should be stored (default: `./storage`)
|
||||
- `STATIC_DIR`: path where the web app's static files live (default: `./static`)
|
||||
- `PORT`: port to listen on localhost for http requests (default: 8080)
|
||||
- `TRANSBEAM_STORAGE_DIR`: path where uploaded files should be stored (default: `./storage`)
|
||||
- `TRANSBEAM_STATIC_DIR`: path where the web app's static files live (default: `./static`)
|
||||
- `TRANSBEAM_PORT`: port to listen on localhost for http requests (default: 8080)
|
||||
- `TRANSBEAM_MAX_LIFETIME`: maximum number of days files can be kept for (default: 30)
|
||||
- `TRANSBEAM_MAX_UPLOAD_SIZE`: maximum size, in bytes, of a fileset
|
||||
being uploaded (default: 16GiB)
|
||||
- `TRANSBEAM_MAX_STORAGE_SIZE`: maximum total size, in bytes, of all
|
||||
files being stored by transbeam (default: 64GiB)
|
||||
- `RUST_LOG`: log levels, for the app as a whole and/or for specific
|
||||
submodules/libraries. See
|
||||
[`env_logger`](https://docs.rs/env_logger/latest/env_logger/)'s
|
||||
|
@ -37,7 +42,7 @@ transbeam is configured with the following environment variables:
|
|||
nix run git+https://git.xeno.science/xenofem/transbeam?ref=main
|
||||
```
|
||||
|
||||
(The Nix package is wrapped with `STATIC_DIR` set automatically to the
|
||||
(The Nix package is wrapped with `TRANSBEAM_STATIC_DIR` set automatically to the
|
||||
correct Nix store path, so it'll serve the static files properly
|
||||
no matter what directory you run it from.)
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
buildInputs = [ pkgs.makeWrapper ];
|
||||
postBuild = ''
|
||||
wrapProgram $out/bin/${name} \
|
||||
--set STATIC_DIR ${./static}
|
||||
--set TRANSBEAM_STATIC_DIR ${./static}
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
|
@ -57,8 +57,8 @@ async fn main() -> std::io::Result<()> {
|
|||
start_reaper(data.clone());
|
||||
|
||||
let static_dir =
|
||||
PathBuf::from(std::env::var("STATIC_DIR").unwrap_or_else(|_| String::from("static")));
|
||||
let port = std::env::var("PORT")
|
||||
PathBuf::from(std::env::var("TRANSBEAM_STATIC_DIR").unwrap_or_else(|_| String::from("static")));
|
||||
let port = std::env::var("TRANSBEAM_PORT")
|
||||
.ok()
|
||||
.and_then(|p| p.parse::<u16>().ok())
|
||||
.unwrap_or(8080);
|
||||
|
|
10
src/store.rs
10
src/store.rs
|
@ -12,12 +12,12 @@ const STATE_FILE_NAME: &str = "files.json";
|
|||
const DEFAULT_STORAGE_DIR: &str = "storage";
|
||||
const DEFAULT_MAX_LIFETIME: u32 = 30;
|
||||
const GIGA: u64 = 1024*1024*1024;
|
||||
const DEFAULT_MAX_SINGLE_SIZE: u64 = 16*GIGA;
|
||||
const DEFAULT_MAX_TOTAL_SIZE: u64 = 64*GIGA;
|
||||
const DEFAULT_MAX_UPLOAD_SIZE: u64 = 16*GIGA;
|
||||
const DEFAULT_MAX_STORAGE_SIZE: u64 = 64*GIGA;
|
||||
|
||||
|
||||
pub(crate) fn storage_dir() -> PathBuf {
|
||||
PathBuf::from(std::env::var("STORAGE_DIR").unwrap_or_else(|_| String::from(DEFAULT_STORAGE_DIR)))
|
||||
PathBuf::from(std::env::var("TRANSBEAM_STORAGE_DIR").unwrap_or_else(|_| String::from(DEFAULT_STORAGE_DIR)))
|
||||
}
|
||||
|
||||
fn parse_env_var<T: FromStr>(var: &str, default: T) -> T {
|
||||
|
@ -29,11 +29,11 @@ pub(crate) fn max_lifetime() -> u32 {
|
|||
}
|
||||
|
||||
pub(crate) fn max_single_size() -> u64 {
|
||||
parse_env_var("TRANSBEAM_MAX_SINGLE_FILE_SIZE", DEFAULT_MAX_SINGLE_SIZE)
|
||||
parse_env_var("TRANSBEAM_MAX_UPLOAD_SIZE", DEFAULT_MAX_UPLOAD_SIZE)
|
||||
}
|
||||
|
||||
pub(crate) fn max_total_size() -> u64 {
|
||||
parse_env_var("TRANSBEAM_MAX_TOTAL_FILE_SIZE", DEFAULT_MAX_TOTAL_SIZE)
|
||||
parse_env_var("TRANSBEAM_MAX_STORAGE_SIZE", DEFAULT_MAX_STORAGE_SIZE)
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
|
|
Loading…
Reference in a new issue