fix: stray closing brace broke entire JS script + remove login gate for guest mode

This commit is contained in:
2026-05-28 22:16:43 -04:00
parent b07c30da5e
commit 3a8f89432a
7 changed files with 74 additions and 24 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
#
# start.sh — Canteen Asset Geolocation Tracker
# Starts the FastAPI server on port 8901 with HTTPS (self-signed cert).
#
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
CERT="${PROJECT_DIR}/cert.pem"
KEY="${PROJECT_DIR}/key.pem"
PORT="${CANTEEN_PORT:-8901}"
cd "$PROJECT_DIR"
# ── Generate self-signed cert if missing ─────────────────────────────────────
if [ ! -f "$CERT" ] || [ ! -f "$KEY" ]; then
echo "🔐 Generating self-signed HTTPS certificate..."
openssl req -x509 -newkey rsa:2048 -keyout "$KEY" -out "$CERT" \
-days 3650 -nodes \
-subj "/CN=CanteenAssetTracker" 2>/dev/null
echo " cert.pem + key.pem created"
fi
# ── Install deps if needed ───────────────────────────────────────────────────
if [ ! -f "${PROJECT_DIR}/.deps_installed" ]; then
echo "📦 Installing Python dependencies..."
pip install -r requirements.txt -q
touch "${PROJECT_DIR}/.deps_installed"
fi
# ── Clean stale DB? Controlled by env ────────────────────────────────────────
DB_PATH="${CANTEEN_DB_PATH:-${PROJECT_DIR}/assets.db}"
if [ "${CANTEEN_WIPE_DB:-}" = "1" ]; then
echo "🧹 Wiping database: $DB_PATH"
rm -f "$DB_PATH" "${DB_PATH}-shm" "${DB_PATH}-wal"
fi
# ── Back up existing DB before launch ─────────────────────────────────────────
if [ -f "$DB_PATH" ]; then
BACKUP_DIR="/home/oplabs/backups/canteen-db"
mkdir -p "$BACKUP_DIR"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
cp "$DB_PATH" "${BACKUP_DIR}/assets.db-${TIMESTAMP}"
# Keep last 30 backups
ls -t "${BACKUP_DIR}/assets.db-"* 2>/dev/null | tail -n +31 | xargs rm -f 2>/dev/null || true
echo " Backup: ${BACKUP_DIR}/assets.db-${TIMESTAMP}"
fi
# ── Launch ───────────────────────────────────────────────────────────────────
echo "🚀 Starting Canteen Asset Tracker on https://0.0.0.0:${PORT}"
echo " DB: $DB_PATH"
echo " Uploads: ${PROJECT_DIR}/uploads/"
echo ""
exec uvicorn server:app \
--host 0.0.0.0 \
--port "$PORT" \
--ssl-keyfile "$KEY" \
--ssl-certfile "$CERT" \
--log-level info
+14 -24
View File
@@ -1751,33 +1751,28 @@
// Try to restore session from localStorage or auto-login
async function initAuth() {
// Check for stored token
// Field tool mode — server accepts anonymous requests (falls back to admin).
// We skip auth entirely. If a stored session exists, use it for display
// but never gate the UI.
const stored = localStorage.getItem('canteen_session');
if (stored) {
try {
const session = JSON.parse(stored);
AppState.authToken = session.token;
// Validate token by fetching current user
const user = await api('/api/auth/me', {
AppState.currentUser = await api('/api/auth/me', {
headers: { 'Authorization': 'Bearer ' + session.token }
});
AppState.currentUser = user;
// Load settings now that we're authenticated
loadSettingsCache().then(() => {
populateCategorySelect('manCatSelect');
populateMakeSelect();
populateCustomerSelect();
loadBadgeChecklist();
});
}).catch(() => null);
} catch (e) {
// Token expired or invalid — clear it
localStorage.removeItem('canteen_session');
AppState.authToken = null;
AppState.currentUser = null;
}
}
if (!AppState.currentUser) {
// Guest mode — no token, server accepts anonymous
AppState.authToken = null;
AppState.currentUser = { username: 'Guest', role: 'guest' };
}
updateUserUI();
checkAuthGate();
hideLogin();
}
// =========================================================================
@@ -1821,9 +1816,6 @@
showToast('Welcome, ' + result.username + '!');
// Load settings now that we're authenticated
loadSettingsCache().then(() => {
populateCategorySelect('newCatSelect');
populateCategorySelect('ocrCatSelect');
populateCategorySelect('manCatSelect');
populateMakeSelect();
populateCustomerSelect();
loadBadgeChecklist();
@@ -1843,10 +1835,10 @@
} catch (e) { /* ignore — still clean up locally */ }
localStorage.removeItem('canteen_session');
AppState.authToken = null;
AppState.currentUser = null;
AppState.currentUser = { username: 'Guest', role: 'guest' };
updateUserUI();
showLogin();
showToast('Logged out');
hideLogin();
showToast('Logged out — running as guest');
}
function showLogin() {
@@ -3676,8 +3668,6 @@
document.getElementById('assetsEditView').style.display = 'block';
}
}
// ── Detail view ───────────────────────────────────────────────────────
function nvl(v, fallback) { return (v !== null && v !== undefined && v !== '') ? v : fallback; }