Skip to content

Commit 3254fe8

Browse files
metamejoepio
authored andcommitted
back to nicer interface
1 parent 365814c commit 3254fe8

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

server/src/files.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use actix_multipart::Field;
44
use futures::StreamExt;
55
use opendal::{services::S3, Operator};
66

7-
use crate::{config::Config, errors::AtomicServerResult};
7+
use crate::{appstate::AppState, config::Config, errors::AtomicServerResult};
88

99
#[derive(Clone, Debug, PartialEq)]
1010
pub enum FileStore {
@@ -50,11 +50,11 @@ impl FileStore {
5050
}
5151
}
5252

53-
pub fn get_subject_file_store<'a>(file_store: &'a FileStore, fs_file_store: &'a FileStore, subject: &str) -> &'a FileStore {
53+
pub fn get_subject_file_store<'a>(appstate: &'a AppState, subject: &str) -> &'a FileStore {
5454
if subject.contains(Self::S3_PREFIX) {
55-
file_store
55+
&appstate.file_store
5656
} else {
57-
fs_file_store
57+
&appstate.fs_file_store
5858
}
5959
}
6060

@@ -196,10 +196,8 @@ mod test {
196196
.map_err(|e| format!("Initialization failed: {}", e))
197197
.expect("failed init config");
198198

199-
let appstate = crate::appstate::init(config.clone()).expect("failed init appstate");
200-
201199
let fs_store = FileStore::init_fs_from_config(&config);
202-
if let FileStore::FS(fs_config) = fs_store.clone() {
200+
if let FileStore::FS(fs_config) = &fs_store {
203201
assert!(fs_config.path.to_str().unwrap().contains("uploads"));
204202
} else {
205203
panic!("fs FileStore not initiated");
@@ -211,16 +209,15 @@ mod test {
211209

212210
assert!(fs_store.get_fs_file_path("my-great-file").unwrap().to_str().unwrap().contains("uploads/my-great-file"));
213211
assert!(fs_store.get_fs_file_path("fs:my-great-file").unwrap().to_str().unwrap().contains("uploads/my-great-file"));
214-
//assert_eq!(file_path, fs_store.get_fs_file_path("my-great-file").unwrap());
215-
//assert_eq!(file_path, fs_store.get_fs_file_path("fs:my-great-file").unwrap());
216212

217213
// FileStore::S3 init
218214
opts.s3_bucket = Some("test-bucket".to_string());
219215
opts.s3_path = Some("uploads".to_string());
220216
config.opts = opts;
217+
let appstate = crate::appstate::init(config.clone()).expect("failed init appstate");
221218

222219
let s3_store = FileStore::init_from_config(&config, fs_store.clone());
223-
if let FileStore::S3(s3_config) = s3_store.clone() {
220+
if let FileStore::S3(s3_config) = &s3_store {
224221
assert_eq!(s3_config.bucket, "test-bucket");
225222
assert_eq!(s3_config.path, "uploads");
226223
} else {
@@ -230,8 +227,8 @@ mod test {
230227
assert_eq!("s3:", s3_store.prefix());
231228
assert_eq!("s3%3A", s3_store.encoded());
232229

233-
assert_eq!(&fs_store, FileStore::get_subject_file_store(&s3_store, &fs_store, "my-great-file"));
234-
assert_eq!(&fs_store, FileStore::get_subject_file_store(&s3_store, &fs_store, "fs:my-great-file"));
235-
assert_eq!(&s3_store, FileStore::get_subject_file_store(&s3_store, &fs_store, "s3:my-great-file"));
230+
assert_eq!(&fs_store, FileStore::get_subject_file_store(&appstate, "my-great-file"));
231+
assert_eq!(&fs_store, FileStore::get_subject_file_store(&appstate, "fs:my-great-file"));
232+
assert_eq!(&s3_store, FileStore::get_subject_file_store(&appstate, "s3:my-great-file"));
236233
}
237234
}

server/src/handlers/download.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub async fn handle_download(
3333

3434
let for_agent = get_client_agent(headers, &appstate, subject.clone())?;
3535
tracing::info!("handle_download: {}", subject);
36-
let file_store = FileStore::get_subject_file_store(&appstate.file_store, &appstate.fs_file_store, &subject);
36+
let file_store = FileStore::get_subject_file_store(&appstate, &subject);
3737
let encoded = subject.replace(file_store.prefix(), &file_store.encoded());
3838
let resource = store.get_resource_extended(&encoded, false, &for_agent)?;
3939
let file_id = resource

0 commit comments

Comments
 (0)