@@ -3,10 +3,7 @@ use std::{fmt, path::PathBuf, time::Duration};
33use opendal:: { services:: S3 , Operator } ;
44use tokio:: fs:: File ;
55
6- use crate :: {
7- config:: { Config , Opts } ,
8- errors:: AtomicServerResult ,
9- } ;
6+ use crate :: { appstate:: AppState , config:: Config , errors:: AtomicServerResult } ;
107
118#[ derive( Clone , Debug ) ]
129pub enum FileStore {
@@ -24,18 +21,21 @@ pub struct S3Config {
2421
2522#[ derive( Clone , Debug ) ]
2623pub struct FSConfig {
27- path : PathBuf
24+ path : PathBuf ,
2825}
2926
3027impl FileStore {
3128 const S3_PREFIX : & ' static str = "s3:" ;
3229 const FS_PREFIX : & ' static str = "fs:" ;
3330
34- pub fn init_fs_from_config ( _opts : & Opts , path : PathBuf ) -> FileStore {
35- FileStore :: FS ( FSConfig { path} )
31+ pub fn init_fs_from_config ( config : & Config ) -> FileStore {
32+ FileStore :: FS ( FSConfig {
33+ path : config. uploads_path . clone ( ) ,
34+ } )
3635 }
3736
38- pub fn init_from_config ( opts : & Opts , fs_file_store : FileStore ) -> FileStore {
37+ pub fn init_from_config ( config : & Config , fs_file_store : FileStore ) -> FileStore {
38+ let opts = & config. opts ;
3939 if opts. s3_bucket . is_some ( ) {
4040 let config = S3Config {
4141 bucket : opts. s3_bucket . clone ( ) . unwrap ( ) ,
@@ -49,11 +49,11 @@ impl FileStore {
4949 }
5050 }
5151
52- pub fn get_subject_file_store < ' a > ( config : & ' a Config , subject : & str ) -> & ' a FileStore {
52+ pub fn get_subject_file_store < ' a > ( appstate : & ' a AppState , subject : & str ) -> & ' a FileStore {
5353 if subject. contains ( Self :: S3_PREFIX ) {
54- & config . file_store
54+ & appstate . file_store
5555 } else {
56- & config . fs_file_store
56+ & appstate . fs_file_store
5757 }
5858 }
5959
0 commit comments