revolt_database/models/files/
ops.rs

1use revolt_result::Result;
2
3use crate::File;
4
5use super::FileUsedFor;
6
7mod mongodb;
8mod reference;
9
10#[async_trait]
11pub trait AbstractAttachments: Sync + Send {
12    /// Insert attachment into database.
13    async fn insert_attachment(&self, attachment: &File) -> Result<()>;
14
15    /// Fetch an attachment by its id.
16    async fn fetch_attachment(&self, tag: &str, file_id: &str) -> Result<File>;
17
18    /// Fetch all deleted attachments.
19    async fn fetch_deleted_attachments(&self) -> Result<Vec<File>>;
20
21    /// Fetch all dangling attachments.
22    async fn fetch_dangling_files(&self) -> Result<Vec<File>>;
23
24    /// Count references to a given hash.
25    async fn count_file_hash_references(&self, hash: &str) -> Result<usize>;
26
27    /// Find an attachment by its details and mark it as used by a given parent.
28    async fn find_and_use_attachment(
29        &self,
30        id: &str,
31        tag: &str,
32        used_for: FileUsedFor,
33        uploader_id: String,
34    ) -> Result<File>;
35
36    /// Mark an attachment as having been reported.
37    async fn mark_attachment_as_reported(&self, id: &str) -> Result<()>;
38
39    /// Mark an attachment as having been deleted.
40    async fn mark_attachment_as_deleted(&self, id: &str) -> Result<()>;
41
42    /// Mark multiple attachments as having been deleted.
43    async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()>;
44
45    /// Delete the attachment entry.
46    async fn delete_attachment(&self, id: &str) -> Result<()>;
47}