lfoppiano commited on
Commit
ccca727
·
verified ·
1 Parent(s): b01c479

Upload config.py

Browse files
Files changed (1) hide show
  1. config.py +37 -0
config.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic_settings import BaseSettings, SettingsConfigDict
2
+ from pathlib import Path
3
+ import tempfile
4
+
5
+ class Settings(BaseSettings):
6
+ model_config = SettingsConfigDict(env_file='.env.fastapi', env_file_encoding='utf-8', extra='ignore')
7
+
8
+ DATA_DIR: str = "backend/data"
9
+ DB_DIR: str = "backend/db"
10
+ WEBDAV_ENABLED: bool = False
11
+ UPLOAD_DIR: str = "" # Will be set to tempdir if empty
12
+
13
+ @property
14
+ def data_root(self) -> Path:
15
+ return Path(self.DATA_DIR)
16
+
17
+ @property
18
+ def db_dir(self) -> Path:
19
+ return Path(self.DB_DIR)
20
+
21
+ @property
22
+ def webdav_enabled(self) -> bool:
23
+ return self.WEBDAV_ENABLED
24
+
25
+ @property
26
+ def upload_dir(self) -> Path:
27
+ if not self.UPLOAD_DIR:
28
+ # Create a temporary directory like Flask does
29
+ self._temp_upload_dir = tempfile.mkdtemp()
30
+ return Path(self._temp_upload_dir)
31
+ return Path(self.UPLOAD_DIR)
32
+
33
+ def get_settings() -> Settings:
34
+ return Settings()
35
+
36
+ # For backward compatibility
37
+ settings = get_settings()