diff --git a/Cargo.toml b/Cargo.toml
index aa3e468..4bb310b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "discoursio-quoter"
-version = "0.0.4"
+version = "0.0.5"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
diff --git a/src/app_state.rs b/src/app_state.rs
index c599242..83616aa 100644
--- a/src/app_state.rs
+++ b/src/app_state.rs
@@ -4,7 +4,7 @@ use aws_sdk_s3::{config::Credentials, Client as S3Client};
use redis::{aio::MultiplexedConnection, AsyncCommands, Client as RedisClient};
use std::{env, time::Duration};
use tokio::time::interval;
-
+use std::collections::HashMap;
use crate::s3_utils::check_file_exists;
#[derive(Clone)]
@@ -110,12 +110,13 @@ impl AppState {
for object in objects.iter() {
if let Some(key) = &object.key {
let parts: Vec<&str> = key.split('.').collect();
- if parts.len() > 1 && !parts.last().unwrap().contains('/') {
- let filename = parts[0..parts.len()-1].join(".");
- file_list.entry(filename).or_insert(key.clone());
- } else {
- file_list.entry(key.to_string()).or_insert(key.clone());
+ let filename = parts.first().unwrap_or(&"");
+ let ext = parts.get(1).unwrap_or(&"");
+ if ext.contains('/') {
+ continue;
}
+ let filename_with_extension = format!("{}.{}", filename, ext);
+ file_list.insert(filename_with_extension, key.clone());
}
}
@@ -150,25 +151,25 @@ impl AppState {
}
/// Сохраняет маппинг старого пути из AWS S3 на новый путь в Storj S3.
- async fn save_path_by_filekey(
+ async fn save_path_by_filename_with_extension(
&self,
- filekey: &str,
+ filename_with_extension: &str,
path: &str,
) -> Result<(), actix_web::Error> {
let mut redis = self.redis.clone();
// Храним маппинг в формате Hash: old_path -> new_path
redis
- .hset::<_, &str, &str, ()>(PATH_MAPPING_KEY, filekey, path)
+ .hset::<_, &str, &str, ()>(PATH_MAPPING_KEY, filename_with_extension, path)
.await
.map_err(|_| ErrorInternalServerError("Failed to save path mapping in Redis"))?;
Ok(())
}
/// Получает путь в хранилище из ключа (имени файла) в Redis.
- pub async fn get_path(&self, filekey: &str) -> Result