Files
qbz/scripts/dev-reset-last-view.sh
T
vicrodh 9d6c2f7eba fix: harden session restore/persist to prevent ghost CSS errors
When last_view pointed to a view with incomplete context (e.g.
album without selectedAlbum data), the Svelte CSS extraction
pipeline would corrupt and produce PostCSS "Unknown word" errors
that survived cache cleans and npm ci.

- Add isSessionRestoreSafeView() whitelist for context-free views
- Add getSessionFallbackView() for graceful degradation
- Centralize persist logic in getPersistedSessionViewState()
- Only persist views that have valid context data
- Add purchase-album to restore path
- Add dev:reset-last-view script to reset session.db
- Fix AlbumCreditsModal.svelte event handler typing
2026-03-11 17:02:29 -06:00

44 lines
1.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
GLOBAL_DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/qbz"
LAST_USER_ID_FILE="${GLOBAL_DATA_DIR}/last_user_id"
USER_ID="${1:-}"
if [[ -z "${USER_ID}" ]]; then
if [[ ! -f "${LAST_USER_ID_FILE}" ]]; then
echo "[qbz] No last_user_id marker found at ${LAST_USER_ID_FILE}"
echo "[qbz] Pass a user id explicitly: bash ./scripts/dev-reset-last-view.sh <user_id>"
exit 1
fi
USER_ID="$(tr -d '[:space:]' < "${LAST_USER_ID_FILE}")"
fi
if [[ -z "${USER_ID}" ]]; then
echo "[qbz] Could not determine the user id to reset."
exit 1
fi
DB_PATH="${GLOBAL_DATA_DIR}/users/${USER_ID}/session.db"
if [[ ! -f "${DB_PATH}" ]]; then
echo "[qbz] Session database not found: ${DB_PATH}"
exit 1
fi
echo "[qbz] Resetting persisted last_view for user ${USER_ID}"
echo "[qbz] Database: ${DB_PATH}"
before_state="$(sqlite3 "${DB_PATH}" "SELECT last_view || '|' || COALESCE(view_context_id, '') || '|' || COALESCE(view_context_type, '') FROM player_state WHERE id = 1;")"
echo "[qbz] Before: ${before_state:-<missing>}"
sqlite3 "${DB_PATH}" <<'SQL'
UPDATE player_state
SET last_view = 'home',
view_context_id = NULL,
view_context_type = NULL
WHERE id = 1;
SQL
after_state="$(sqlite3 "${DB_PATH}" "SELECT last_view || '|' || COALESCE(view_context_id, '') || '|' || COALESCE(view_context_type, '') FROM player_state WHERE id = 1;")"
echo "[qbz] After: ${after_state:-<missing>}"