use ruma::{OwnedServerName, ServerName, UserId}; use sha2::{digest::Output, Sha256}; use crate::{config::MediaRetentionConfig, Error, Result}; use super::{BlockedMediaInfo, DbFileMeta, MediaType}; pub trait Data: Send + Sync { #[allow(clippy::too_many_arguments)] fn create_file_metadata( &self, sha256_digest: Output, file_size: u64, servername: &ServerName, media_id: &str, filename: Option<&str>, content_type: Option<&str>, user_id: Option<&UserId>, is_blocked_filehash: bool, ) -> Result<()>; fn search_file_metadata(&self, servername: &ServerName, media_id: &str) -> Result; #[allow(clippy::too_many_arguments)] fn create_thumbnail_metadata( &self, sha256_digest: Output, file_size: u64, servername: &ServerName, media_id: &str, width: u32, height: u32, filename: Option<&str>, content_type: Option<&str>, ) -> Result<()>; // Returns the sha256 hash, filename and content_type and whether the media should be accessible via /// unauthenticated endpoints. fn search_thumbnail_metadata( &self, servername: &ServerName, media_id: &str, width: u32, height: u32, ) -> Result; fn purge_and_get_hashes( &self, media: &[(OwnedServerName, String)], force_filehash: bool, ) -> Vec>; fn purge_and_get_hashes_from_user( &self, user_id: &UserId, force_filehash: bool, after: Option, ) -> Vec>; fn purge_and_get_hashes_from_server( &self, server_name: &ServerName, force_filehash: bool, after: Option, ) -> Vec>; fn is_blocked(&self, server_name: &ServerName, media_id: &str) -> Result; fn block( &self, media: &[(OwnedServerName, String)], unix_secs: u64, reason: Option, ) -> Vec; fn block_from_user( &self, user_id: &UserId, now: u64, reason: &str, after: Option, ) -> Vec; fn unblock(&self, media: &[(OwnedServerName, String)]) -> Vec; /// Returns a Vec of: /// - The server the media is from /// - The media id /// - The time it was blocked, in unix seconds /// - The optional reason why it was blocked fn list_blocked(&self) -> Vec>; fn is_blocked_filehash(&self, sha256_digest: &[u8]) -> Result; /// Gets the files that need to be deleted from the media backend in order to meet the `space` /// requirements, as specified in the retention config. Calling this also causes those files' /// metadata to be deleted from the database. fn files_to_delete( &self, sha256_digest: &[u8], retention: &MediaRetentionConfig, media_type: MediaType, new_size: u64, ) -> Result>>; /// Gets the files that need to be deleted from the media backend in order to meet the /// time-based requirements (`created` and `accessed`), as specified in the retention config. /// Calling this also causes those files' metadata to be deleted from the database. fn cleanup_time_retention(&self, retention: &MediaRetentionConfig) -> Vec>; fn update_last_accessed(&self, server_name: &ServerName, media_id: &str) -> Result<()>; fn update_last_accessed_filehash(&self, sha256_digest: &[u8]) -> Result<()>; }