File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ pub fn build_config(opts: Opts) -> AtomicServerResult<Config> {
271271 let initialize = !std:: path:: Path :: exists ( & store_path) || opts. initialize ;
272272
273273 // Initialize FileStore config
274- let fs_file_store = FileStore :: init_fs_from_config ( & opts) ;
274+ let fs_file_store = FileStore :: init_fs_from_config ( & opts, uploads_path . clone ( ) ) ;
275275 let file_store = FileStore :: init_from_config ( & opts, fs_file_store. clone ( ) ) ;
276276
277277 if opts. https & opts. email . is_none ( ) {
Original file line number Diff line number Diff line change @@ -23,14 +23,16 @@ pub struct S3Config {
2323}
2424
2525#[ derive( Clone , Debug ) ]
26- pub struct FSConfig { }
26+ pub struct FSConfig {
27+ path : PathBuf
28+ }
2729
2830impl FileStore {
2931 const S3_PREFIX : & ' static str = "s3:" ;
3032 const FS_PREFIX : & ' static str = "fs:" ;
3133
32- pub fn init_fs_from_config ( _opts : & Opts ) -> FileStore {
33- FileStore :: FS ( FSConfig { } )
34+ pub fn init_fs_from_config ( _opts : & Opts , path : PathBuf ) -> FileStore {
35+ FileStore :: FS ( FSConfig { path } )
3436 }
3537
3638 pub fn init_from_config ( opts : & Opts , fs_file_store : FileStore ) -> FileStore {
@@ -55,6 +57,17 @@ impl FileStore {
5557 }
5658 }
5759
60+ pub fn get_fs_file_path ( & self , file_id : & str ) -> AtomicServerResult < PathBuf > {
61+ if let FileStore :: FS ( config) = self {
62+ let fs_file_id = file_id. strip_prefix ( Self :: FS_PREFIX ) . unwrap_or ( file_id) ;
63+ let mut file_path = config. path . clone ( ) ;
64+ file_path. push ( fs_file_id. to_string ( ) ) ;
65+ Ok ( file_path)
66+ } else {
67+ Err ( "Wrong FileStore passed to get_fs_file_path" . into ( ) )
68+ }
69+ }
70+
5871 pub fn prefix ( & self ) -> & str {
5972 match self {
6073 Self :: S3 ( _) => Self :: S3_PREFIX ,
Original file line number Diff line number Diff line change @@ -53,9 +53,7 @@ pub fn download_file_handler_partial(
5353 req : & HttpRequest ,
5454 appstate : & AppState ,
5555) -> AtomicServerResult < HttpResponse > {
56- let fs_file_id = file_id. strip_prefix ( "fs:" ) . unwrap_or ( file_id) ;
57- let mut file_path = appstate. config . uploads_path . clone ( ) ;
58- file_path. push ( fs_file_id. to_string ( ) ) ;
56+ let file_path = appstate. config . fs_file_store . get_fs_file_path ( file_id) ?;
5957 let file = NamedFile :: open ( file_path) ?;
6058 Ok ( file. into_response ( req) )
6159}
You can’t perform that action at this time.
0 commit comments