Settings: per-user default for download_disabled

New pref download_disabled_default (stored in user_prefs + mirrored to
_user_settings.json for the render pipeline). When true, apply_sidecar
marks all activities as download_disabled unless the sidecar explicitly
sets download_disabled: false (per-activity opt-in from the edit drawer).

Settings page gets an "Activity defaults" card with the toggle.
This commit is contained in:
Davide Scaini
2026-05-16 20:51:23 +02:00
parent 2d9620c6d1
commit de602ff5d9
4 changed files with 79 additions and 5 deletions
+5 -1
View File
@@ -50,8 +50,12 @@ def apply_sidecar_edit(activity_id: str, payload: dict[str, Any], data_dir: Path
hide = [s for s in (payload.get("hide_stats") or []) if s in STAT_PANELS]
if hide:
lines.append(f"hide_stats: [{', '.join(hide)}]")
if payload.get("download_disabled"):
dd = payload.get("download_disabled")
if dd is True:
lines.append("download_disabled: true")
elif dd is False:
# Explicit false: allows per-activity opt-in against a user-level default
lines.append("download_disabled: false")
description = (payload.get("description") or "").strip()
+15 -4
View File
@@ -69,7 +69,7 @@ def parse_sidecar(path: Path) -> tuple[dict, str]:
return {}, text.strip()
def apply_sidecar(detail: dict, fm: dict, body: str) -> dict:
def apply_sidecar(detail: dict, fm: dict, body: str, *, download_disabled_default: bool = False) -> dict:
"""Apply sidecar overrides to a detail JSON dict. Returns a modified copy."""
from bincio.extract.writer import _infer_indoor_title
d = dict(detail)
@@ -97,8 +97,12 @@ def apply_sidecar(detail: dict, fm: dict, body: str) -> dict:
d["privacy"] = "unlisted" if fm["private"] else detail.get("privacy", "public")
if "hide_stats" in fm:
d["custom"]["hide_stats"] = [str(s) for s in (fm["hide_stats"] or [])]
if "download_disabled" in fm:
dd = fm.get("download_disabled") # True, False, or None (absent)
if dd is True:
d["download_disabled"] = True
elif dd is None and download_disabled_default:
d["download_disabled"] = True
# dd is False → explicit per-activity opt-in, leave unset
return d
@@ -239,6 +243,13 @@ def _merge_all_locked(data_dir: Path) -> int:
merged_dir = data_dir / "_merged"
merged_acts = merged_dir / "activities"
_settings_path = data_dir / "_user_settings.json"
try:
_user_settings = json.loads(_settings_path.read_text(encoding="utf-8")) if _settings_path.exists() else {}
except (OSError, json.JSONDecodeError):
_user_settings = {}
_dl_default: bool = bool(_user_settings.get("download_disabled_default", False))
# Collect sidecars upfront
sidecars: dict[str, tuple[dict, str]] = {}
if edits_dir.exists():
@@ -287,9 +298,9 @@ def _merge_all_locked(data_dir: Path) -> int:
detail = json.loads(src.read_text(encoding="utf-8"))
if activity_id in sidecars:
fm, body = sidecars[activity_id]
detail = apply_sidecar(detail, fm, body)
detail = apply_sidecar(detail, fm, body, download_disabled_default=_dl_default)
else:
detail = apply_sidecar(detail, {}, "")
detail = apply_sidecar(detail, {}, "", download_disabled_default=_dl_default)
if activity_id in image_lists:
detail["custom"] = dict(detail.get("custom") or {})
detail["custom"]["images"] = image_lists[activity_id]
+12
View File
@@ -222,6 +222,18 @@ async def me_set_prefs(
# Coerce all values to strings; ignore unknown keys silently
prefs = {str(k): str(v) for k, v in body.items()}
set_user_prefs(deps._get_db(), user.handle, prefs)
# Mirror download_disabled_default to a file so the render pipeline can read it
if "download_disabled_default" in prefs:
user_dir = deps._get_data_dir() / user.handle
settings_path = user_dir / "_user_settings.json"
try:
current = json.loads(settings_path.read_text(encoding="utf-8")) if settings_path.exists() else {}
except (OSError, json.JSONDecodeError):
current = {}
current["download_disabled_default"] = prefs["download_disabled_default"] == "true"
settings_path.write_text(json.dumps(current, indent=2), encoding="utf-8")
return JSONResponse({"ok": True})