@@ -4,7 +4,7 @@ use actix_multipart::Field;
44use futures:: StreamExt ;
55use 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 ) ]
1010pub 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}
0 commit comments