1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-07-22 17:18:35 +00:00

Merge branch 'shekohex/fix-media-file-name' into 'next'

fix: Media file name too long

Closes #146

See merge request famedly/conduit!467
This commit is contained in:
Shady Khalifa 2025-02-05 02:58:04 +00:00
commit b9c1cd6938
5 changed files with 126 additions and 1 deletions

View file

@ -4,6 +4,7 @@ use ruma::{
serde::Base64, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedEventId, OwnedRoomAliasId,
OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId,
};
use sha2::Digest;
use crate::api::server_server::DestinationResponse;
@ -27,7 +28,7 @@ use std::{
str::FromStr,
sync::{
atomic::{self, AtomicBool},
Arc, RwLock as StdRwLock,
Arc, Mutex, RwLock as StdRwLock,
},
time::{Duration, Instant},
};
@ -474,6 +475,21 @@ impl Service {
}
pub fn get_media_file(&self, key: &[u8]) -> PathBuf {
let mut r = PathBuf::new();
r.push(self.config.database_path.clone());
r.push("media");
// Using the hash of the key as the filename
// This is to prevent the total length of the path from exceeding the maximum length
r.push(general_purpose::URL_SAFE_NO_PAD.encode(sha2::Sha256::digest(key));
r
}
/// This is the old version of `get_media_file` that uses the key as the filename.
///
/// This is deprecated and will be removed in a future release.
/// Please use `get_media_file` instead.
#[deprecated(note = "Use get_media_file instead")]
pub fn get_media_file_old(&self, key: &[u8]) -> PathBuf {
let mut r = PathBuf::new();
r.push(self.config.database_path.clone());
r.push("media");