1
use std::sync::Arc;
2

            
3
use crate::AppState;
4
use axum::{
5
    extract::{Path, State},
6
    http::{HeaderMap, StatusCode, header},
7
    response::IntoResponse,
8
};
9

            
10
#[derive(Debug)]
11
pub struct S3File {
12
    pub name: String,
13
    pub link: String,
14
}
15

            
16
pub async fn download_file(
17
    State(_data): State<Arc<AppState>>,
18
    Path(_file_name): Path<String>,
19
) -> Result<impl IntoResponse, StatusCode> {
20
    let bytes = vec![1, 2, 3];
21
    let mut headers = HeaderMap::new();
22
    headers.insert(
23
        header::CONTENT_TYPE,
24
        header::HeaderValue::from_static("application/octet-stream"),
25
    );
26
    headers.insert(
27
        header::CONTENT_DISPOSITION,
28
        header::HeaderValue::from_static("attachment"),
29
    );
30

            
31
    Ok((headers, bytes).into_response())
32
}
33

            
34
1
pub async fn list_s3(State(_data): State<Arc<AppState>>) -> Result<Vec<S3File>, StatusCode> {
35
    /*
36
    let client = &data.s3.clone();
37

            
38
    let list_req = ListObjectsRequest {
39
        bucket: data.conf.s3_bucket.clone(),
40
        prefix: Some("files/".to_string()),
41
        ..Default::default()
42
    };
43

            
44
    client
45
        .list_objects(list_req)
46
        .await
47
        .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
48
        .contents
49
        .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?
50
        .iter()
51
        .map(|obj| -> Result<S3File, StatusCode> {
52
            let name = obj
53
                .key
54
                .as_ref()
55
                .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?
56
                .strip_prefix("files/")
57
                .ok_or(StatusCode::INTERNAL_SERVER_ERROR)?
58
                .to_owned();
59
            let link = format!("/api/files/download/{}", name);
60

            
61
            Ok(S3File { name, link })
62
        })
63
    .collect()
64
     */
65
1
    Ok(vec![])
66
1
}