entertainarr_adapter_filesystem/
lib.rs1use std::collections::HashMap;
2use std::sync::Arc;
3
4use anyhow::Context;
5use nutype::nutype;
6
7mod media;
8
9#[nutype(
10 sanitize(trim, lowercase),
11 validate(not_empty, regex = "^[a-z_\\-0-9]+$"),
12 derive(Debug, Eq, Hash, PartialEq, Deserialize)
13)]
14pub struct DiskName(String);
15
16#[derive(Debug, Default, serde::Deserialize)]
17pub struct Config {
18 #[serde(default)]
19 pub disks: HashMap<DiskName, FileSystemConfig>,
20}
21
22impl Config {
23 pub async fn build(self) -> anyhow::Result<Client> {
24 let mut disks = HashMap::with_capacity(self.disks.len());
25 for (name, config) in self.disks {
26 let name = name.into_inner();
27 let value = config
28 .build()
29 .with_context(|| format!("unable to build disk {name:?}"))?;
30 disks.insert(name, value);
31 }
32 Ok(Client(Arc::new(InnerClient { disks })))
33 }
34}
35
36#[derive(Clone, Debug)]
37pub struct Client(Arc<InnerClient>);
38
39#[derive(Debug)]
40struct InnerClient {
41 disks: HashMap<String, FileSystemClient>,
42}
43
44#[derive(Debug, serde::Deserialize)]
45#[serde(tag = "type")]
46pub enum FileSystemConfig {
47 #[serde(rename = "pcloud")]
48 PCloud(entertainarr_adapter_filesystem_pcloud::Config),
49}
50
51impl FileSystemConfig {
52 fn build(self) -> anyhow::Result<FileSystemClient> {
53 match self {
54 Self::PCloud(inner) => inner.build().map(FileSystemClient::PCloud),
55 }
56 }
57}
58
59#[derive(Debug)]
60pub enum FileSystemClient {
61 PCloud(entertainarr_adapter_filesystem_pcloud::PcloudClient),
62}