Lines
17.65 %
Functions
12.5 %
Branches
100 %
use std::sync::Arc;
use crate::AppState;
use axum::{
extract::{Path, State},
http::{HeaderMap, StatusCode, header},
response::IntoResponse,
};
#[derive(Debug)]
pub struct S3File {
pub name: String,
pub link: String,
}
pub async fn download_file(
State(_data): State<Arc<AppState>>,
Path(_file_name): Path<String>,
) -> Result<impl IntoResponse, StatusCode> {
let bytes = vec![1, 2, 3];
let mut headers = HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
header::HeaderValue::from_static("application/octet-stream"),
);
header::CONTENT_DISPOSITION,
header::HeaderValue::from_static("attachment"),
Ok((headers, bytes).into_response())
pub async fn list_s3(State(_data): State<Arc<AppState>>) -> Result<Vec<S3File>, StatusCode> {
/*
let client = &data.s3.clone();
let list_req = ListObjectsRequest {
bucket: data.conf.s3_bucket.clone(),
prefix: Some("files/".to_string()),
..Default::default()
client
.list_objects(list_req)
.await
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
.contents
.ok_or(StatusCode::INTERNAL_SERVER_ERROR)?
.iter()
.map(|obj| -> Result<S3File, StatusCode> {
let name = obj
.key
.as_ref()
.strip_prefix("files/")
.to_owned();
let link = format!("/api/files/download/{}", name);
Ok(S3File { name, link })
})
.collect()
*/
Ok(vec![])