From 1353145014a7ab96f719ef82e4ec0e678a9c71e8 Mon Sep 17 00:00:00 2001 From: blek Date: Sun, 22 Oct 2023 13:44:05 +1000 Subject: [PATCH] API config settings --- filed/config/filed.toml.example | 27 +++++++++++++++ filed/src/config/types.rs | 59 ++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/filed/config/filed.toml.example b/filed/config/filed.toml.example index d6aeb58..9c73491 100644 --- a/filed/config/filed.toml.example +++ b/filed/config/filed.toml.example @@ -52,3 +52,30 @@ instance_motto="A minute file sharing service" # Instance emoji. # Used as the icon where icon images are not available 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 diff --git a/filed/src/config/types.rs b/filed/src/config/types.rs index a3840b3..dbe8bd4 100644 --- a/filed/src/config/types.rs +++ b/filed/src/config/types.rs @@ -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>, + + /// 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 { pub fn validate(self: &Self) -> Result<(), String> { Ok(()) @@ -87,10 +136,17 @@ impl Branding { } } +impl APISettings { + fn validate(self: &Self) -> Result<(), String> { + Ok(()) + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Config { pub files: FilesPolicy, - pub brand: Branding + pub brand: Branding, + pub api: APISettings } impl Config { @@ -98,6 +154,7 @@ impl Config { pub fn validate(self: &Self) -> Result<(), String> { self.files.validate()?; self.brand.validate()?; + self.api .validate()?; Ok(()) }