Skip to main content

rs_plugin_common_interfaces/provider/
mod.rs

1// Your plugin must implement:
2// exists(path: RsProviderPath) -> bool;
3// remove(path: RsProviderPath) -> bool;
4// infos(path: RsProviderPath) -> MediaForUpdate;
5// get(path: RsProviderPath) -> RsRequest;
6// add(path: RsProviderAddRequest) -> RsRequest;
7
8use serde::{Deserialize, Serialize};
9use strum_macros::EnumString;
10
11use crate::RsRequest;
12
13#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
14#[serde(rename_all = "camelCase")]
15pub struct RsProviderPath {
16    pub root: Option<String>,
17    pub source: String,
18}
19
20#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
21#[serde(rename_all = "camelCase")]
22pub struct RsProviderAddRequest {
23    pub root: String,
24    pub name: String,
25    pub overwrite: bool,
26}
27
28#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
29#[serde(rename_all = "camelCase")]
30pub struct RsProviderAddResponse {
31    pub request: RsRequest,
32    pub multipart: Option<String>,
33    pub source: Option<String>,
34    pub packets: Option<u64>,
35}
36
37#[derive(
38    Debug, Serialize, Deserialize, Clone, PartialEq, strum_macros::Display, EnumString, Default,
39)]
40#[strum(serialize_all = "camelCase")]
41#[serde(rename_all = "camelCase")]
42pub enum RsProviderEntryType {
43    Directory,
44    File,
45    #[default]
46    Other,
47}
48
49#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
50#[serde(rename_all = "camelCase")]
51pub struct RsProviderEntry {
52    pub source: String,
53    pub kind: RsProviderEntryType,
54    pub size: Option<u64>,
55    pub mimetype: Option<String>,
56
57    pub hash: Option<String>,
58
59    pub added: Option<i64>,
60    pub modified: Option<i64>,
61    pub created: Option<i64>,
62}
63
64impl RsProviderEntry {
65    pub fn mime_or_default(&self) -> String {
66        self.mimetype
67            .clone()
68            .unwrap_or("application/octet-stream".to_string())
69    }
70}