1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2025-09-15 18:57:03 +00:00

use the sha2 of the key and add database migrations

This commit is contained in:
Shady Khalifa 2023-04-24 22:53:19 +02:00
parent 37952c1a19
commit ca86b1772f
No known key found for this signature in database
GPG key ID: 52DFAC81BEA54EAA
3 changed files with 47 additions and 5 deletions

View file

@ -3,6 +3,7 @@ pub use data::Data;
use ruma::{
OwnedDeviceId, OwnedEventId, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId,
};
use sha2::Digest;
use crate::api::server_server::FedDest;
@ -14,14 +15,16 @@ use ruma::{
},
DeviceId, RoomVersionId, ServerName, UserId,
};
use std::sync::atomic::{self, AtomicBool};
use std::{
collections::{BTreeMap, HashMap},
fs,
future::Future,
net::{IpAddr, SocketAddr},
path::PathBuf,
sync::{Arc, Mutex, RwLock},
sync::{
atomic::{self, AtomicBool},
Arc, Mutex, RwLock,
},
time::{Duration, Instant},
};
use tokio::sync::{broadcast, watch::Receiver, Mutex as TokioMutex, Semaphore};
@ -339,6 +342,24 @@ 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");
r.push(base64::encode_config(
// Using the hash of the key as the filename
// This is to prevent the total length of the path from exceeding the maximum length
sha2::Sha256::digest(key),
base64::URL_SAFE_NO_PAD,
));
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");