API config settings

This commit is contained in:
blek 2023-10-22 13:44:05 +10:00
parent 3ff8759a97
commit 1353145014
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 85 additions and 1 deletions

View File

@ -52,3 +52,30 @@ instance_motto="A minute file sharing service"
# Instance emoji. # Instance emoji.
# Used as the icon where icon images are not available # Used as the icon where icon images are not available
instance_emoji="🌠" instance_emoji="🌠"
# API settings
[api]
# Whether the API is enabled
enabled=true
# API Keys
# Uncomment to enable
# apikeys=[ "123" ]
# Whether /api/get_all is enabled
get_all=true
# Whether to return only the user IP's files on /api/get_all
get_all_own_only=true
# Whether /api/delete is enabled
delete=false
# Whether /api/delete can delete any file
# (this is ignored unless an API key is provided)
sudo_delete=false
# Whether /api/upload is enabled
# It is not recommended to enable it if API key auth is not enabled
upload=false

View File

@ -75,6 +75,55 @@ impl Default for Branding {
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct APISettings {
/// If API is enabled
#[serde(default)]
pub enabled: bool,
/// Password
#[serde(default)]
pub apikeys: Option<Vec<String>>,
/// Whether /api/get_all is enabled
#[serde(default)]
pub get_all: bool,
/// Whether to return only the
/// user IP's files on /api/get_all
#[serde(default)]
pub get_all_own_only: bool,
/// Whether /api/delete is enabled
#[serde(default)]
pub delete: bool,
/// If /api/delete can delete any file,
/// not only the own file
/// (with API key provided)
#[serde(default)]
pub sudo_delete: bool,
/// Whether /api/upload is enabled
#[serde(default)]
pub upload: bool,
}
impl Default for APISettings {
fn default() -> Self {
APISettings {
enabled: true,
apikeys: None,
get_all: true,
get_all_own_only: true,
delete: false,
sudo_delete: false,
upload: false
}
}
}
impl FilesPolicy { impl FilesPolicy {
pub fn validate(self: &Self) -> Result<(), String> { pub fn validate(self: &Self) -> Result<(), String> {
Ok(()) Ok(())
@ -87,10 +136,17 @@ impl Branding {
} }
} }
impl APISettings {
fn validate(self: &Self) -> Result<(), String> {
Ok(())
}
}
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config { pub struct Config {
pub files: FilesPolicy, pub files: FilesPolicy,
pub brand: Branding pub brand: Branding,
pub api: APISettings
} }
impl Config { impl Config {
@ -98,6 +154,7 @@ impl Config {
pub fn validate(self: &Self) -> Result<(), String> { pub fn validate(self: &Self) -> Result<(), String> {
self.files.validate()?; self.files.validate()?;
self.brand.validate()?; self.brand.validate()?;
self.api .validate()?;
Ok(()) Ok(())
} }