Upload 8 files
Browse files- auth.py +36 -0
- databases.py +2 -109
- page_modules/analyze_audiodescriptions.py +0 -4
auth.py
CHANGED
|
@@ -239,6 +239,42 @@ def render_sidebar():
|
|
| 239 |
except Exception:
|
| 240 |
blockchain_published = False
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
# Netejar sessi贸 d'usuari
|
| 243 |
st.session_state.user = None
|
| 244 |
st.session_state.sms_verified = None
|
|
|
|
| 239 |
except Exception:
|
| 240 |
blockchain_published = False
|
| 241 |
|
| 242 |
+
# Registrar desconnexi贸 a events.db
|
| 243 |
+
try:
|
| 244 |
+
current_user = st.session_state.user or {}
|
| 245 |
+
session_id = st.session_state.get("session_id", "")
|
| 246 |
+
ip = st.session_state.get("client_ip", "")
|
| 247 |
+
phone = (
|
| 248 |
+
st.session_state.get("sms_phone_verified")
|
| 249 |
+
or st.session_state.get("sms_phone")
|
| 250 |
+
or ""
|
| 251 |
+
)
|
| 252 |
+
last_password = st.session_state.get("last_password", "")
|
| 253 |
+
log_event(
|
| 254 |
+
session=session_id,
|
| 255 |
+
ip=ip,
|
| 256 |
+
user=current_user.get("username", ""),
|
| 257 |
+
password=last_password,
|
| 258 |
+
phone=phone,
|
| 259 |
+
action="logout",
|
| 260 |
+
sha1sum="",
|
| 261 |
+
visibility="",
|
| 262 |
+
)
|
| 263 |
+
except Exception as e:
|
| 264 |
+
log(f"Error registrant esdeveniment de logout: {e}")
|
| 265 |
+
|
| 266 |
+
# Anotar al log el resultat de la publicaci贸 a Polygon (si aplica)
|
| 267 |
+
digest_hash = digest_info.get("events_digest") if digest_info else None
|
| 268 |
+
events_count = digest_info.get("events_count") if digest_info else None
|
| 269 |
+
log(
|
| 270 |
+
"Logout completat: "
|
| 271 |
+
f"session={session_id or '-'} "
|
| 272 |
+
f"events_digest={'s铆' if digest_hash else 'no'} "
|
| 273 |
+
f"events_count={events_count if events_count is not None else '-'} "
|
| 274 |
+
f"polygon_published={'s铆' if blockchain_published else 'no'} "
|
| 275 |
+
f"polygon_url={polygonscan_url or '-'}"
|
| 276 |
+
)
|
| 277 |
+
|
| 278 |
# Netejar sessi贸 d'usuari
|
| 279 |
st.session_state.user = None
|
| 280 |
st.session_state.sms_verified = None
|
databases.py
CHANGED
|
@@ -356,117 +356,10 @@ def get_audiodescription_history(sha1sum: str, version: str) -> list[sqlite3.Row
|
|
| 356 |
"ORDER BY rowid DESC "
|
| 357 |
"LIMIT 1"
|
| 358 |
)
|
| 359 |
-
print(
|
| 360 |
-
"[DEBUG] get_audiodescription_history",
|
| 361 |
-
f"DB={AUDIODESCRIPTIONS_DB_PATH}",
|
| 362 |
-
f"exists={AUDIODESCRIPTIONS_DB_PATH.exists()}",
|
| 363 |
-
f"sha1sum={sha1sum}",
|
| 364 |
-
f"version={version}",
|
| 365 |
-
)
|
| 366 |
-
# Verificar cu谩ntas filas totales hay en la tabla y qu茅 valores tienen
|
| 367 |
-
try:
|
| 368 |
-
with _connect_audiodescriptions_db() as conn_check:
|
| 369 |
-
total_rows = conn_check.execute("SELECT COUNT(*) FROM audiodescriptions").fetchone()[0]
|
| 370 |
-
print(f"[DEBUG] Total rows in audiodescriptions table: {total_rows}")
|
| 371 |
-
# Mostrar todos los valores 煤nicos de sha1sum y version
|
| 372 |
-
rows_check = conn_check.execute(
|
| 373 |
-
"SELECT sha1sum, version FROM audiodescriptions"
|
| 374 |
-
).fetchall()
|
| 375 |
-
pairs = [(r["sha1sum"], r["version"]) for r in rows_check]
|
| 376 |
-
print(f"[DEBUG] All (sha1sum, version) pairs in DB: {pairs}")
|
| 377 |
-
for sha_pair, ver_pair in pairs:
|
| 378 |
-
count_param = conn_check.execute(
|
| 379 |
-
"SELECT COUNT(*) FROM audiodescriptions WHERE sha1sum=? AND version=?",
|
| 380 |
-
(sha_pair, ver_pair),
|
| 381 |
-
).fetchone()[0]
|
| 382 |
-
count_literal = conn_check.execute(
|
| 383 |
-
f"SELECT COUNT(*) FROM audiodescriptions WHERE sha1sum='{sha_pair}' AND version='{ver_pair}'"
|
| 384 |
-
).fetchone()[0]
|
| 385 |
-
count_nocase = conn_check.execute(
|
| 386 |
-
"SELECT COUNT(*) FROM audiodescriptions WHERE sha1sum=? AND LOWER(version)=LOWER(?)",
|
| 387 |
-
(sha_pair, ver_pair),
|
| 388 |
-
).fetchone()[0]
|
| 389 |
-
print(
|
| 390 |
-
"[DEBUG] Pair counts",
|
| 391 |
-
sha_pair,
|
| 392 |
-
ver_pair,
|
| 393 |
-
f"param={count_param}",
|
| 394 |
-
f"literal={count_literal}",
|
| 395 |
-
f"nocase={count_nocase}",
|
| 396 |
-
)
|
| 397 |
-
except Exception as e:
|
| 398 |
-
print(f"[DEBUG] Error checking total rows: {e}")
|
| 399 |
-
print(f"[DEBUG] get_audiodescription_history SQL: {sql}")
|
| 400 |
-
print(f"[DEBUG] get_audiodescription_history params: {(sha1sum, version)}")
|
| 401 |
|
| 402 |
with _connect_audiodescriptions_db() as conn:
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
test_count = conn.execute(test_sql).fetchone()[0]
|
| 406 |
-
print(f"[DEBUG] Test query (sin params): {test_count} row(s)")
|
| 407 |
-
|
| 408 |
-
# Consulta principal per a sha1sum+versi贸 (nom茅s l'煤ltim registre)
|
| 409 |
-
cur = conn.execute(sql, (sha1sum, version))
|
| 410 |
-
fetched_rows = cur.fetchall()
|
| 411 |
-
print(f"[DEBUG] get_audiodescription_history fetched {len(fetched_rows)} row(s) before slicing")
|
| 412 |
-
for idx, fetched in enumerate(fetched_rows):
|
| 413 |
-
try:
|
| 414 |
-
row_data = {key: fetched[key] for key in fetched.keys()}
|
| 415 |
-
print(f"[DEBUG] Row {idx}: {row_data}")
|
| 416 |
-
except Exception:
|
| 417 |
-
print(f"[DEBUG] Row {idx}: <unprintable> {type(fetched)}")
|
| 418 |
-
|
| 419 |
-
rows = fetched_rows[:1]
|
| 420 |
-
print(f"[DEBUG] get_audiodescription_history returning {len(rows)} row(s)")
|
| 421 |
-
if rows:
|
| 422 |
-
try:
|
| 423 |
-
print(
|
| 424 |
-
"[DEBUG] get_audiodescription_history row keys:",
|
| 425 |
-
list(rows[0].keys()),
|
| 426 |
-
)
|
| 427 |
-
except Exception:
|
| 428 |
-
pass
|
| 429 |
-
|
| 430 |
-
# Diagn貌stic addicional: veure totes les versions disponibles per a aquest sha1sum
|
| 431 |
-
try:
|
| 432 |
-
cur2 = conn.execute(
|
| 433 |
-
"""
|
| 434 |
-
SELECT sha1sum, version,
|
| 435 |
-
LENGTH(une_ad) AS len_une_ad,
|
| 436 |
-
LENGTH(free_ad) AS len_free_ad,
|
| 437 |
-
LENGTH(ok_une_ad) AS len_ok_une_ad,
|
| 438 |
-
LENGTH(ok_free_ad) AS len_ok_free_ad,
|
| 439 |
-
LENGTH(test_une_ad) AS len_test_une_ad,
|
| 440 |
-
LENGTH(test_free_ad) AS len_test_free_ad
|
| 441 |
-
FROM audiodescriptions
|
| 442 |
-
WHERE sha1sum = ?
|
| 443 |
-
ORDER BY version, rowid
|
| 444 |
-
""",
|
| 445 |
-
(sha1sum,),
|
| 446 |
-
)
|
| 447 |
-
diag_rows = cur2.fetchall() or []
|
| 448 |
-
summary = [
|
| 449 |
-
{
|
| 450 |
-
"version": r["version"],
|
| 451 |
-
"len_une_ad": r["len_une_ad"],
|
| 452 |
-
"len_free_ad": r["len_free_ad"],
|
| 453 |
-
"len_ok_une_ad": r["len_ok_une_ad"],
|
| 454 |
-
"len_ok_free_ad": r["len_ok_free_ad"],
|
| 455 |
-
"len_test_une_ad": r["len_test_une_ad"],
|
| 456 |
-
"len_test_free_ad": r["len_test_free_ad"],
|
| 457 |
-
}
|
| 458 |
-
for r in diag_rows
|
| 459 |
-
]
|
| 460 |
-
print(
|
| 461 |
-
"[DEBUG] get_audiodescription_history versions for sha1sum",
|
| 462 |
-
sha1sum,
|
| 463 |
-
"->",
|
| 464 |
-
summary,
|
| 465 |
-
)
|
| 466 |
-
except Exception as e:
|
| 467 |
-
print(f"[DEBUG] get_audiodescription_history diag error: {e}")
|
| 468 |
-
|
| 469 |
-
return rows
|
| 470 |
except sqlite3.OperationalError:
|
| 471 |
return []
|
| 472 |
|
|
|
|
| 356 |
"ORDER BY rowid DESC "
|
| 357 |
"LIMIT 1"
|
| 358 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
with _connect_audiodescriptions_db() as conn:
|
| 361 |
+
row = conn.execute(sql, (sha1sum, version)).fetchone()
|
| 362 |
+
return [row] if row is not None else []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
except sqlite3.OperationalError:
|
| 364 |
return []
|
| 365 |
|
page_modules/analyze_audiodescriptions.py
CHANGED
|
@@ -397,11 +397,7 @@ def render_analyze_audiodescriptions_page(api, permissions: Dict[str, bool]) ->
|
|
| 397 |
text_content = ""
|
| 398 |
if subcarpeta_seleccio:
|
| 399 |
# Llegir des de audiodescriptions.db (totes les versions per sha1+versi贸)
|
| 400 |
-
print(
|
| 401 |
-
f"[DEBUG] UI: demanant historial AD per sha1sum={selected_sha1}, version={subcarpeta_seleccio}"
|
| 402 |
-
)
|
| 403 |
rows = get_audiodescription_history(selected_sha1, subcarpeta_seleccio)
|
| 404 |
-
print(f"[DEBUG] UI: get_audiodescription_history ha retornat {len(rows)} fila(es)")
|
| 405 |
|
| 406 |
selected_row = None
|
| 407 |
if rows:
|
|
|
|
| 397 |
text_content = ""
|
| 398 |
if subcarpeta_seleccio:
|
| 399 |
# Llegir des de audiodescriptions.db (totes les versions per sha1+versi贸)
|
|
|
|
|
|
|
|
|
|
| 400 |
rows = get_audiodescription_history(selected_sha1, subcarpeta_seleccio)
|
|
|
|
| 401 |
|
| 402 |
selected_row = None
|
| 403 |
if rows:
|