# Implementation Plan ## 1. Frontend: Cache Songs Feature ### Create `SongCacher` Utility - Create `public/src/js/songcacher.js` containing the `SongCacher` class. - Implement methods: - `cacheAll()`: Iterates all songs in `assets.songs` and fetches their assets. - `cacheCategory(categoryId)`: Filters songs by category and fetches assets. - `cacheSong(songId)`: Fetches assets for a single song. - Use `loader.ajax` (or `fetch`) to download files (`main.tja`, music file, etc.) so they are cached by the browser/service worker. ### Update Assets & Settings - Modify `public/src/js/assets.js` to include `songcacher.js` in the load list. - Modify `public/src/js/settings.js`: - Add a "Cache Songs" option to the settings menu. - Use a selection interface (e.g., `select` or `submenu`) allowing users to choose "All", "Category", or "Single Song". - Trigger `SongCacher` methods based on selection. ## 2. Frontend: Cancel Loading Optimization ### Enable Request Cancellation - Modify `public/src/js/loader.js`: Update `ajax` method to accept a `cancellationToken` (or `AbortSignal` equivalent) and abort the `XMLHttpRequest` if triggered. - Modify `public/src/js/abstractfile.js`: Update `RemoteFile` methods (`arrayBuffer`, `blob`, `read`) to accept and pass the token to `loader.ajax`. - Modify `public/src/js/soundbuffer.js`: Update `load` method to accept and pass the token. ### Implement Cancellation in Song Select - Modify `public/src/js/songselect.js`: - In `startPreview`, create a new cancellation token. - Store the current token. - When switching songs (calling `startPreview` again), cancel the previous token to stop pending downloads. ## 3. Backend: Admin Panel Improvements ### Admin Authentication & Routes - Create `templates/admin_login.html` for the password-only login. - Modify `app.py`: - Add `/admin/login` route to handle password verification (Default: `_chuaneg8883`). - Set a session variable (e.g., `admin_logged_in`) upon success. - Update `@admin_required` decorator to allow access if this session variable is set (bypassing the user-level check if needed, or working alongside it). ### Admin Features (Stats & Management) - Modify `app.py`: - In `route_api_scores_save`, increment a `play_count` field in the `db.songs` collection for the played song. - Create `templates/admin_stats.html` (or update `admin_songs.html`) to display: - User statistics. - Song statistics (including the new `play_count`). ## 4. Backend: New Category - Modify `tools/categories.json`: Add a new category entry for "Custom Charts" (自制谱面). ## 5. Localization - Modify `public/src/js/strings.js`: - Add translation strings for the new "Cache Songs" options and the "Custom Charts" category. - Ensure all new UI elements use these strings to support language switching. ## 6. Git Operations - Create and checkout new branch `Utra-Ver`. - Commit all changes. - Push to remote repository (User: `AnthonyDuan`, Pass: `_chuaneg8883`).