Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e0c66ea9e | |||
| 07c311c1cd | |||
| cf00c9f7c5 |
@@ -1 +1 @@
|
|||||||
v1.4.12
|
v1.4.13
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "aniworld-web",
|
"name": "aniworld-web",
|
||||||
"version": "1.4.12",
|
"version": "1.4.13",
|
||||||
"description": "Aniworld Anime Download Manager - Web Frontend",
|
"description": "Aniworld Anime Download Manager - Web Frontend",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -208,8 +208,9 @@ async def setup_auth(req: SetupRequest):
|
|||||||
# Start initialization in background
|
# Start initialization in background
|
||||||
asyncio.create_task(run_initialization())
|
asyncio.create_task(run_initialization())
|
||||||
|
|
||||||
# Return redirect to loading page
|
# Return redirect to loading page with phase=initial
|
||||||
return {"status": "ok", "redirect": "/loading"}
|
# The loading page will show ONLY series_sync step, then redirect to /setup/unresolved
|
||||||
|
return {"status": "ok", "redirect": "/loading?phase=initial"}
|
||||||
# Note: Media scan is skipped during setup as it requires
|
# Note: Media scan is skipped during setup as it requires
|
||||||
# background_loader service which is only available during
|
# background_loader service which is only available during
|
||||||
# application lifespan. It will run on first application startup.
|
# application lifespan. It will run on first application startup.
|
||||||
|
|||||||
@@ -373,4 +373,51 @@ async def complete_unresolved_folders(
|
|||||||
status="success",
|
status="success",
|
||||||
message=f"Marked {count} folders as handled. Unresolved phase completed.",
|
message=f"Marked {count} folders as handled. Unresolved phase completed.",
|
||||||
count=count,
|
count=count,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class NfoScanPhaseResponse(BaseModel):
|
||||||
|
"""Response model for NFO scan phase trigger."""
|
||||||
|
status: str = Field(..., description="Status of the operation")
|
||||||
|
message: str = Field(..., description="Human-readable message")
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/nfo-scan-phase", response_model=NfoScanPhaseResponse)
|
||||||
|
async def trigger_nfo_scan_phase() -> NfoScanPhaseResponse:
|
||||||
|
"""Trigger the NFO scan phase.
|
||||||
|
|
||||||
|
This endpoint is called by the loading page when accessed with ?phase=nfo.
|
||||||
|
It starts the NFO scan in the background and returns immediately.
|
||||||
|
The loading page then connects via WebSocket to receive progress updates.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
NfoScanPhaseResponse with status and message
|
||||||
|
"""
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
from src.server.services.initialization_service import perform_nfo_scan_phase
|
||||||
|
from src.server.services.progress_service import get_progress_service
|
||||||
|
|
||||||
|
progress_service = get_progress_service()
|
||||||
|
|
||||||
|
async def run_nfo_scan():
|
||||||
|
"""Run NFO scan phase with progress updates."""
|
||||||
|
try:
|
||||||
|
await perform_nfo_scan_phase(progress_service)
|
||||||
|
logger.info("NFO scan phase completed via API trigger")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("NFO scan phase failed: %s", e, exc_info=True)
|
||||||
|
if progress_service:
|
||||||
|
await progress_service.fail_progress(
|
||||||
|
progress_id="nfo_scan",
|
||||||
|
error_message=f"NFO scan failed: {str(e)}",
|
||||||
|
metadata={"step_id": "nfo_scan", "phase": "nfo"}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Start NFO scan in background
|
||||||
|
asyncio.create_task(run_nfo_scan())
|
||||||
|
|
||||||
|
return NfoScanPhaseResponse(
|
||||||
|
status="started",
|
||||||
|
message="NFO scan phase started. Check progress via WebSocket."
|
||||||
)
|
)
|
||||||
@@ -132,24 +132,31 @@ class SetupRedirectMiddleware(BaseHTTPMiddleware):
|
|||||||
Either a redirect to /setup or the normal response
|
Either a redirect to /setup or the normal response
|
||||||
"""
|
"""
|
||||||
path = request.url.path
|
path = request.url.path
|
||||||
|
query_params = request.query_params
|
||||||
|
|
||||||
# Check if trying to access setup or loading page after completion
|
# Check if trying to access setup or loading page after completion
|
||||||
if path in ("/setup", "/loading", "/setup/unresolved"):
|
if path in ("/setup", "/loading", "/setup/unresolved"):
|
||||||
if not self._needs_setup():
|
if not self._needs_setup():
|
||||||
if path == "/setup":
|
if path == "/setup":
|
||||||
# Redirect to loading if initialization is in progress
|
# Redirect to login if setup is already complete
|
||||||
# Otherwise redirect to login
|
|
||||||
return RedirectResponse(url="/login", status_code=302)
|
return RedirectResponse(url="/login", status_code=302)
|
||||||
elif path == "/setup/unresolved":
|
elif path == "/setup/unresolved":
|
||||||
# Check if unresolved phase is already completed
|
# Check if unresolved phase is already completed
|
||||||
if self._is_unresolved_completed():
|
if self._is_unresolved_completed():
|
||||||
# Redirect to loading - unresolved phase already done
|
# Redirect to loading - unresolved phase already done
|
||||||
return RedirectResponse(url="/loading", status_code=302)
|
return RedirectResponse(url="/loading?phase=nfo", status_code=302)
|
||||||
elif path == "/loading":
|
elif path == "/loading":
|
||||||
# Always allow access to loading page - it handles its own
|
# Handle phase query parameter
|
||||||
# redirect flow via WebSocket events (initialization_complete
|
phase = query_params.get("phase")
|
||||||
# event triggers redirect to /setup/unresolved)
|
if phase == "initial":
|
||||||
pass
|
# phase=initial should not be accessed after setup is complete
|
||||||
|
# Redirect to login
|
||||||
|
return RedirectResponse(url="/login", status_code=302)
|
||||||
|
elif not phase:
|
||||||
|
# No phase specified and setup is complete
|
||||||
|
# Redirect to login since user should be further in the flow
|
||||||
|
return RedirectResponse(url="/login", status_code=302)
|
||||||
|
# phase=nfo is allowed - it triggers the NFO scan phase
|
||||||
|
|
||||||
# Skip setup check for exempt paths
|
# Skip setup check for exempt paths
|
||||||
if self._is_path_exempt(path):
|
if self._is_path_exempt(path):
|
||||||
|
|||||||
@@ -386,8 +386,8 @@ async def perform_initial_setup(progress_service=None):
|
|||||||
# Load series into memory from database
|
# Load series into memory from database
|
||||||
await _load_series_into_memory(progress_service)
|
await _load_series_into_memory(progress_service)
|
||||||
|
|
||||||
# Run NFO scan as part of initialization
|
# NOTE: NFO scan is NO longer run here - it runs in a separate phase
|
||||||
await perform_nfo_scan_if_needed(progress_service)
|
# after unresolved folders are completed (via /loading?phase=nfo)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -534,6 +534,82 @@ async def perform_nfo_scan_if_needed(progress_service=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def perform_nfo_scan_phase(progress_service=None):
|
||||||
|
"""Perform the NFO scan phase as part of the second loading page phase.
|
||||||
|
|
||||||
|
This is called when the loading page is accessed with ?phase=nfo query param.
|
||||||
|
It runs the NFO scan and emits progress updates via the progress service.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
progress_service: Optional ProgressService for emitting updates
|
||||||
|
"""
|
||||||
|
logger.info("Starting NFO scan phase...")
|
||||||
|
|
||||||
|
if progress_service:
|
||||||
|
from src.server.services.progress_service import ProgressType
|
||||||
|
await progress_service.start_progress(
|
||||||
|
progress_id="nfo_scan",
|
||||||
|
progress_type=ProgressType.SCAN,
|
||||||
|
title="Scanning NFO Files",
|
||||||
|
total=100,
|
||||||
|
message="Starting NFO scan...",
|
||||||
|
metadata={"step_id": "nfo_scan", "phase": "nfo"}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if NFO scan was already completed
|
||||||
|
is_nfo_scan_done = await _check_nfo_scan_status()
|
||||||
|
|
||||||
|
# Check if NFO features are configured
|
||||||
|
if not await _is_nfo_scan_configured():
|
||||||
|
message = (
|
||||||
|
"Skipped - TMDB API key not configured"
|
||||||
|
if not settings.tmdb_api_key
|
||||||
|
else "Skipped - NFO features disabled"
|
||||||
|
)
|
||||||
|
logger.info("NFO scan phase skipped: %s", message)
|
||||||
|
|
||||||
|
if progress_service:
|
||||||
|
await progress_service.complete_progress(
|
||||||
|
progress_id="nfo_scan",
|
||||||
|
message=message,
|
||||||
|
metadata={"step_id": "nfo_scan", "phase": "nfo", "nfo_scan_complete": True}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Skip if already completed
|
||||||
|
if is_nfo_scan_done:
|
||||||
|
logger.info("Skipping NFO scan phase - already completed on previous run")
|
||||||
|
if progress_service:
|
||||||
|
await progress_service.complete_progress(
|
||||||
|
progress_id="nfo_scan",
|
||||||
|
message="Already completed",
|
||||||
|
metadata={"step_id": "nfo_scan", "phase": "nfo", "nfo_scan_complete": True}
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Execute the NFO scan
|
||||||
|
try:
|
||||||
|
await _execute_nfo_scan(progress_service)
|
||||||
|
await _mark_nfo_scan_completed()
|
||||||
|
|
||||||
|
# Send completion event
|
||||||
|
if progress_service:
|
||||||
|
await progress_service.complete_progress(
|
||||||
|
progress_id="nfo_scan",
|
||||||
|
message="NFO scan completed successfully",
|
||||||
|
metadata={"step_id": "nfo_scan", "phase": "nfo", "nfo_scan_complete": True}
|
||||||
|
)
|
||||||
|
logger.info("NFO scan phase completed successfully")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Failed to complete NFO scan phase: %s", e, exc_info=True)
|
||||||
|
if progress_service:
|
||||||
|
await progress_service.fail_progress(
|
||||||
|
progress_id="nfo_scan",
|
||||||
|
error_message=f"NFO scan failed: {str(e)}",
|
||||||
|
metadata={"step_id": "nfo_scan", "phase": "nfo"}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def _check_media_scan_status() -> bool:
|
async def _check_media_scan_status() -> bool:
|
||||||
"""Check if initial media scan has been completed.
|
"""Check if initial media scan has been completed.
|
||||||
|
|
||||||
|
|||||||
@@ -279,6 +279,10 @@
|
|||||||
let ws = null;
|
let ws = null;
|
||||||
const steps = new Map();
|
const steps = new Map();
|
||||||
let isComplete = false;
|
let isComplete = false;
|
||||||
|
|
||||||
|
// Get phase from URL query parameter
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const currentPhase = urlParams.get('phase') || 'initial';
|
||||||
|
|
||||||
const stepOrder = [
|
const stepOrder = [
|
||||||
'series_sync',
|
'series_sync',
|
||||||
@@ -290,6 +294,68 @@
|
|||||||
'nfo_scan': 'Scanning NFO Files'
|
'nfo_scan': 'Scanning NFO Files'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// State management for setup flow
|
||||||
|
const SETUP_STATES = {
|
||||||
|
INITIAL: 'initial',
|
||||||
|
UNRESOLVED: 'unresolved',
|
||||||
|
NFO: 'nfo'
|
||||||
|
};
|
||||||
|
|
||||||
|
function setSetupPhase(phase) {
|
||||||
|
sessionStorage.setItem('setup_phase', phase);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSetupPhase() {
|
||||||
|
return sessionStorage.getItem('setup_phase');
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSetupPhase() {
|
||||||
|
sessionStorage.removeItem('setup_phase');
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStateAndRedirect() {
|
||||||
|
const storedPhase = getSetupPhase();
|
||||||
|
if (storedPhase && storedPhase !== currentPhase) {
|
||||||
|
// State mismatch - redirect to correct page based on stored phase
|
||||||
|
if (storedPhase === SETUP_STATES.INITIAL) {
|
||||||
|
window.location.href = '/loading?phase=initial';
|
||||||
|
return false;
|
||||||
|
} else if (storedPhase === SETUP_STATES.UNRESOLVED) {
|
||||||
|
window.location.href = '/setup/unresolved';
|
||||||
|
return false;
|
||||||
|
} else if (storedPhase === SETUP_STATES.NFO) {
|
||||||
|
window.location.href = '/loading?phase=nfo';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For initial phase, we only show series_sync step
|
||||||
|
// For nfo phase, we only show nfo_scan step
|
||||||
|
function getStepsForPhase(phase) {
|
||||||
|
if (phase === 'nfo') {
|
||||||
|
return ['nfo_scan'];
|
||||||
|
}
|
||||||
|
return ['series_sync'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function triggerNfoScanPhase() {
|
||||||
|
// Call API to trigger NFO scan phase
|
||||||
|
fetch('/api/setup/nfo-scan-phase', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
}).then(res => {
|
||||||
|
if (!res.ok) {
|
||||||
|
console.error('Failed to trigger NFO scan phase');
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('Error triggering NFO scan phase:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||||
const wsUrl = `${protocol}//${window.location.host}/ws/connect`;
|
const wsUrl = `${protocol}//${window.location.host}/ws/connect`;
|
||||||
@@ -300,21 +366,24 @@
|
|||||||
console.log('WebSocket connected');
|
console.log('WebSocket connected');
|
||||||
updateConnectionStatus(true);
|
updateConnectionStatus(true);
|
||||||
|
|
||||||
// Subscribe to system room for progress updates
|
// Subscribe to rooms based on phase
|
||||||
ws.send(JSON.stringify({
|
if (currentPhase === 'nfo') {
|
||||||
action: 'join',
|
// For nfo phase, only subscribe to scan room
|
||||||
data: {
|
ws.send(JSON.stringify({
|
||||||
room: 'system'
|
action: 'join',
|
||||||
}
|
data: {
|
||||||
}));
|
room: 'scan'
|
||||||
|
}
|
||||||
// Subscribe to scan room for NFO scan progress
|
}));
|
||||||
ws.send(JSON.stringify({
|
} else {
|
||||||
action: 'join',
|
// For initial phase (series_sync), subscribe to system room
|
||||||
data: {
|
ws.send(JSON.stringify({
|
||||||
room: 'scan'
|
action: 'join',
|
||||||
}
|
data: {
|
||||||
}));
|
room: 'system'
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = (event) => {
|
ws.onmessage = (event) => {
|
||||||
@@ -359,12 +428,18 @@
|
|||||||
const data = message.data || message;
|
const data = message.data || message;
|
||||||
const { type, status, title, message: msg, percent, current, total, metadata } = data;
|
const { type, status, title, message: msg, percent, current, total, metadata } = data;
|
||||||
|
|
||||||
// Handle NFO scan events
|
// For NFO phase, all events go to handleNfoScanUpdate
|
||||||
if (type === 'nfo_scan_started' || type === 'nfo_scan_progress' || type === 'nfo_scan_completed') {
|
if (currentPhase === 'nfo') {
|
||||||
handleNfoScanUpdate(data);
|
handleNfoScanUpdate(data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For initial phase (series_sync), skip NFO scan events
|
||||||
|
if (type === 'nfo_scan_started' || type === 'nfo_scan_progress' || type === 'nfo_scan_completed') {
|
||||||
|
// Ignore NFO scan events during initial phase
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Determine step ID based on type and metadata
|
// Determine step ID based on type and metadata
|
||||||
let stepId = metadata?.step_id || type;
|
let stepId = metadata?.step_id || type;
|
||||||
|
|
||||||
@@ -375,9 +450,10 @@
|
|||||||
|
|
||||||
updateStep(stepId, status, msg, percent, current, total);
|
updateStep(stepId, status, msg, percent, current, total);
|
||||||
|
|
||||||
// Check for completion
|
// Check for completion of series_sync
|
||||||
if (metadata?.initialization_complete) {
|
if (metadata?.initialization_complete || type === 'series_sync' && status === 'completed') {
|
||||||
showCompletion();
|
// For initial phase, series_sync completion leads to /setup/unresolved
|
||||||
|
handleSeriesSyncComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
@@ -385,6 +461,22 @@
|
|||||||
showError(msg || 'An error occurred during initialization');
|
showError(msg || 'An error occurred during initialization');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSeriesSyncComplete() {
|
||||||
|
isComplete = true;
|
||||||
|
document.getElementById('connectionStatus').style.display = 'none';
|
||||||
|
|
||||||
|
if (ws) {
|
||||||
|
ws.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the initial phase state
|
||||||
|
clearSetupPhase();
|
||||||
|
|
||||||
|
// For initial phase, series_sync completion always leads to /setup/unresolved
|
||||||
|
// The unresolved page will handle checking if there are folders or redirect to nfo phase
|
||||||
|
window.location.href = '/setup/unresolved';
|
||||||
|
}
|
||||||
|
|
||||||
function handleNfoScanUpdate(data) {
|
function handleNfoScanUpdate(data) {
|
||||||
const stepId = 'nfo_scan';
|
const stepId = 'nfo_scan';
|
||||||
@@ -404,7 +496,7 @@
|
|||||||
const progressTextEl = stepEl.querySelector('.progress-text');
|
const progressTextEl = stepEl.querySelector('.progress-text');
|
||||||
|
|
||||||
const nfoData = data.data || data;
|
const nfoData = data.data || data;
|
||||||
const { status, message, current, total, key, folder } = nfoData;
|
const { status, message, current, total, key, folder, metadata } = nfoData;
|
||||||
|
|
||||||
// Update status
|
// Update status
|
||||||
stepEl.className = 'progress-step';
|
stepEl.className = 'progress-step';
|
||||||
@@ -447,13 +539,26 @@
|
|||||||
progressTextEl.textContent = `${Math.round(percent)}%`;
|
progressTextEl.textContent = `${Math.round(percent)}%`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for completion
|
// Check for completion - handle based on phase
|
||||||
if (data.type === 'nfo_scan_completed') {
|
if (data.type === 'nfo_scan_completed' || metadata?.nfo_scan_complete) {
|
||||||
setTimeout(() => {
|
handleNfoPhaseComplete();
|
||||||
checkUnresolvedAndProceed();
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleNfoPhaseComplete() {
|
||||||
|
isComplete = true;
|
||||||
|
document.getElementById('connectionStatus').style.display = 'none';
|
||||||
|
|
||||||
|
if (ws) {
|
||||||
|
ws.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear the NFO phase state
|
||||||
|
clearSetupPhase();
|
||||||
|
|
||||||
|
// For NFO phase, completion always goes to login
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
|
||||||
function createStep(stepId, title) {
|
function createStep(stepId, title) {
|
||||||
const container = document.getElementById('progressContainer');
|
const container = document.getElementById('progressContainer');
|
||||||
@@ -595,6 +700,27 @@
|
|||||||
|
|
||||||
// Start WebSocket connection when page loads
|
// Start WebSocket connection when page loads
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
// Validate state and redirect if there's a mismatch
|
||||||
|
if (!validateStateAndRedirect()) {
|
||||||
|
return; // Redirect in progress
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the correct state for this phase
|
||||||
|
if (currentPhase === 'nfo') {
|
||||||
|
setSetupPhase(SETUP_STATES.NFO);
|
||||||
|
} else {
|
||||||
|
setSetupPhase(SETUP_STATES.INITIAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the correct steps based on phase
|
||||||
|
const stepsForPhase = getStepsForPhase(currentPhase);
|
||||||
|
if (stepsForPhase.length === 1 && stepsForPhase[0] === 'nfo_scan') {
|
||||||
|
// For nfo phase, create the step and trigger the scan immediately
|
||||||
|
createStep('nfo_scan', stepTitles['nfo_scan']);
|
||||||
|
// Trigger NFO scan phase via API
|
||||||
|
triggerNfoScanPhase();
|
||||||
|
}
|
||||||
|
|
||||||
connectWebSocket();
|
connectWebSocket();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -790,37 +790,14 @@
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (response.ok && data.status === 'ok') {
|
if (response.ok && data.status === 'ok') {
|
||||||
// Redirect to loading page if provided, otherwise check for unresolved folders
|
// Always redirect to loading page with initial phase
|
||||||
if (data.redirect) {
|
// The loading page will handle unresolved folder check
|
||||||
showMessage('Setup saved! Initializing your anime library...', 'success');
|
showMessage('Setup saved! Initializing your anime library...', 'success');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.location.href = data.redirect;
|
// Set session storage state before redirecting
|
||||||
}, 500);
|
sessionStorage.setItem('setup_phase', 'initial');
|
||||||
} else {
|
window.location.href = '/loading?phase=initial';
|
||||||
// Check for unresolved folders before redirecting
|
}, 500);
|
||||||
showMessage('Setup completed successfully! Checking for unresolved series...', 'success');
|
|
||||||
setTimeout(async () => {
|
|
||||||
try {
|
|
||||||
const token = localStorage.getItem('auth_token');
|
|
||||||
const res = await fetch('/api/setup/unresolved', {
|
|
||||||
headers: { 'Authorization': `Bearer ${token}` }
|
|
||||||
});
|
|
||||||
if (res.ok) {
|
|
||||||
const unresolved = await res.json();
|
|
||||||
if (unresolved && unresolved.length > 0) {
|
|
||||||
window.location.href = '/setup/unresolved';
|
|
||||||
} else {
|
|
||||||
window.location.href = '/login';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
window.location.href = '/login';
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error checking unresolved folders:', e);
|
|
||||||
window.location.href = '/login';
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
const errorMessage = data.detail || data.message || 'Setup failed';
|
const errorMessage = data.detail || data.message || 'Setup failed';
|
||||||
showMessage(errorMessage, 'error');
|
showMessage(errorMessage, 'error');
|
||||||
|
|||||||
@@ -594,13 +594,13 @@
|
|||||||
? folder.search_suggestions.map(s => `
|
? folder.search_suggestions.map(s => `
|
||||||
<div class="suggestion-item">
|
<div class="suggestion-item">
|
||||||
<i class="fas fa-link"></i>
|
<i class="fas fa-link"></i>
|
||||||
<a href="${s.link}" class="suggestion-link" target="_blank">${s.name || s.title}</a>
|
<a href="#" class="suggestion-link" data-provider-key="${s.provider_key || s.key || ''}" data-folder="${folder.folder_name}">${s.name || s.title}</a>
|
||||||
</div>
|
</div>
|
||||||
`).join('')
|
`).join('')
|
||||||
: '<div class="no-suggestions"><i class="fas fa-info-circle"></i> No suggestions found</div>';
|
: '<div class="no-suggestions"><i class="fas fa-info-circle"></i> No suggestions found</div>';
|
||||||
|
|
||||||
const searchAgainBtn = (folder.search_suggestions && folder.search_suggestions.length === 0)
|
// Always show search row so user can search multiple times
|
||||||
? `<div class="search-again-row">
|
const searchAgainBtn = `<div class="search-again-row">
|
||||||
<input type="text" class="search-again-input"
|
<input type="text" class="search-again-input"
|
||||||
placeholder="Custom search..."
|
placeholder="Custom search..."
|
||||||
value="${folder.title || ''}"
|
value="${folder.title || ''}"
|
||||||
@@ -608,8 +608,7 @@
|
|||||||
<button class="search-again-btn" data-folder="${folder.folder_name}">
|
<button class="search-again-btn" data-folder="${folder.folder_name}">
|
||||||
<i class="fas fa-search"></i> Search Again
|
<i class="fas fa-search"></i> Search Again
|
||||||
</button>
|
</button>
|
||||||
</div>`
|
</div>`;
|
||||||
: '';
|
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="folder-item" data-folder="${folder.folder_name}">
|
<div class="folder-item" data-folder="${folder.folder_name}">
|
||||||
@@ -653,7 +652,11 @@
|
|||||||
listEl.style.display = 'none';
|
listEl.style.display = 'none';
|
||||||
emptyEl.style.display = 'block';
|
emptyEl.style.display = 'block';
|
||||||
document.getElementById('skip-link').style.display = 'block';
|
document.getElementById('skip-link').style.display = 'block';
|
||||||
setTimeout(() => { window.location.href = '/loading'; }, 2000);
|
// No unresolved folders - redirect to NFO scan phase
|
||||||
|
setTimeout(() => {
|
||||||
|
sessionStorage.setItem('setup_phase', 'nfo');
|
||||||
|
window.location.href = '/loading?phase=nfo';
|
||||||
|
}, 2000);
|
||||||
} else {
|
} else {
|
||||||
listEl.style.display = 'flex';
|
listEl.style.display = 'flex';
|
||||||
emptyEl.style.display = 'none';
|
emptyEl.style.display = 'none';
|
||||||
@@ -767,22 +770,79 @@
|
|||||||
suggestionsEl.innerHTML = result.search_suggestions.map(s => `
|
suggestionsEl.innerHTML = result.search_suggestions.map(s => `
|
||||||
<div class="suggestion-item">
|
<div class="suggestion-item">
|
||||||
<i class="fas fa-link"></i>
|
<i class="fas fa-link"></i>
|
||||||
<a href="${s.link}" class="suggestion-link" target="_blank">${s.name || s.title}</a>
|
<a href="#" class="suggestion-link" data-provider-key="${s.provider_key || s.key || ''}" data-folder="${folder}">${s.name || s.title}</a>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
} else {
|
} else {
|
||||||
suggestionsEl.innerHTML = '<div class="no-suggestions"><i class="fas fa-info-circle"></i> No suggestions found</div>';
|
suggestionsEl.innerHTML = '<div class="no-suggestions"><i class="fas fa-info-circle"></i> No suggestions found</div>';
|
||||||
}
|
}
|
||||||
// Remove the search row since we now have suggestions (or none)
|
// Keep search row visible for additional searches
|
||||||
const searchRow = item.querySelector('.search-again-row');
|
btn.classList.remove('searching');
|
||||||
if (searchRow) searchRow.remove();
|
btn.innerHTML = '<i class="fas fa-search"></i> Search Again';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast('Search failed', 'error');
|
showToast('Search failed', 'error');
|
||||||
|
btn.classList.remove('searching');
|
||||||
|
btn.innerHTML = '<i class="fas fa-search"></i> Search Again';
|
||||||
} finally {
|
} finally {
|
||||||
btn.classList.remove('searching');
|
btn.classList.remove('searching');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Suggestion link click - populate input and resolve
|
||||||
|
document.querySelectorAll('.suggestion-link').forEach(link => {
|
||||||
|
link.addEventListener('click', async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const providerKey = e.target.dataset.providerKey;
|
||||||
|
const folder = e.target.dataset.folder;
|
||||||
|
|
||||||
|
if (!providerKey) {
|
||||||
|
showToast('No provider key available for this suggestion', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = document.querySelector(`.folder-input[data-folder="${folder}"]`);
|
||||||
|
const resolveBtn = document.querySelector(`.resolve-btn[data-folder="${folder}"]`);
|
||||||
|
const item = document.querySelector(`.folder-item[data-folder="${folder}"]`);
|
||||||
|
const errEl = document.querySelector(`.folder-error[data-folder="${folder}"]`);
|
||||||
|
|
||||||
|
if (!input || !resolveBtn || !item) return;
|
||||||
|
|
||||||
|
// Populate input and enable button
|
||||||
|
input.value = providerKey;
|
||||||
|
resolveBtn.disabled = false;
|
||||||
|
|
||||||
|
// Trigger resolve
|
||||||
|
item.classList.add('resolving');
|
||||||
|
resolveBtn.disabled = true;
|
||||||
|
resolveBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await resolveFolder(folder, providerKey);
|
||||||
|
|
||||||
|
if (result.status === 'success') {
|
||||||
|
showToast(`Added: ${result.message.replace('Successfully resolved and added series: ', '')}`, 'success');
|
||||||
|
item.classList.add('resolved');
|
||||||
|
setTimeout(() => {
|
||||||
|
item.remove();
|
||||||
|
checkEmptyList();
|
||||||
|
}, 400);
|
||||||
|
} else {
|
||||||
|
errEl.textContent = result.detail || result.message || 'Failed to resolve';
|
||||||
|
errEl.classList.add('visible');
|
||||||
|
resolveBtn.disabled = false;
|
||||||
|
resolveBtn.innerHTML = 'Resolve';
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
errEl.textContent = 'Server error. Please try again.';
|
||||||
|
errEl.classList.add('visible');
|
||||||
|
resolveBtn.disabled = false;
|
||||||
|
resolveBtn.innerHTML = 'Resolve';
|
||||||
|
} finally {
|
||||||
|
item.classList.remove('resolving');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkEmptyList() {
|
function checkEmptyList() {
|
||||||
@@ -796,7 +856,11 @@
|
|||||||
emptyEl.style.display = 'block';
|
emptyEl.style.display = 'block';
|
||||||
skipLink.style.display = 'block';
|
skipLink.style.display = 'block';
|
||||||
showToast('All series configured!', 'success');
|
showToast('All series configured!', 'success');
|
||||||
setTimeout(() => { window.location.href = '/loading'; }, 2000);
|
// All folders resolved - redirect to NFO scan phase
|
||||||
|
setTimeout(() => {
|
||||||
|
sessionStorage.setItem('setup_phase', 'nfo');
|
||||||
|
window.location.href = '/loading?phase=nfo';
|
||||||
|
}, 2000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,7 +885,12 @@
|
|||||||
const result = await completeUnresolved();
|
const result = await completeUnresolved();
|
||||||
if (result.status === 'success') {
|
if (result.status === 'success') {
|
||||||
showToast(result.message, 'success');
|
showToast(result.message, 'success');
|
||||||
setTimeout(() => { window.location.href = '/loading'; }, 1000);
|
// Clear unresolved state and set NFO phase before redirecting
|
||||||
|
clearSetupPhase();
|
||||||
|
setTimeout(() => {
|
||||||
|
sessionStorage.setItem('setup_phase', 'nfo');
|
||||||
|
window.location.href = '/loading?phase=nfo';
|
||||||
|
}, 1000);
|
||||||
} else {
|
} else {
|
||||||
showToast(result.message || 'Failed to complete', 'error');
|
showToast(result.message || 'Failed to complete', 'error');
|
||||||
doneBtn.disabled = false;
|
doneBtn.disabled = false;
|
||||||
@@ -840,8 +909,40 @@
|
|||||||
doneBtn.style.display = 'inline-flex';
|
doneBtn.style.display = 'inline-flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// State management for setup flow
|
||||||
|
function setSetupPhase(phase) {
|
||||||
|
sessionStorage.setItem('setup_phase', phase);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSetupPhase() {
|
||||||
|
sessionStorage.removeItem('setup_phase');
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStateAndRedirect() {
|
||||||
|
const storedPhase = sessionStorage.getItem('setup_phase');
|
||||||
|
// If we have a stored phase that isn't 'unresolved', redirect appropriately
|
||||||
|
if (storedPhase && storedPhase !== 'unresolved') {
|
||||||
|
if (storedPhase === 'initial') {
|
||||||
|
window.location.href = '/loading?phase=initial';
|
||||||
|
return false;
|
||||||
|
} else if (storedPhase === 'nfo') {
|
||||||
|
window.location.href = '/loading?phase=nfo';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Init
|
// Init
|
||||||
(async function init() {
|
(async function init() {
|
||||||
|
// Validate state and redirect if there's a mismatch
|
||||||
|
if (!validateStateAndRedirect()) {
|
||||||
|
return; // Redirect in progress
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the unresolved phase state
|
||||||
|
setSetupPhase('unresolved');
|
||||||
|
|
||||||
const folders = await fetchUnresolved();
|
const folders = await fetchUnresolved();
|
||||||
if (folders !== null) {
|
if (folders !== null) {
|
||||||
renderFolders(folders);
|
renderFolders(folders);
|
||||||
|
|||||||
Reference in New Issue
Block a user