mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-27 14:14:35 +01:00
Create media::FileMeta to represent a file and meta data
This commit is contained in:
parent
2da48b941d
commit
1c6f211933
4 changed files with 33 additions and 9 deletions
|
@ -4,7 +4,9 @@ use std::{
|
|||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use crate::{utils, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{
|
||||
database::media::FileMeta, pdu::PduBuilder, utils, ConduitResult, Database, Error, Ruma,
|
||||
};
|
||||
use keys::{upload_signatures, upload_signing_keys};
|
||||
use log::warn;
|
||||
|
||||
|
@ -3273,7 +3275,11 @@ pub fn get_content_route(
|
|||
_server_name: String,
|
||||
_media_id: String,
|
||||
) -> ConduitResult<get_content::Response> {
|
||||
if let Some((filename, content_type, file)) = db
|
||||
if let Some(FileMeta {
|
||||
filename,
|
||||
content_type,
|
||||
file,
|
||||
}) = db
|
||||
.media
|
||||
.get(format!("mxc://{}/{}", body.server_name, body.media_id))?
|
||||
{
|
||||
|
@ -3301,7 +3307,9 @@ pub fn get_content_thumbnail_route(
|
|||
_server_name: String,
|
||||
_media_id: String,
|
||||
) -> ConduitResult<get_content_thumbnail::Response> {
|
||||
if let Some((_, content_type, file)) = db.media.get_thumbnail(
|
||||
if let Some(FileMeta {
|
||||
content_type, file, ..
|
||||
}) = db.media.get_thumbnail(
|
||||
format!("mxc://{}/{}", body.server_name, body.media_id),
|
||||
body.width
|
||||
.try_into()
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub(self) mod account_data;
|
||||
pub(self) mod globals;
|
||||
pub(self) mod key_backups;
|
||||
pub(self) mod media;
|
||||
pub(crate) mod media;
|
||||
pub(self) mod rooms;
|
||||
pub(self) mod uiaa;
|
||||
pub(self) mod users;
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
use crate::{utils, Error, Result};
|
||||
use std::mem;
|
||||
|
||||
pub type FileMeta = (Option<String>, String, Vec<u8>);
|
||||
pub struct FileMeta {
|
||||
pub filename: Option<String>,
|
||||
pub content_type: String,
|
||||
pub file: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct Media {
|
||||
pub(super) mediaid_file: sled::Tree, // MediaId = MXC + WidthHeight + Filename + ContentType
|
||||
|
@ -61,7 +65,11 @@ impl Media {
|
|||
})?)
|
||||
};
|
||||
|
||||
Ok(Some((filename, content_type, file.to_vec())))
|
||||
Ok(Some(FileMeta {
|
||||
filename,
|
||||
content_type,
|
||||
file: file.to_vec(),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
@ -107,7 +115,11 @@ impl Media {
|
|||
)
|
||||
};
|
||||
|
||||
Ok(Some((filename, content_type, file.to_vec())))
|
||||
Ok(Some(FileMeta {
|
||||
filename,
|
||||
content_type,
|
||||
file: file.to_vec(),
|
||||
}))
|
||||
} else if let Some(r) = self.mediaid_file.scan_prefix(&original_prefix).next() {
|
||||
// Generate a thumbnail
|
||||
let (key, file) = r?;
|
||||
|
@ -154,7 +166,11 @@ impl Media {
|
|||
|
||||
self.mediaid_file.insert(thumbnail_key, &*thumbnail_bytes)?;
|
||||
|
||||
Ok(Some((filename, content_type, thumbnail_bytes)))
|
||||
Ok(Some(FileMeta {
|
||||
filename,
|
||||
content_type,
|
||||
file: thumbnail_bytes.to_vec(),
|
||||
}))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ pub mod push_rules;
|
|||
mod ruma_wrapper;
|
||||
mod utils;
|
||||
|
||||
pub use database::Database;
|
||||
pub use database::{media::FileMeta, Database};
|
||||
pub use error::{Error, Result};
|
||||
pub use pdu::PduEvent;
|
||||
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
|
||||
|
|
Loading…
Reference in a new issue