revolt_database/models/files/
ops.rs

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