Falko Schindler 1 年之前
父節點
當前提交
60351e9f6c
共有 4 個文件被更改,包括 4 次插入9 次删除
  1. 0 1
      nicegui/globals.py
  2. 0 3
      nicegui/run.py
  3. 0 2
      nicegui/run_with.py
  4. 4 3
      nicegui/storage.py

+ 0 - 1
nicegui/globals.py

@@ -41,7 +41,6 @@ reload: bool
 title: str
 viewport: str
 favicon: Optional[Union[str, Path]]
-storage_path: Path
 dark: Optional[bool]
 language: Language
 binding_refresh_interval: float

+ 0 - 3
nicegui/run.py

@@ -65,7 +65,6 @@ def run(*,
         prod_js: bool = True,
         endpoint_documentation: Literal['none', 'internal', 'page', 'all'] = 'none',
         storage_secret: Optional[str] = None,
-        storage_path: Union[str, Path] = Path('.nicegui'),
         **kwargs: Any,
         ) -> None:
     '''ui.run
@@ -95,7 +94,6 @@ def run(*,
     :param prod_js: whether to use the production version of Vue and Quasar dependencies (default: `True`)
     :param endpoint_documentation: control what endpoints appear in the autogenerated OpenAPI docs (default: 'none', options: 'none', 'internal', 'page', 'all')
     :param storage_secret: secret key for browser-based storage (default: `None`, a value is required to enable ui.storage.individual and ui.storage.browser)
-    :param storage_path: directory for local storage (default: `.nicegui` in the current working directory)
     :param kwargs: additional keyword arguments are passed to `uvicorn.run`    
     '''
     globals.ui_run_has_been_called = True
@@ -109,7 +107,6 @@ def run(*,
     globals.tailwind = tailwind
     globals.prod_js = prod_js
     globals.endpoint_documentation = endpoint_documentation
-    globals.storage_path = Path(storage_path)
 
     for route in globals.app.routes:
         if not isinstance(route, Route):

+ 0 - 2
nicegui/run_with.py

@@ -21,7 +21,6 @@ def run_with(
     tailwind: bool = True,
     prod_js: bool = True,
     storage_secret: Optional[str] = None,
-    storage_path: Union[str, Path] = Path('.nicegui'),
 ) -> None:
     globals.ui_run_has_been_called = True
     globals.title = title
@@ -32,7 +31,6 @@ def run_with(
     globals.binding_refresh_interval = binding_refresh_interval
     globals.tailwind = tailwind
     globals.prod_js = prod_js
-    globals.storage_path = Path(storage_path)
 
     set_storage_secret(storage_secret)
     app.on_event('startup')(lambda: handle_startup(with_welcome_message=False))

+ 4 - 3
nicegui/storage.py

@@ -74,7 +74,8 @@ class RequestTrackingMiddleware(BaseHTTPMiddleware):
 class Storage:
 
     def __init__(self) -> None:
-        self._general = PersistentDict(globals.storage_path / 'storage_general.json')
+        self.storage_path = Path('.nicegui')
+        self._general = PersistentDict(self.storage_path / 'storage_general.json')
         self._users: Dict[str, PersistentDict] = {}
 
     @property
@@ -115,7 +116,7 @@ class Storage:
                 raise RuntimeError('app.storage.user needs a storage_secret passed in ui.run()')
         id = request.session['id']
         if id not in self._users:
-            self._users[id] = PersistentDict(globals.storage_path / f'storage_user_{id}.json')
+            self._users[id] = PersistentDict(self.storage_path / f'storage_user_{id}.json')
         return self._users[id]
 
     @property
@@ -127,5 +128,5 @@ class Storage:
         """Clears all storage."""
         self._general.clear()
         self._users.clear()
-        for filepath in globals.storage_path.glob('storage_*.json'):
+        for filepath in self.storage_path.glob('storage_*.json'):
             filepath.unlink()