Fix setup to login redirect issue

- Fix setup.html to use redirect_url from API response instead of hardcoded '/'
- Add database creation (aniworld.db, cache.db) during setup process
- Setup now properly creates all required files for validation
- After setup completion, users are correctly redirected to /login
- Tested: setup API returns correct redirect_url, database files created, redirect works
This commit is contained in:
2025-10-06 13:32:35 +02:00
parent 6d0c3fdf26
commit 57d49bcf78
7 changed files with 90 additions and 52 deletions

View File

@@ -500,6 +500,57 @@ async def process_setup(request_data: SetupRequest) -> SetupResponse:
}
}
# Create database files if they don't exist
try:
db_path = Path("data/aniworld.db")
cache_db_path = Path("data/cache.db")
# Ensure data directory exists
db_path.parent.mkdir(parents=True, exist_ok=True)
# Create empty database files if they don't exist
if not db_path.exists():
import sqlite3
with sqlite3.connect(str(db_path)) as conn:
cursor = conn.cursor()
# Create a basic table to make the database valid
cursor.execute("""
CREATE TABLE IF NOT EXISTS setup_info (
id INTEGER PRIMARY KEY,
setup_date TEXT,
version TEXT
)
""")
cursor.execute("""
INSERT INTO setup_info (setup_date, version)
VALUES (?, ?)
""", (datetime.utcnow().isoformat(), "1.0.0"))
conn.commit()
logger.info("Created aniworld.db")
if not cache_db_path.exists():
import sqlite3
with sqlite3.connect(str(cache_db_path)) as conn:
cursor = conn.cursor()
# Create a basic cache table
cursor.execute("""
CREATE TABLE IF NOT EXISTS cache (
id INTEGER PRIMARY KEY,
key TEXT UNIQUE,
value TEXT,
created_at TEXT
)
""")
conn.commit()
logger.info("Created cache.db")
except Exception as e:
logger.error(f"Failed to create database files: {e}")
return SetupResponse(
status="error",
message=f"Failed to create database files: {str(e)}"
)
# Mark setup as complete and save configuration
success = setup_service.mark_setup_complete(config_updates)

View File

@@ -513,7 +513,9 @@
if (data.status === 'success') {
showMessage('Setup completed successfully! Redirecting...', 'success');
setTimeout(() => {
window.location.href = '/';
// Use redirect_url from API response, fallback to /login
const redirectUrl = data.redirect_url || '/login';
window.location.href = redirectUrl;
}, 2000);
} else {
showMessage(data.message, 'error');