feat: add local fallback for S3 writes
This commit is contained in:
@@ -60,6 +60,8 @@ struct StorageEndpointView {
|
||||
#[derive(Debug, Serialize)]
|
||||
struct StorageEndpointsResponse {
|
||||
active_backend: String,
|
||||
local_object_count: i64,
|
||||
local_stored_bytes: i64,
|
||||
endpoints: Vec<StorageEndpointView>,
|
||||
}
|
||||
|
||||
@@ -109,6 +111,7 @@ async fn list_storage_endpoints(
|
||||
} else {
|
||||
"local"
|
||||
};
|
||||
let (local_object_count, local_stored_bytes) = local_usage(&state).await?;
|
||||
let mut views = Vec::with_capacity(endpoints.len());
|
||||
for endpoint in endpoints {
|
||||
views.push(endpoint_view(&state, endpoint).await?);
|
||||
@@ -118,6 +121,8 @@ async fn list_storage_endpoints(
|
||||
success: true,
|
||||
data: StorageEndpointsResponse {
|
||||
active_backend: active_backend.to_string(),
|
||||
local_object_count,
|
||||
local_stored_bytes,
|
||||
endpoints: views,
|
||||
},
|
||||
}))
|
||||
@@ -536,6 +541,28 @@ async fn endpoint_usage(state: &AppState, endpoint_id: Uuid) -> Result<(i64, i64
|
||||
.map_err(|err| AppError::new(ErrorCode::Internal, "统计存储使用量失败").with_source(err))
|
||||
}
|
||||
|
||||
async fn local_usage(state: &AppState) -> Result<(i64, i64), AppError> {
|
||||
sqlx::query_as::<_, (i64, i64)>(
|
||||
r#"
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM task_files
|
||||
WHERE status = 'completed'
|
||||
AND storage_backend = 'local'
|
||||
AND COALESCE(storage_key, storage_path) IS NOT NULL)
|
||||
+ (SELECT COUNT(*) FROM tasks
|
||||
WHERE zip_storage_backend = 'local'
|
||||
AND zip_storage_key IS NOT NULL) AS object_count,
|
||||
COALESCE((SELECT SUM(compressed_size)::BIGINT FROM task_files
|
||||
WHERE status = 'completed' AND storage_backend = 'local'), 0::BIGINT)
|
||||
+ COALESCE((SELECT SUM(zip_size)::BIGINT FROM tasks
|
||||
WHERE zip_storage_backend = 'local'), 0::BIGINT) AS stored_bytes
|
||||
"#,
|
||||
)
|
||||
.fetch_one(&state.db)
|
||||
.await
|
||||
.map_err(|err| AppError::new(ErrorCode::Internal, "统计本地存储使用量失败").with_source(err))
|
||||
}
|
||||
|
||||
async fn record_test_result(
|
||||
state: &AppState,
|
||||
endpoint_id: Uuid,
|
||||
|
||||
Reference in New Issue
Block a user