VeuReu commited on
Commit
758eede
·
1 Parent(s): 334102a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -8,7 +8,7 @@ except ModuleNotFoundError: # Py<3.11
8
  import tomli as tomllib
9
  import streamlit as st
10
 
11
- from database import set_db_path, init_schema
12
  from api_client import APIClient
13
  from utils import ensure_dirs
14
  from auth import initialize_auth_system, render_login_form, render_sidebar, require_login
@@ -25,14 +25,27 @@ os.environ["STREAMLIT_DATA_DIRECTORY"] = "/tmp/.streamlit"
25
  Path("/tmp/.streamlit").mkdir(parents=True, exist_ok=True)
26
  Path("/tmp/data").mkdir(parents=True, exist_ok=True)
27
  source_db = "init_data/veureu.db"
28
- target_db = "/tmp/data/app.db"
29
  if not os.path.exists(target_db) and os.path.exists(source_db):
30
  shutil.copy(source_db, target_db)
31
 
32
- static_videos = Path(__file__).parent / "videos"
33
  runtime_videos = Path("/tmp/data/videos")
34
  if not runtime_videos.exists():
35
- shutil.copytree(static_videos, runtime_videos, dirs_exist_ok=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
 
38
  # --- Config ---
@@ -72,7 +85,7 @@ API_TOKEN = CFG.get("api", {}).get("token") or os.getenv("API_SHARED_TOKEN")
72
 
73
  os.makedirs(DATA_DIR, exist_ok=True)
74
  ensure_dirs(DATA_DIR)
75
- DB_PATH = os.path.join(DATA_DIR, "app.db")
76
  set_db_path(DB_PATH)
77
  init_schema()
78
 
 
8
  import tomli as tomllib
9
  import streamlit as st
10
 
11
+ from databases import set_db_path, init_schema
12
  from api_client import APIClient
13
  from utils import ensure_dirs
14
  from auth import initialize_auth_system, render_login_form, render_sidebar, require_login
 
25
  Path("/tmp/.streamlit").mkdir(parents=True, exist_ok=True)
26
  Path("/tmp/data").mkdir(parents=True, exist_ok=True)
27
  source_db = "init_data/veureu.db"
28
+ target_db = "/tmp/data/login.db"
29
  if not os.path.exists(target_db) and os.path.exists(source_db):
30
  shutil.copy(source_db, target_db)
31
 
32
+ # Vídeos estàtics: prioritzar demo/data/videos, caure a demo/videos si cal
33
  runtime_videos = Path("/tmp/data/videos")
34
  if not runtime_videos.exists():
35
+ base_dir = Path(__file__).parent
36
+ candidates = [
37
+ base_dir / "data" / "videos", # nova ubicació
38
+ base_dir / "videos", # compatibilitat enrere
39
+ ]
40
+
41
+ static_videos = None
42
+ for cand in candidates:
43
+ if cand.exists():
44
+ static_videos = cand
45
+ break
46
+
47
+ if static_videos is not None:
48
+ shutil.copytree(static_videos, runtime_videos, dirs_exist_ok=True)
49
 
50
 
51
  # --- Config ---
 
85
 
86
  os.makedirs(DATA_DIR, exist_ok=True)
87
  ensure_dirs(DATA_DIR)
88
+ DB_PATH = os.path.join(DATA_DIR, "login.db")
89
  set_db_path(DB_PATH)
90
  init_schema()
91