mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-20 03:11:14 +00:00
Allow configuring pict-rs' temporary directory
This commit is contained in:
parent
a30044278c
commit
6b2ccbf975
8 changed files with 22 additions and 4 deletions
|
@ -3,6 +3,7 @@ address = "0.0.0.0:8080"
|
|||
read_only = false
|
||||
danger_dummy_mode = false
|
||||
max_file_count = 1
|
||||
temporary_directory = "/tmp"
|
||||
|
||||
[client]
|
||||
timeout = 30
|
||||
|
|
|
@ -32,6 +32,11 @@ api_key = 'API_KEY'
|
|||
# default: 1
|
||||
max_file_count = 1
|
||||
|
||||
## Optional: directory pict-rs will use to create temporary files
|
||||
# environment variable: PICTRS__SERVER__TEMPORARY_DIRECTORY
|
||||
# default: The system's advertised temporary directory ("/tmp" on most linuxes)
|
||||
temporary_directory = "/tmp"
|
||||
|
||||
## Client configuration
|
||||
[client]
|
||||
## Optional: time (in seconds) the client will wait for a response before giving up
|
||||
|
|
|
@ -54,7 +54,7 @@ impl ConfigSource<PathBuf, ()> {
|
|||
}
|
||||
}
|
||||
|
||||
// deserialized Configuration for the pict-rs application
|
||||
// Instantiated configuration for the pict-rs application
|
||||
#[derive(Debug)]
|
||||
pub struct PictRsConfiguration {
|
||||
pub(crate) config: Configuration,
|
||||
|
|
|
@ -52,6 +52,7 @@ impl Args {
|
|||
Command::Run(Run {
|
||||
address,
|
||||
api_key,
|
||||
temporary_directory,
|
||||
client_timeout,
|
||||
upgrade_concurrency,
|
||||
metrics_prometheus_address,
|
||||
|
@ -110,6 +111,7 @@ impl Args {
|
|||
read_only,
|
||||
danger_dummy_mode,
|
||||
max_file_count,
|
||||
temporary_directory,
|
||||
};
|
||||
|
||||
let client = Client {
|
||||
|
@ -515,6 +517,8 @@ struct Server {
|
|||
danger_dummy_mode: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
max_file_count: Option<u32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
temporary_directory: Option<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize)]
|
||||
|
@ -898,6 +902,10 @@ struct Run {
|
|||
#[arg(long)]
|
||||
api_key: Option<String>,
|
||||
|
||||
/// The temporary directory pict-rs should use when processing media
|
||||
#[arg(long)]
|
||||
temporary_directory: Option<PathBuf>,
|
||||
|
||||
/// How long (in seconds) the internel HTTP client should wait for responses
|
||||
///
|
||||
/// This number defaults to 30
|
||||
|
|
|
@ -23,6 +23,7 @@ struct ServerDefaults {
|
|||
read_only: bool,
|
||||
danger_dummy_mode: bool,
|
||||
max_file_count: u32,
|
||||
temporary_directory: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Serialize)]
|
||||
|
@ -184,6 +185,7 @@ impl Default for ServerDefaults {
|
|||
read_only: false,
|
||||
danger_dummy_mode: false,
|
||||
max_file_count: 1,
|
||||
temporary_directory: std::env::temp_dir(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,6 +116,8 @@ pub(crate) struct Server {
|
|||
pub(crate) danger_dummy_mode: bool,
|
||||
|
||||
pub(crate) max_file_count: u32,
|
||||
|
||||
pub(crate) temporary_directory: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
|
||||
|
|
|
@ -2091,7 +2091,7 @@ impl PictRsConfiguration {
|
|||
pub async fn run(self) -> color_eyre::Result<()> {
|
||||
let PictRsConfiguration { config, operation } = self;
|
||||
|
||||
let tmp_dir = TmpDir::init().await?;
|
||||
let tmp_dir = TmpDir::init(&config.server.temporary_directory).await?;
|
||||
|
||||
let client = build_client()?;
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ pub(crate) struct TmpDir {
|
|||
}
|
||||
|
||||
impl TmpDir {
|
||||
pub(crate) async fn init() -> std::io::Result<Arc<Self>> {
|
||||
let path = std::env::temp_dir().join(Uuid::new_v4().to_string());
|
||||
pub(crate) async fn init<P: AsRef<Path>>(path: P) -> std::io::Result<Arc<Self>> {
|
||||
let path = path.as_ref().join(Uuid::new_v4().to_string());
|
||||
tokio::fs::create_dir(&path).await?;
|
||||
Ok(Arc::new(TmpDir { path: Some(path) }))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue