1use std::{borrow::Cow, cmp::Ordering};
2
3use serde::ser::SerializeStruct;
4
5use crate::entry::EntryBase;
6
7pub mod checksum;
8pub mod delete;
9pub mod movefile; pub mod rename;
11pub mod upload;
12
13#[derive(Debug, serde::Deserialize)]
18pub struct FileResponse {
19 pub metadata: File,
21}
22
23#[derive(Clone, Debug)]
30pub enum FileIdentifier<'a> {
31 Path(Cow<'a, str>),
33
34 FileId(u64),
36}
37
38impl<'a> FileIdentifier<'a> {
39 #[inline]
41 pub fn path<P: Into<Cow<'a, str>>>(path: P) -> Self {
42 Self::Path(path.into())
43 }
44
45 #[inline]
47 pub fn file_id(fileid: u64) -> Self {
48 Self::FileId(fileid)
49 }
50}
51
52impl Default for FileIdentifier<'_> {
53 fn default() -> Self {
54 Self::FileId(0)
55 }
56}
57
58impl<'a> From<Cow<'a, str>> for FileIdentifier<'a> {
59 fn from(value: Cow<'a, str>) -> Self {
60 Self::Path(value)
61 }
62}
63
64impl<'a> From<&'a str> for FileIdentifier<'a> {
65 fn from(value: &'a str) -> Self {
66 Self::Path(Cow::Borrowed(value))
67 }
68}
69
70impl<'a> From<&'a String> for FileIdentifier<'a> {
71 fn from(value: &'a String) -> Self {
72 Self::Path(Cow::Borrowed(value))
73 }
74}
75
76impl From<String> for FileIdentifier<'_> {
77 fn from(value: String) -> Self {
78 Self::Path(Cow::Owned(value))
79 }
80}
81
82impl From<u64> for FileIdentifier<'_> {
83 fn from(value: u64) -> Self {
84 Self::FileId(value)
85 }
86}
87
88impl serde::Serialize for FileIdentifier<'_> {
89 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
90 where
91 S: serde::Serializer,
92 {
93 let mut builder = serializer.serialize_struct(stringify!(FileIdentifier), 1)?;
94 match self {
95 Self::FileId(file_id) => {
96 builder.serialize_field("fileid", file_id)?;
97 }
98 Self::Path(path) => {
99 builder.serialize_field("path", path)?;
100 }
101 }
102 builder.end()
103 }
104}
105
106#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
112pub struct File {
113 #[serde(flatten)]
115 pub base: EntryBase,
116
117 #[serde(rename = "fileid")]
119 pub file_id: u64,
120
121 pub size: Option<usize>,
123
124 pub hash: Option<usize>,
126
127 #[serde(rename = "contenttype")]
129 pub content_type: Option<String>,
130}
131
132impl Eq for File {}
133
134impl PartialEq for File {
135 fn eq(&self, other: &Self) -> bool {
136 self.base.id.eq(&other.base.id)
137 }
138}
139
140impl Ord for File {
141 fn cmp(&self, other: &Self) -> Ordering {
142 self.base.name.cmp(&other.base.name)
143 }
144}
145
146impl PartialOrd for File {
147 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
148 Some(self.cmp(other))
149 }
150}