Fix SQLite path: use AppData on Windows, posix paths for Linux/Docker
This commit is contained in:
@@ -2,4 +2,5 @@ SITE_ID=your-unique-site-id
|
|||||||
CLOUD_URL=https://your-vps.com
|
CLOUD_URL=https://your-vps.com
|
||||||
SECRET_KEY=generate-a-long-random-string-here
|
SECRET_KEY=generate-a-long-random-string-here
|
||||||
LICENSE_GRACE_HOURS=24
|
LICENSE_GRACE_HOURS=24
|
||||||
DATABASE_URL=sqlite:///./pos.db
|
# DATABASE_URL is set automatically — only override if you know what you're doing
|
||||||
|
# DATABASE_URL=sqlite:///./pos.db
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
|
||||||
|
_HERE = Path(__file__).parent # always points to local_backend/
|
||||||
|
|
||||||
|
# Use AppData on Windows (avoids Controlled Folder Access blocks),
|
||||||
|
# fall back to local_backend/ on Linux/Mac/Docker
|
||||||
|
if os.name == "nt":
|
||||||
|
_DB_DEFAULT = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local")) / "pos" / "pos.db"
|
||||||
|
_DB_DEFAULT.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
else:
|
||||||
|
_DB_DEFAULT = _HERE / "pos.db"
|
||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
SITE_ID: str = ""
|
SITE_ID: str = ""
|
||||||
CLOUD_URL: str = "https://your-vps.com"
|
CLOUD_URL: str = ""
|
||||||
SECRET_KEY: str = "change-me-generate-a-long-random-string"
|
SECRET_KEY: str = "change-me-generate-a-long-random-string"
|
||||||
LICENSE_GRACE_HOURS: int = 24
|
LICENSE_GRACE_HOURS: int = 24
|
||||||
DATABASE_URL: str = "sqlite:///./pos.db"
|
DATABASE_URL: str = f"sqlite:///{_DB_DEFAULT.as_posix()}"
|
||||||
|
|
||||||
class Config:
|
model_config = {"env_file": str(_HERE / ".env")}
|
||||||
env_file = ".env"
|
|
||||||
|
|
||||||
|
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
|
|||||||
@@ -11,13 +11,14 @@ from pathlib import Path
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
|
|
||||||
from config import settings
|
from config import settings
|
||||||
from middleware.license_check import license_state
|
from middleware.license_check import license_state
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
SYNC_INTERVAL_SECONDS = 6 * 60 * 60 # 6 hours
|
SYNC_INTERVAL_SECONDS = 6 * 60 * 60 # 6 hours
|
||||||
STATE_FILE = Path("license_state.json")
|
STATE_FILE = Path(__file__).parent.parent / "license_state.json"
|
||||||
|
|
||||||
|
|
||||||
def _load_persisted_state():
|
def _load_persisted_state():
|
||||||
|
|||||||
Reference in New Issue
Block a user