mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 00:01:24 +01:00
return Option from media::data::search_file_metadata
This is useful to easily distinguish missing files from corrupted keys. All existing usage sites have been modified so there is no behavior change in this commit.
This commit is contained in:
parent
861016ce0f
commit
f0f81db99b
3 changed files with 23 additions and 16 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use ruma::{api::client::error::ErrorKind, OwnedMxcUri};
|
||||
use ruma::OwnedMxcUri;
|
||||
|
||||
use crate::{
|
||||
database::KeyValueDatabase,
|
||||
|
|
@ -158,21 +158,21 @@ impl service::media::Data for KeyValueDatabase {
|
|||
mxc: OwnedMxcUri,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(FileMeta, MediaFileKey)> {
|
||||
) -> Result<Option<(FileMeta, MediaFileKey)>> {
|
||||
let mut prefix = mxc.as_bytes().to_vec();
|
||||
prefix.push(0xFF);
|
||||
prefix.extend_from_slice(&width.to_be_bytes());
|
||||
prefix.extend_from_slice(&height.to_be_bytes());
|
||||
prefix.push(0xFF);
|
||||
|
||||
let (key, _) =
|
||||
self.mediaid_file.scan_prefix(prefix).next().ok_or(
|
||||
Error::BadRequest(ErrorKind::NotFound, "Media not found"),
|
||||
)?;
|
||||
let Some((key, _)) = self.mediaid_file.scan_prefix(prefix).next()
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
let key = MediaFileKey::new(key);
|
||||
let parts = MediaFileKeyParts::try_from(&key)?;
|
||||
Ok((parts.meta, key))
|
||||
Ok(Some((parts.meta, key)))
|
||||
}
|
||||
|
||||
fn delete_file_metadata(&self, key: MediaFileKey) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue