This commit is contained in:
parent
a8936c92d3
commit
f28d65810d
|
@ -3,7 +3,7 @@ use aws_config::BehaviorVersion;
|
||||||
use aws_sdk_s3::{config::Credentials, Client as S3Client};
|
use aws_sdk_s3::{config::Credentials, Client as S3Client};
|
||||||
use redis::{aio::MultiplexedConnection, AsyncCommands, Client as RedisClient};
|
use redis::{aio::MultiplexedConnection, AsyncCommands, Client as RedisClient};
|
||||||
use std::env;
|
use std::env;
|
||||||
use log::info;
|
use log::warn;
|
||||||
use crate::s3_utils::get_s3_filelist;
|
use crate::s3_utils::get_s3_filelist;
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl AppState {
|
||||||
|
|
||||||
/// Кэширует список файлов из Storj S3 в Redis.
|
/// Кэширует список файлов из Storj S3 в Redis.
|
||||||
pub async fn cache_filelist(&self) {
|
pub async fn cache_filelist(&self) {
|
||||||
info!("caching storj filelist...");
|
warn!("caching AWS filelist...");
|
||||||
let mut redis = self.redis.clone();
|
let mut redis = self.redis.clone();
|
||||||
|
|
||||||
// Запрашиваем список файлов из Storj S3
|
// Запрашиваем список файлов из Storj S3
|
||||||
|
@ -103,7 +103,7 @@ impl AppState {
|
||||||
.expect(&format!("Failed to cache file {} in Redis", filename));
|
.expect(&format!("Failed to cache file {} in Redis", filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("cached {} files", filelist.len());
|
warn!("cached {} files", filelist.len());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Получает путь из ключа (имени файла) в Redis.
|
/// Получает путь из ключа (имени файла) в Redis.
|
||||||
|
|
|
@ -138,8 +138,27 @@ pub async fn proxy_handler(
|
||||||
}
|
}
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
warn!("cannot find stored path for: {}", filekey);
|
warn!("cannot find stored path for: {}", filekey);
|
||||||
let filepath = format!("unsafe/production/{}", filekey);
|
let ct_parts = content_type.split("/").collect::<Vec<&str>>();
|
||||||
// download from aws to storj
|
let filepath = format!("unsafe/production/{}/{}", ct_parts[0], filekey);
|
||||||
|
|
||||||
|
match check_file_exists(&state.storj_client, &state.bucket, &filepath).await? {
|
||||||
|
true => {
|
||||||
|
warn!("file {} exists in storj", filepath);
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
warn!("file {} does not exist in storj", filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match check_file_exists(&state.aws_client, &state.bucket, &filepath).await? {
|
||||||
|
true => {
|
||||||
|
warn!("file {} exists in aws", filepath);
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
warn!("file {} does not exist in aws", filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await {
|
match load_file_from_s3(&state.aws_client, &state.bucket, &filepath).await {
|
||||||
Ok(filedata) => {
|
Ok(filedata) => {
|
||||||
thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())
|
thumbdata_save(filedata.clone(), &state, &filekey, content_type.to_string())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user