This commit is contained in:
@@ -108,18 +108,20 @@ impl AppState {
|
||||
// Формируем список файлов без дубликатов по имени файла (без расширения)
|
||||
|
||||
for object in objects.iter() {
|
||||
if let Some(storj_objkey) = &object.key {
|
||||
let filekey = storj_objkey.split('.')
|
||||
.chain(std::iter::once("")) // Ensure the chain doesn't break on empty strings
|
||||
.filter(|s| !s.is_empty()) // Filter out any empty strings
|
||||
.map(|s| s.split('/')) // Map to Split iterator
|
||||
.nth(0) // Get the first non-empty split result or default to &""
|
||||
.and_then(|s| s.last()) // Call last() on the resulting iterator if it exists, otherwise None
|
||||
.unwrap_or(&"");
|
||||
|
||||
if let Some(storj_filepath) = &object.key {
|
||||
let filepath = match storj_filepath.ends_with("/webp") {
|
||||
true => &storj_filepath.replace("/webp", ""),
|
||||
false => storj_filepath,
|
||||
};
|
||||
let mut parts = filepath.split('/').collect::<Vec<&str>>(); // Explicit type annotation
|
||||
let filename = parts.pop().unwrap();
|
||||
let mut filename_parts = filename.split('.').collect::<Vec<&str>>();
|
||||
let _ext = filename_parts.pop().unwrap();
|
||||
let filekey = filename_parts.pop().unwrap();
|
||||
|
||||
// Сохраняем список файлов в Redis, используя HSET для каждого файла
|
||||
let _: () = redis
|
||||
.hset(PATH_MAPPING_KEY, filekey, storj_objkey)
|
||||
.hset(PATH_MAPPING_KEY, filekey, storj_filepath)
|
||||
.await
|
||||
.expect("Failed to cache file in Redis");
|
||||
}
|
||||
@@ -164,7 +166,7 @@ impl AppState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Получает путь в хранилище из ключа (имени файла) в Redis.
|
||||
/// Получает путь в Storj из ключа (имени файла) в Redis.
|
||||
pub async fn get_path(&self, file_key: &str) -> Result<Option<String>, actix_web::Error> {
|
||||
let mut redis = self.redis.clone();
|
||||
let new_path: Option<String> = redis
|
||||
|
Reference in New Issue
Block a user