Initial speaking practice site
This commit is contained in:
commit
bcebeaef82
38 files changed
+10698
No files matched your search
@@ -0,0 +1,174 @@
|
||||
# Speaking Lab Admin Page Design
|
||||
|
||||
## Goal
|
||||
|
||||
Move content management out of the study page and into a dedicated local admin page. The first admin page supports only adding and deleting materials, keeping the study page focused on learning.
|
||||
|
||||
## Scope
|
||||
|
||||
In scope:
|
||||
|
||||
- Add a dedicated `admin.html` page.
|
||||
- Add a small admin entry button beside the left material rail title on `index.html`.
|
||||
- Show the admin entry button only when the current local user is an admin.
|
||||
- Remove the bottom `后台管理` dock from the study page.
|
||||
- Support adding materials from the new admin page through the existing `POST /api/videos` endpoint.
|
||||
- Support deleting materials from the new admin page through a new `DELETE /api/videos/{video_id}` endpoint.
|
||||
- Delete local uploaded video and subtitle files when deleting a material.
|
||||
- Keep external video/HLS URLs untouched when deleting a material.
|
||||
|
||||
Out of scope:
|
||||
|
||||
- Editing video title, speaker, description, tags, or URL.
|
||||
- Replacing subtitles after creation.
|
||||
- Real backend authentication or sessions.
|
||||
- User roles stored in SQLite.
|
||||
- Batch delete, undo, recycle bin, or soft delete.
|
||||
- Server deployment.
|
||||
|
||||
## Admin Visibility
|
||||
|
||||
This phase keeps the current local prototype auth rule:
|
||||
|
||||
- A user is an admin when their email contains `admin`.
|
||||
- Login state remains in browser `localStorage`.
|
||||
- The study page shows the admin entry button only for admin users.
|
||||
- The admin page checks the same local login state. If the visitor is not an admin, it shows a simple message telling them to return to the study page and log in with an admin email.
|
||||
|
||||
This is not secure server-side authorization. It is acceptable for the local prototype phase and should be replaced when real multi-user deployment starts.
|
||||
|
||||
## Study Page Changes
|
||||
|
||||
The study page should become learning-focused.
|
||||
|
||||
Changes:
|
||||
|
||||
- Remove the bottom `后台管理` dock from `index.html`.
|
||||
- Keep login/register in the top bar.
|
||||
- In the left material rail header, show:
|
||||
- `素材`
|
||||
- current video count
|
||||
- a small admin button when the current user is admin
|
||||
- Clicking the admin button navigates to `admin.html`.
|
||||
|
||||
The existing study page continues to load videos through `GET /api/videos`, use demo videos as empty-library fallback, and preserve existing study behaviors.
|
||||
|
||||
## Admin Page
|
||||
|
||||
Add `admin.html` and `admin.js`.
|
||||
|
||||
The admin page has:
|
||||
|
||||
- Header with product name and a return-to-study button.
|
||||
- Admin status area showing the current local admin email.
|
||||
- Add material form:
|
||||
- title
|
||||
- speaker
|
||||
- description
|
||||
- comma-separated tags
|
||||
- local video file
|
||||
- video/HLS URL
|
||||
- English `.srt` / `.vtt` subtitle
|
||||
- Chinese `.srt` / `.vtt` subtitle
|
||||
- Material list:
|
||||
- title
|
||||
- speaker
|
||||
- tags
|
||||
- source type
|
||||
- subtitle availability
|
||||
- delete button
|
||||
|
||||
First-version behavior:
|
||||
|
||||
- Add uses existing `POST /api/videos`.
|
||||
- On successful add, the form resets and the list reloads.
|
||||
- Delete asks for confirmation with `确定删除这个素材吗?此操作不可恢复。`
|
||||
- Confirmed delete calls `DELETE /api/videos/{video_id}`.
|
||||
- Successful delete removes the item from the list.
|
||||
|
||||
## Backend Delete Design
|
||||
|
||||
Add `DELETE /api/videos/{video_id}`.
|
||||
|
||||
Behavior:
|
||||
|
||||
- If the video does not exist, return 404 with `视频不存在`.
|
||||
- Before deleting database rows, collect local file paths:
|
||||
- `videos.video_url` if it starts with `/uploads/`
|
||||
- every related `subtitles.file_path` if it starts with `/uploads/`
|
||||
- Delete the video row from SQLite. Existing foreign key cascade deletes related subtitle rows.
|
||||
- After the database delete succeeds, attempt to remove collected local files from disk.
|
||||
- Ignore missing files.
|
||||
- If a file cannot be deleted, keep the database delete successful and return a response that includes a warning list.
|
||||
|
||||
Suggested response:
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"deletedVideoId": 1,
|
||||
"warnings": []
|
||||
}
|
||||
```
|
||||
|
||||
If file deletion has warnings:
|
||||
|
||||
```json
|
||||
{
|
||||
"ok": true,
|
||||
"deletedVideoId": 1,
|
||||
"warnings": ["无法删除文件: uploads/videos/example.mp4"]
|
||||
}
|
||||
```
|
||||
|
||||
## Data And File Safety
|
||||
|
||||
Delete only files under the project `uploads/` directory. Never delete arbitrary paths from database content.
|
||||
|
||||
Implementation rule:
|
||||
|
||||
- Convert `/uploads/...` URLs to filesystem paths under the project upload directory.
|
||||
- Resolve the path.
|
||||
- Delete it only if the resolved path is inside `UPLOADS_DIR`.
|
||||
|
||||
This prevents a bad database value from deleting unrelated local files.
|
||||
|
||||
## Testing
|
||||
|
||||
Manual verification:
|
||||
|
||||
1. Start the app:
|
||||
|
||||
```powershell
|
||||
cd F:\ooo\speaking-practice-local
|
||||
python -m uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000
|
||||
```
|
||||
|
||||
2. Open `http://127.0.0.1:8000`.
|
||||
3. Log in with a normal email. Confirm the material rail does not show the admin button.
|
||||
4. Log out, then log in with an email containing `admin`. Confirm the admin button appears beside `素材`.
|
||||
5. Click the admin button. Confirm `admin.html` opens.
|
||||
6. Add a URL-based material with subtitles from the admin page.
|
||||
7. Return to the study page and confirm the new material appears.
|
||||
8. Return to the admin page and delete the material.
|
||||
9. Return to the study page and confirm the deleted material no longer appears.
|
||||
10. Add a local video-file material with subtitles, then delete it. Confirm uploaded files are removed from `uploads/videos/` and `uploads/subtitles/`.
|
||||
11. Open `http://127.0.0.1:8000/docs` and confirm `DELETE /api/videos/{video_id}` appears.
|
||||
|
||||
Automated or command-line checks:
|
||||
|
||||
```powershell
|
||||
python -m py_compile backend\main.py backend\db.py
|
||||
node --check app.js
|
||||
node --check admin.js
|
||||
```
|
||||
|
||||
## Future Work
|
||||
|
||||
Likely follow-up phases:
|
||||
|
||||
- Edit video metadata.
|
||||
- Replace subtitles.
|
||||
- Add backend-backed accounts and real admin authorization.
|
||||
- Add import/export backup.
|
||||
- Add server deployment flow.
|
||||
@@ -0,0 +1,150 @@
|
||||
# Speaking Lab Content Library Design
|
||||
|
||||
## Goal
|
||||
|
||||
Turn the current Speaking Lab prototype into a local product prototype with a real content library. The first implementation focuses on content management: admins can add a video with metadata, choose either a local video file or a video/HLS URL, upload English and Chinese subtitles at the same time, and see the content persist after refresh.
|
||||
|
||||
## Scope
|
||||
|
||||
In scope:
|
||||
|
||||
- Add backend video library APIs.
|
||||
- Save uploaded video files under `uploads/videos/`.
|
||||
- Save uploaded subtitle files under `uploads/subtitles/`.
|
||||
- Store video metadata and subtitle records in SQLite.
|
||||
- Load the video list from the backend on page startup.
|
||||
- Keep existing playback, subtitle display, search, tag filtering, and transcript-click behavior where possible.
|
||||
|
||||
Out of scope for this phase:
|
||||
|
||||
- Editing or deleting videos from the web UI.
|
||||
- Replacing subtitles after a video has been created.
|
||||
- Real user authentication or permissions.
|
||||
- Learning records, favorites, watch-later, playback progress, or AI speaking feedback.
|
||||
- Server deployment, Docker, domains, HTTPS, or cloud storage.
|
||||
|
||||
## Recommended Approach
|
||||
|
||||
Use the minimal content-library API approach.
|
||||
|
||||
The backend keeps the current FastAPI + SQLite structure. The frontend admin form submits a `FormData` payload to the backend instead of creating temporary browser-only object URLs. The backend decides whether the video source is an uploaded file or an external URL, saves files when present, writes database rows, and returns a normalized video object for the frontend to render.
|
||||
|
||||
## API Design
|
||||
|
||||
Add these endpoints:
|
||||
|
||||
```text
|
||||
GET /api/videos
|
||||
GET /api/videos/{video_id}
|
||||
POST /api/videos
|
||||
```
|
||||
|
||||
`POST /api/videos` accepts multipart form data:
|
||||
|
||||
```text
|
||||
title
|
||||
speaker
|
||||
description
|
||||
tags
|
||||
video_file optional
|
||||
video_url optional
|
||||
subtitle_en optional
|
||||
subtitle_zh optional
|
||||
```
|
||||
|
||||
Validation rules:
|
||||
|
||||
- `title` is required.
|
||||
- At least one of `video_file` or `video_url` is required.
|
||||
- If both `video_file` and `video_url` are present, the uploaded file wins.
|
||||
- Subtitle files are optional.
|
||||
- Uploaded subtitles must use `.srt` or `.vtt`.
|
||||
- Uploaded videos should use common browser-playable video formats such as `.mp4`, `.webm`, `.mov`, or `.m4v`.
|
||||
- Tags are submitted as comma-separated text and returned to the frontend as an array.
|
||||
|
||||
## Data Design
|
||||
|
||||
Reuse the existing `videos` and `subtitles` tables.
|
||||
|
||||
`videos` usage:
|
||||
|
||||
- `title`: required video title.
|
||||
- `speaker`: speaker or source label.
|
||||
- `description`: optional description.
|
||||
- `tags`: JSON string, for example `["technology", "design"]`.
|
||||
- `video_url`: final playable URL. For uploaded files this is a local static URL such as `/uploads/videos/example.mp4`; for external sources this is the original video or HLS URL.
|
||||
- `status`: set to `published` for this phase.
|
||||
|
||||
`subtitles` usage:
|
||||
|
||||
- `video_id`: parent video.
|
||||
- `language_code`: `en` or `zh`.
|
||||
- `language_name`: `English` or `中文`.
|
||||
- `format`: `srt` or `vtt`.
|
||||
- `file_path`: local static URL such as `/uploads/subtitles/example.srt`.
|
||||
- `content`: raw subtitle text.
|
||||
|
||||
The frontend can continue parsing subtitle content into cues with the existing parser.
|
||||
|
||||
## Frontend Behavior
|
||||
|
||||
On page startup, the frontend calls `GET /api/videos` and renders the returned videos in the existing material list. The existing local demo videos remain as an empty-library fallback only; they are not automatically inserted into the database.
|
||||
|
||||
When an admin submits the existing backstage form:
|
||||
|
||||
1. Build `FormData` from title, speaker, description, tags, video file, video URL, English subtitle, and Chinese subtitle.
|
||||
2. Submit it to `POST /api/videos`.
|
||||
3. Disable the submit button and show an adding state while the request is running.
|
||||
4. On success, insert the returned video at the top of the list, clear the form, and select the new video.
|
||||
5. On failure, show the backend error message.
|
||||
|
||||
Existing behavior to preserve:
|
||||
|
||||
- Search by title, speaker, description, and tags.
|
||||
- Tag filtering.
|
||||
- Bilingual subtitle display.
|
||||
- Click transcript line to jump the video.
|
||||
- Current subtitle highlighting during playback.
|
||||
|
||||
## Error Handling
|
||||
|
||||
Backend errors should be clear enough for a non-technical local user:
|
||||
|
||||
- Missing title: `标题不能为空`
|
||||
- Missing video source: `请上传视频文件或填写视频地址`
|
||||
- Unsupported subtitle file: `字幕只支持 .srt 或 .vtt`
|
||||
- Unsupported video file: `视频文件格式不支持`
|
||||
- File save failure: `保存文件失败,请重试`
|
||||
|
||||
The frontend can use a simple alert for this phase. A toast or notification system is out of scope.
|
||||
|
||||
## Testing
|
||||
|
||||
Manual verification:
|
||||
|
||||
1. Start the app:
|
||||
|
||||
```powershell
|
||||
cd F:\ooo\speaking-practice-local
|
||||
python -m uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000
|
||||
```
|
||||
|
||||
2. Open `http://127.0.0.1:8000`.
|
||||
3. Log in with an email containing `admin`.
|
||||
4. Add a video using an external video or HLS URL plus English and Chinese subtitles.
|
||||
5. Refresh the page and confirm the video remains in the list.
|
||||
6. Add a video using a local video file plus subtitles.
|
||||
7. Refresh the page and confirm the local video remains playable.
|
||||
8. Confirm subtitles render and transcript clicks jump playback.
|
||||
9. Open `http://127.0.0.1:8000/docs` and confirm the three video APIs are visible.
|
||||
|
||||
## Future Work
|
||||
|
||||
Likely next phases after this content-library slice:
|
||||
|
||||
- Add edit and delete actions for videos.
|
||||
- Persist real user accounts and admin permissions.
|
||||
- Move favorites, watch-later, and playback progress from `localStorage` to SQLite.
|
||||
- Add import/export or backup for the local content library.
|
||||
- Package a beginner-friendly local startup script.
|
||||
- Later, prepare server deployment once the local product loop is stable.
|
||||
@@ -0,0 +1,227 @@
|
||||
# Speaking Lab Learning Progress v1 Design
|
||||
|
||||
## Goal
|
||||
|
||||
Add a local-first learning progress layer so a learner can leave a video, come back later, and immediately know where to continue and which subtitle lines still need practice.
|
||||
|
||||
## Current Context
|
||||
|
||||
Speaking Lab already has:
|
||||
|
||||
- A study page that loads videos from `/api/videos`.
|
||||
- Subtitle parsing and clickable transcript lines.
|
||||
- Playback controls for previous, replay, next, and loop.
|
||||
- Local login stored in `localStorage` under `speaking-lab-state-v1`.
|
||||
- Per-user favorites and watch-later lists stored locally.
|
||||
- An admin page for adding and deleting materials.
|
||||
|
||||
This feature keeps the same local-first model. It does not add backend users, cloud sync, or production authentication.
|
||||
|
||||
## Scope
|
||||
|
||||
Learning Progress v1 includes:
|
||||
|
||||
- Save the last playback time for each user and video.
|
||||
- Save the last active subtitle line for each user and video.
|
||||
- Add a `继续学习` action when a video has saved progress.
|
||||
- Restore progress when the learner opens a video.
|
||||
- Add per-line practice status controls:
|
||||
- `已练`
|
||||
- `难句`
|
||||
- Show practice status on transcript lines.
|
||||
- Show progress in the left material list, for example `35%`.
|
||||
- Store all progress in browser `localStorage`.
|
||||
|
||||
Learning Progress v1 excludes:
|
||||
|
||||
- Backend progress persistence.
|
||||
- Multi-device sync.
|
||||
- Learning calendars, streaks, charts, or dashboards.
|
||||
- Persistent recording history.
|
||||
- AI pronunciation scoring.
|
||||
- Real authentication or role enforcement.
|
||||
|
||||
## User Experience
|
||||
|
||||
### Continue Learning
|
||||
|
||||
When a logged-in learner opens a video with saved progress:
|
||||
|
||||
- The video restores to the last saved playback time.
|
||||
- The transcript restores the previously active line when possible.
|
||||
- A `继续学习` button appears in the existing video action area.
|
||||
- Clicking `继续学习` jumps to the saved time and plays from there.
|
||||
|
||||
If there is no saved progress for the current video:
|
||||
|
||||
- The `继续学习` button is hidden or disabled.
|
||||
- The existing learning controls behave as they do today.
|
||||
|
||||
### Transcript Line Status
|
||||
|
||||
Each transcript line gets two compact controls:
|
||||
|
||||
- `已练`: marks the line as practiced.
|
||||
- `难句`: marks the line as difficult.
|
||||
|
||||
The two states are independent:
|
||||
|
||||
- A line can be only practiced.
|
||||
- A line can be only difficult.
|
||||
- A line can be both practiced and difficult.
|
||||
- Clicking an active state again removes that state.
|
||||
|
||||
Visual behavior:
|
||||
|
||||
- Practiced lines use a calm success state.
|
||||
- Difficult lines use a warm warning state.
|
||||
- Status controls stay compact and do not push transcript text into awkward wrapping.
|
||||
|
||||
### Material List Progress
|
||||
|
||||
Each video item in the left material list shows a compact progress label:
|
||||
|
||||
- With subtitles: `已练 3/10 · 30%`
|
||||
- Without subtitles but with playback progress: `看到 02:14`
|
||||
- With no progress: no extra progress label, keeping the list quiet.
|
||||
|
||||
Progress percentage is calculated from practiced subtitle lines:
|
||||
|
||||
```text
|
||||
practiced line count / primary subtitle line count
|
||||
```
|
||||
|
||||
If the current primary subtitle language changes, the denominator follows the currently loaded primary cues for that video. If a video has no subtitle cues, v1 falls back to displaying saved playback time only.
|
||||
|
||||
## Data Model
|
||||
|
||||
Progress is stored inside each local user object in `speaking-lab-state-v1`.
|
||||
|
||||
Existing user shape:
|
||||
|
||||
```js
|
||||
{
|
||||
id: "user-...",
|
||||
email: "learner@example.com",
|
||||
password: "...",
|
||||
role: "user",
|
||||
favorites: [],
|
||||
watchLater: []
|
||||
}
|
||||
```
|
||||
|
||||
New user shape:
|
||||
|
||||
```js
|
||||
{
|
||||
id: "user-...",
|
||||
email: "learner@example.com",
|
||||
password: "...",
|
||||
role: "user",
|
||||
favorites: [],
|
||||
watchLater: [],
|
||||
progress: {
|
||||
"video-id": {
|
||||
currentTime: 124.5,
|
||||
activeLineIndex: 6,
|
||||
practicedLineIndexes: [0, 1, 2],
|
||||
difficultLineIndexes: [4, 6],
|
||||
updatedAt: "2026-06-01T12:00:00.000Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Compatibility:
|
||||
|
||||
- Existing users without `progress` get `progress: {}` when loaded or updated.
|
||||
- Existing saved localStorage data must continue to work.
|
||||
- Video IDs are stored as strings because API video IDs are normalized to strings in the frontend.
|
||||
|
||||
## Save Rules
|
||||
|
||||
Playback progress saves:
|
||||
|
||||
- On video `timeupdate`, save `currentTime`.
|
||||
- Throttle saves to avoid writing localStorage too frequently.
|
||||
- Save immediately when selecting a different video.
|
||||
- Save immediately when the page is about to unload.
|
||||
|
||||
Line progress saves:
|
||||
|
||||
- When active transcript line changes, save `activeLineIndex`.
|
||||
- When the user toggles `已练` or `难句`, save the updated arrays immediately.
|
||||
|
||||
Privacy and locality:
|
||||
|
||||
- All progress remains in the browser.
|
||||
- Clearing browser storage clears progress.
|
||||
|
||||
## Error Handling
|
||||
|
||||
If localStorage read fails:
|
||||
|
||||
- Fall back to an empty state, matching existing behavior.
|
||||
|
||||
If localStorage write fails:
|
||||
|
||||
- Keep the UI usable for the current session.
|
||||
- Avoid showing noisy errors for every time update.
|
||||
|
||||
If a saved line index is out of range after subtitles are replaced:
|
||||
|
||||
- Keep saved playback time.
|
||||
- Ignore the invalid line index and use the first available line.
|
||||
|
||||
If a video is deleted:
|
||||
|
||||
- Old progress entries may remain in localStorage.
|
||||
- They are harmless because deleted videos will not render.
|
||||
- Cleanup can be handled later when backend user sync exists.
|
||||
|
||||
## UI Placement
|
||||
|
||||
Study page changes only:
|
||||
|
||||
- Add `继续学习` beside existing `收藏` and `稍后再看`.
|
||||
- Add status controls inside each transcript line.
|
||||
- Add progress text to each material item under speaker/tags.
|
||||
|
||||
Admin page does not change for this feature.
|
||||
|
||||
## Testing
|
||||
|
||||
Manual verification:
|
||||
|
||||
1. Log in as a normal user.
|
||||
2. Open a video with subtitles.
|
||||
3. Jump to a subtitle line and play briefly.
|
||||
4. Mark one line as `已练`.
|
||||
5. Mark another line as `难句`.
|
||||
6. Refresh the page.
|
||||
7. Confirm the same video restores progress.
|
||||
8. Confirm transcript line statuses remain visible.
|
||||
9. Confirm the left material list shows progress.
|
||||
10. Log out and log in as another user.
|
||||
11. Confirm the second user does not inherit the first user's progress.
|
||||
|
||||
Automated checks:
|
||||
|
||||
- Add small Node tests for pure progress helpers:
|
||||
- default progress creation
|
||||
- practiced percentage calculation
|
||||
- line status toggle behavior
|
||||
- progress summary formatting
|
||||
- Keep existing syntax checks:
|
||||
- `node --check app.js`
|
||||
- `node --check admin.js`
|
||||
|
||||
## Future Extensions
|
||||
|
||||
After v1 works locally, good next steps are:
|
||||
|
||||
- Backend progress persistence.
|
||||
- A small `我的学习` page.
|
||||
- Review mode that filters only difficult lines.
|
||||
- Recording history attached to specific subtitle lines.
|
||||
- Export/import local progress before account sync exists.
|
||||
@@ -0,0 +1,101 @@
|
||||
# Speaking Lab DeepSeek Subtitle AI Design
|
||||
|
||||
## Goal
|
||||
|
||||
Add an admin-side AI subtitle workflow that can clean downloaded English subtitle files and generate aligned Chinese translations after a material has been uploaded. The first version uses DeepSeek for text processing and translation, while keeping true audio-based timestamp calibration behind a future ASR provider boundary.
|
||||
|
||||
## User Experience
|
||||
|
||||
The admin page shows an `AI 修复并翻译字幕` action for an existing material that has English subtitles. If DeepSeek is not configured, the action remains visible but reports a clear setup message instead of failing silently.
|
||||
|
||||
The setup path is intentionally simple for a beginner:
|
||||
|
||||
```env
|
||||
DEEPSEEK_API_KEY=your_key_here
|
||||
DEEPSEEK_BASE_URL=https://api.deepseek.com
|
||||
DEEPSEEK_MODEL=deepseek-chat
|
||||
```
|
||||
|
||||
After the local server restarts, the admin can click `测试 AI 连接`. If the connection works, `AI 修复并翻译字幕` becomes usable.
|
||||
|
||||
## First Version Scope
|
||||
|
||||
The first version does these things:
|
||||
|
||||
- Parse uploaded English VTT/SRT into cue objects.
|
||||
- Remove empty cues and exact duplicate cues.
|
||||
- Keep the original English wording when the downloaded subtitle content is already correct.
|
||||
- Ask DeepSeek to translate each cleaned English cue into natural Chinese for English learners.
|
||||
- Save a clean English VTT and a matching Chinese VTT back to the material.
|
||||
- Return a processing report, including cue count before/after, duplicate count, and translation count.
|
||||
|
||||
The first version does not promise automatic audio timestamp correction. It exposes the structure needed for that later, but does not pretend DeepSeek can listen to the uploaded video.
|
||||
|
||||
## Architecture
|
||||
|
||||
Backend additions:
|
||||
|
||||
- `backend/ai_config.py`: reads environment variables and reports whether DeepSeek is configured.
|
||||
- `backend/subtitle_tools.py`: parses, cleans, deduplicates, and builds VTT files.
|
||||
- `backend/deepseek_client.py`: small HTTP client for the DeepSeek-compatible chat API.
|
||||
- `backend/subtitle_ai.py`: orchestrates clean-and-translate processing.
|
||||
- New API endpoints in `backend/main.py`:
|
||||
- `GET /api/ai/status`
|
||||
- `POST /api/ai/test`
|
||||
- `POST /api/videos/{video_id}/ai/subtitles`
|
||||
|
||||
Frontend additions:
|
||||
|
||||
- Admin page AI panel near the subtitle editor.
|
||||
- Buttons for `测试 AI 连接` and `AI 修复并翻译字幕`.
|
||||
- Status and result messages shown in plain Chinese.
|
||||
|
||||
## Data Flow
|
||||
|
||||
1. Admin uploads video and English subtitles as usual.
|
||||
2. Admin clicks `AI 修复并翻译字幕`.
|
||||
3. Backend loads the material and English subtitle content from SQLite.
|
||||
4. `subtitle_tools` parses and cleans cues locally.
|
||||
5. `deepseek_client` sends the cleaned cue list to DeepSeek for Chinese translation.
|
||||
6. `subtitle_ai` validates that translation count matches English cue count.
|
||||
7. Backend updates the existing English subtitle and upserts the Chinese subtitle.
|
||||
8. Admin page refreshes the material list and shows a report.
|
||||
|
||||
## Error Handling
|
||||
|
||||
If API config is missing, return a friendly `400` with the missing setup information.
|
||||
|
||||
If DeepSeek returns invalid JSON or the wrong number of translations, return a readable error and leave the existing material unchanged.
|
||||
|
||||
If the material has no English subtitle, return a readable error saying English subtitles are required first.
|
||||
|
||||
If the API call times out, return a readable retry message and leave existing subtitles unchanged.
|
||||
|
||||
## Future ASR Calibration
|
||||
|
||||
True timestamp calibration needs an ASR provider that can process audio and return sentence or word timestamps. The first version prepares the interface boundary but leaves `ASR_PROVIDER` disabled.
|
||||
|
||||
Later flow:
|
||||
|
||||
```text
|
||||
video -> extract audio -> ASR timestamps -> align cleaned English text -> DeepSeek translate -> save EN/ZH VTT
|
||||
```
|
||||
|
||||
DeepSeek remains the translation and text cleanup provider. ASR can be added as a separate provider without changing the admin workflow.
|
||||
|
||||
## Testing
|
||||
|
||||
Unit tests cover:
|
||||
|
||||
- Empty cue removal.
|
||||
- Exact duplicate cue removal.
|
||||
- VTT rebuild output.
|
||||
- Missing DeepSeek config status.
|
||||
- Translation count validation.
|
||||
|
||||
Integration-style tests cover:
|
||||
|
||||
- AI endpoint rejects missing API key clearly.
|
||||
- AI endpoint rejects materials without English subtitles.
|
||||
- AI endpoint updates English and Chinese subtitles when given a fake DeepSeek client.
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
# Speaking Lab Focused Learning UI Design
|
||||
|
||||
## Goal
|
||||
|
||||
Refine Speaking Lab's interface so it feels more like a focused English learning product instead of a generic admin-style dashboard.
|
||||
|
||||
The selected direction is a clean, focused learning workspace with small icon-led status cards.
|
||||
|
||||
## Visual Direction
|
||||
|
||||
Use a restrained learning-app style:
|
||||
|
||||
- calm background
|
||||
- white panels
|
||||
- compact cards
|
||||
- clear learning status
|
||||
- small icons beside dashboard metrics
|
||||
- strong but limited teal accent
|
||||
- softer supporting colors for learned, unstudied, favorites, and difficult items
|
||||
|
||||
Avoid:
|
||||
|
||||
- heavy marketing hero styling
|
||||
- decorative blobs
|
||||
- large gradients
|
||||
- overly colorful one-off cards
|
||||
- changing the app structure or data model
|
||||
|
||||
## Scope
|
||||
|
||||
This UI pass includes:
|
||||
|
||||
- Home dashboard metric cards with small icons.
|
||||
- More learning-oriented dashboard card layout:
|
||||
- icon on the left
|
||||
- label and hint in the middle
|
||||
- count on the right
|
||||
- Home material cards with slightly clearer hierarchy.
|
||||
- Study page visual polish:
|
||||
- video panel feels like a focused practice surface
|
||||
- subtitle area feels more like a training prompt
|
||||
- transcript lines have clearer current, practiced, and difficult states
|
||||
- toolbar buttons feel less generic
|
||||
|
||||
This UI pass excludes:
|
||||
|
||||
- README edits.
|
||||
- Backend changes.
|
||||
- New API endpoints.
|
||||
- New user data fields.
|
||||
- Real icon libraries.
|
||||
- Custom thumbnail upload.
|
||||
- Major layout restructuring.
|
||||
|
||||
## Home Page Details
|
||||
|
||||
Dashboard metric cards should use text icons implemented in HTML/CSS:
|
||||
|
||||
- current materials: `::`
|
||||
- studied: check mark
|
||||
- unstudied: clock-like circle
|
||||
- favorites: heart
|
||||
- difficult materials: marker symbol
|
||||
|
||||
Icons should be small and familiar, with soft tinted backgrounds.
|
||||
|
||||
Metric cards should remain clickable filters.
|
||||
|
||||
The active metric card should still be visually obvious, but it should not feel like a dark admin button. Use a restrained accent state.
|
||||
|
||||
## Study Page Details
|
||||
|
||||
The study page should better communicate that the learner is practicing English:
|
||||
|
||||
- Use a slightly softer page background.
|
||||
- Keep the video as the main focus.
|
||||
- Make the subtitle card look like a prompt area:
|
||||
- primary English line larger and clearer
|
||||
- Chinese line quieter
|
||||
- enough padding for comfortable reading
|
||||
- Make the tool row more compact and training-like.
|
||||
- Make transcript rows cleaner:
|
||||
- active row has a visible left accent
|
||||
- practiced row has a soft green treatment
|
||||
- difficult row has a soft amber treatment
|
||||
- status buttons remain easy to scan
|
||||
|
||||
No behavior changes are required.
|
||||
|
||||
## Testing
|
||||
|
||||
Automated checks:
|
||||
|
||||
```powershell
|
||||
node --check home.js
|
||||
node --check app.js
|
||||
node --check admin.js
|
||||
python -m py_compile backend\main.py backend\db.py
|
||||
node tests\progress-helpers.test.mjs
|
||||
node tests\admin-file-input.test.mjs
|
||||
```
|
||||
|
||||
Browser checks:
|
||||
|
||||
1. Open `http://127.0.0.1:8000/`.
|
||||
2. Confirm dashboard metric cards show small icons.
|
||||
3. Confirm metric cards still filter materials.
|
||||
4. Confirm home cards still open `study.html?video=<id>`.
|
||||
5. Open `http://127.0.0.1:8000/study.html`.
|
||||
6. Confirm video area, subtitle prompt, toolbar, and transcript look more like a learning workspace.
|
||||
7. Confirm no text overlaps on the current browser width.
|
||||
|
||||
## Future Extensions
|
||||
|
||||
Later UI improvements can include:
|
||||
|
||||
- replacing text icons with a real icon library
|
||||
- custom cover images
|
||||
- a dedicated difficult-sentence review page
|
||||
- daily learning streaks
|
||||
@@ -0,0 +1,235 @@
|
||||
# Speaking Lab Home Dashboard v1 Design
|
||||
|
||||
## Goal
|
||||
|
||||
Upgrade the existing home page from a simple material grid into a learning dashboard that feels useful as a shareable product prototype.
|
||||
|
||||
The dashboard should help a learner answer three questions quickly:
|
||||
|
||||
- What can I study?
|
||||
- What have I already studied?
|
||||
- Which saved or difficult materials should I return to?
|
||||
|
||||
## Current Context
|
||||
|
||||
Speaking Lab currently has:
|
||||
|
||||
- `index.html`: home page with search, tag chips, material cards, and admin link.
|
||||
- `home.js`: loads `/api/videos`, renders generated covers, and reads local user progress.
|
||||
- `study.html` and `app.js`: learning workspace with subtitles, progress, favorites, watch-later, and difficult-line tracking.
|
||||
- `admin.html` and `admin.js`: local admin page for adding, editing, replacing, and deleting materials.
|
||||
- Local user state in `localStorage` under `speaking-lab-state-v1`.
|
||||
- Material metadata from FastAPI and SQLite through `GET /api/videos`.
|
||||
|
||||
No README changes are part of this upgrade.
|
||||
|
||||
## Scope
|
||||
|
||||
Home Dashboard v1 includes:
|
||||
|
||||
- Add a left overview panel on the home page.
|
||||
- Show dashboard metrics:
|
||||
- total materials
|
||||
- studied materials
|
||||
- unstudied materials
|
||||
- favorite materials
|
||||
- materials with difficult lines
|
||||
- Add status filters:
|
||||
- all
|
||||
- studied
|
||||
- unstudied
|
||||
- favorites
|
||||
- difficult
|
||||
- Keep existing search and tag/category filters.
|
||||
- Combine status, search, and tag filters.
|
||||
- Upgrade material cards with:
|
||||
- favorite toggle
|
||||
- sentence count
|
||||
- practiced percentage
|
||||
- difficult-line count
|
||||
- subtitle language summary
|
||||
- latest progress hint
|
||||
- Keep card click behavior opening `study.html?video=<id>`.
|
||||
- Keep admin link visible only to local admin users.
|
||||
|
||||
Home Dashboard v1 excludes:
|
||||
|
||||
- README updates.
|
||||
- Real backend accounts.
|
||||
- Server-side learning progress.
|
||||
- Uploading custom thumbnails.
|
||||
- Extracting thumbnails from video files.
|
||||
- Backend search or filter endpoints.
|
||||
- Calendar/check-in features.
|
||||
- Separate pages for favorites or difficult sentences.
|
||||
|
||||
## Layout
|
||||
|
||||
The home page becomes a two-column dashboard on desktop:
|
||||
|
||||
- Left column:
|
||||
- product name and compact learning overview
|
||||
- metric buttons for total, studied, unstudied, favorites, and difficult
|
||||
- Right column:
|
||||
- heading and primary material grid
|
||||
- search and category controls
|
||||
- status text
|
||||
- material cards
|
||||
|
||||
On smaller screens, the overview panel stacks above the grid.
|
||||
|
||||
The design should stay practical and work-focused. It should look like a learning tool, not a marketing landing page.
|
||||
|
||||
## Filters
|
||||
|
||||
Dashboard status filters are represented by metric buttons in the overview panel.
|
||||
|
||||
Filter rules:
|
||||
|
||||
- `all`: every material.
|
||||
- `studied`: material has practiced lines or playback progress.
|
||||
- `unstudied`: material has no practiced lines and no playback progress.
|
||||
- `favorites`: material ID is in the current user's favorites.
|
||||
- `difficult`: material progress has at least one difficult line.
|
||||
|
||||
If the visitor is not logged in:
|
||||
|
||||
- `studied`, `favorites`, and `difficult` counts are zero.
|
||||
- Clicking those filters shows an empty state that asks the learner to log in before tracking personal learning data.
|
||||
- `all` and `unstudied` still work from the material list.
|
||||
|
||||
Search and tag filters combine with the active status filter.
|
||||
|
||||
## Dashboard Metrics
|
||||
|
||||
Metrics are calculated in the browser from loaded videos and local user state.
|
||||
|
||||
Definitions:
|
||||
|
||||
- total materials: number of videos loaded from `/api/videos`.
|
||||
- studied materials: materials with `currentTime > 1`, `activeLineIndex > 0`, or at least one practiced line.
|
||||
- unstudied materials: total minus studied materials for the current user.
|
||||
- favorite materials: current user's `favorites` list intersected with loaded videos.
|
||||
- difficult materials: materials whose progress has at least one difficult line.
|
||||
|
||||
Metrics should update immediately after:
|
||||
|
||||
- login or logout
|
||||
- clicking a favorite button on a card
|
||||
- changing filters
|
||||
- reloading materials
|
||||
|
||||
Study-page progress changes are already stored in localStorage. The home page reads that state when it loads.
|
||||
|
||||
## Material Cards
|
||||
|
||||
Each card displays:
|
||||
|
||||
- generated preview cover
|
||||
- title
|
||||
- speaker/source
|
||||
- tags
|
||||
- subtitle language summary
|
||||
- sentence count
|
||||
- practiced percentage
|
||||
- difficult-line count
|
||||
- progress hint, such as `已练 3/12 · 25%` or `看到 02:04`
|
||||
- favorite button
|
||||
|
||||
Favorite behavior:
|
||||
|
||||
- Clicking the favorite button toggles the current video in the user's `favorites`.
|
||||
- The click does not open the study page.
|
||||
- If no user is logged in, show a short alert asking the learner to log in first.
|
||||
|
||||
Card navigation:
|
||||
|
||||
- Clicking the non-button area opens `study.html?video=<id>`.
|
||||
|
||||
## Empty States
|
||||
|
||||
Empty states should explain the current filter result.
|
||||
|
||||
Examples:
|
||||
|
||||
- No materials at all:
|
||||
- admin user: `还没有素材,去后台添加第一个素材。`
|
||||
- normal visitor: `暂无素材。`
|
||||
- Search or category has no matches:
|
||||
- `没有匹配的素材。`
|
||||
- Personal filter without login:
|
||||
- `登录后可以查看你的学习记录。`
|
||||
- Favorites filter with no favorites:
|
||||
- `还没有收藏素材。`
|
||||
- Difficult filter with no difficult materials:
|
||||
- `还没有标记难句。`
|
||||
|
||||
## State And Data
|
||||
|
||||
No backend changes are required.
|
||||
|
||||
Home Dashboard v1 uses:
|
||||
|
||||
- `GET /api/videos`
|
||||
- `localStorage` key `speaking-lab-state-v1`
|
||||
- existing user shape:
|
||||
- `favorites`
|
||||
- `watchLater`
|
||||
- `progress`
|
||||
|
||||
Helper logic in `home.js` should stay local to the home page. Shared backend schema is unchanged.
|
||||
|
||||
## Error Handling
|
||||
|
||||
If `/api/videos` fails:
|
||||
|
||||
- show the API error or a clear fallback message
|
||||
- clear the grid
|
||||
- avoid crashing metric rendering
|
||||
|
||||
If localStorage is malformed:
|
||||
|
||||
- fall back to an empty user state
|
||||
- continue rendering materials
|
||||
|
||||
If a progress entry refers to a deleted material:
|
||||
|
||||
- ignore it in dashboard metrics
|
||||
|
||||
## Testing
|
||||
|
||||
Automated checks:
|
||||
|
||||
```powershell
|
||||
node --check home.js
|
||||
node --check app.js
|
||||
node --check admin.js
|
||||
python -m py_compile backend\main.py backend\db.py
|
||||
node tests\progress-helpers.test.mjs
|
||||
node tests\admin-file-input.test.mjs
|
||||
```
|
||||
|
||||
Manual browser checks:
|
||||
|
||||
1. Open `http://127.0.0.1:8000/`.
|
||||
2. Confirm the dashboard overview appears.
|
||||
3. Confirm materials render as cards.
|
||||
4. Search by title, speaker, and tag.
|
||||
5. Click a category chip and confirm it combines with search.
|
||||
6. Log in as a normal user.
|
||||
7. Favorite a card from the home page and confirm the favorite count updates.
|
||||
8. Click the favorite filter and confirm only favorites show.
|
||||
9. Open a material, mark one line practiced and one line difficult, then return home.
|
||||
10. Confirm studied and difficult counts update after reload.
|
||||
11. Confirm clicking a card opens `study.html?video=<id>`.
|
||||
12. Confirm an admin user still sees the admin link.
|
||||
|
||||
## Future Extensions
|
||||
|
||||
Good follow-up features after this:
|
||||
|
||||
- Upload custom cover images in the admin page.
|
||||
- Add a dedicated difficult-sentence review page.
|
||||
- Add a daily learning/check-in calendar.
|
||||
- Move user progress to SQLite when preparing for shared accounts.
|
||||
- Add real authentication before deploying publicly.
|
||||
@@ -0,0 +1,215 @@
|
||||
# Speaking Lab Home Page v1 Design
|
||||
|
||||
## Goal
|
||||
|
||||
Add a dedicated home page for browsing learning materials, so `http://127.0.0.1:8000/` feels like a shareable product entry instead of opening directly inside the study workspace.
|
||||
|
||||
## Current Context
|
||||
|
||||
Speaking Lab currently has:
|
||||
|
||||
- `index.html`: the study page.
|
||||
- `app.js`: study-page logic for loading videos, search, tags, subtitles, recording, favorites, watch-later, and learning progress.
|
||||
- `admin.html` and `admin.js`: admin material management.
|
||||
- `/api/videos`: returns material metadata, tags, video URLs, subtitles, and source type.
|
||||
- Local user state in `localStorage`.
|
||||
|
||||
The current left-side material rail is useful inside the study page, but it is too narrow to work as the product home page.
|
||||
|
||||
## Scope
|
||||
|
||||
Home Page v1 includes:
|
||||
|
||||
- Make `/` open the new home page.
|
||||
- Move the current study experience to `study.html`.
|
||||
- Add `home.html` and `home.js`.
|
||||
- Home page supports searching materials.
|
||||
- Home page supports category filtering from material tags.
|
||||
- Home page shows material cards in a responsive grid.
|
||||
- Cards show an automatic preview cover when no real thumbnail exists.
|
||||
- Cards show title, speaker/source, tags, subtitle languages, and learning progress.
|
||||
- Clicking a card opens `study.html?video=<id>`.
|
||||
- The study page reads `?video=<id>` and opens that material first.
|
||||
- Admin entry remains available for admin users.
|
||||
|
||||
Home Page v1 excludes:
|
||||
|
||||
- Uploading custom thumbnails.
|
||||
- Automatically extracting thumbnails from video files.
|
||||
- Pagination.
|
||||
- Advanced sorting.
|
||||
- Multi-level category management.
|
||||
- Backend search endpoints.
|
||||
- Server-side user authentication.
|
||||
|
||||
## Page Routing
|
||||
|
||||
Routes after this feature:
|
||||
|
||||
```text
|
||||
/
|
||||
```
|
||||
|
||||
Shows the new home page.
|
||||
|
||||
```text
|
||||
/study.html
|
||||
```
|
||||
|
||||
Shows the current learning workspace.
|
||||
|
||||
```text
|
||||
/study.html?video=<id>
|
||||
```
|
||||
|
||||
Opens the learning workspace and selects the requested material.
|
||||
|
||||
```text
|
||||
/admin.html
|
||||
```
|
||||
|
||||
Shows the existing admin page.
|
||||
|
||||
## Home Page Layout
|
||||
|
||||
The home page uses a product-library layout:
|
||||
|
||||
- Top bar:
|
||||
- `Speaking Lab`
|
||||
- Search input
|
||||
- Login/register or current user
|
||||
- Admin link shown only for admin users
|
||||
- Category row:
|
||||
- `全部`
|
||||
- One chip per tag from loaded materials
|
||||
- Main content:
|
||||
- Responsive grid of material cards
|
||||
- Empty state when no materials match
|
||||
|
||||
The home page should be practical and product-like, not a marketing landing page. It should prioritize finding and opening materials.
|
||||
|
||||
## Material Card
|
||||
|
||||
Each card displays:
|
||||
|
||||
- Preview cover area.
|
||||
- Title.
|
||||
- Speaker/source.
|
||||
- Tags.
|
||||
- Subtitle language summary, for example `英文 / 中文`.
|
||||
- Learning progress summary, for example `已练 2/15 · 13%` or `看到 02:04`.
|
||||
|
||||
Clicking anywhere on a card opens:
|
||||
|
||||
```text
|
||||
study.html?video=<id>
|
||||
```
|
||||
|
||||
## Preview Cover Strategy
|
||||
|
||||
Home Page v1 uses generated CSS preview covers instead of real video thumbnails.
|
||||
|
||||
Reason:
|
||||
|
||||
- Local and remote videos may not be safe or easy to screenshot in the browser.
|
||||
- Cross-origin video URLs may block frame extraction.
|
||||
- A generated cover is reliable and fast for the prototype.
|
||||
|
||||
Generated cover contents:
|
||||
|
||||
- Large short title or initials.
|
||||
- First tag as a category badge.
|
||||
- Subtle color variant based on material ID.
|
||||
|
||||
Future extension:
|
||||
|
||||
- Add a backend `thumbnail_url` field.
|
||||
- Allow admin upload of cover images.
|
||||
- Show real thumbnail when available, generated cover as fallback.
|
||||
|
||||
## Search And Category Behavior
|
||||
|
||||
Search matches:
|
||||
|
||||
- Title.
|
||||
- Speaker/source.
|
||||
- Description.
|
||||
- Tags.
|
||||
|
||||
Category filtering:
|
||||
|
||||
- `全部` shows all materials.
|
||||
- Clicking a tag chip filters cards whose tags include that tag.
|
||||
- Search and category filters combine.
|
||||
|
||||
## Study Page Behavior
|
||||
|
||||
The current study page becomes `study.html`.
|
||||
|
||||
Changes:
|
||||
|
||||
- It keeps existing playback, subtitles, recording, progress, favorites, and admin entry behavior.
|
||||
- On load, it checks `URLSearchParams` for `video`.
|
||||
- If the requested video exists, it selects that video.
|
||||
- If the requested video does not exist, it falls back to existing active-video behavior.
|
||||
|
||||
The study page may keep the left material rail for quick switching during learning.
|
||||
|
||||
## State And Data
|
||||
|
||||
Home page uses:
|
||||
|
||||
- `GET /api/videos` for materials.
|
||||
- The same `speaking-lab-state-v1` localStorage key for users and progress.
|
||||
|
||||
No new database table is required.
|
||||
|
||||
No backend API change is required for Home Page v1.
|
||||
|
||||
## Error Handling
|
||||
|
||||
If `/api/videos` fails:
|
||||
|
||||
- Show a clear local error state.
|
||||
- Home page may show demo/sample materials only if the study page already uses those as fallback.
|
||||
|
||||
If no materials exist:
|
||||
|
||||
- Show an empty state that points admin users to `admin.html`.
|
||||
- Non-admin users see a simple “暂无素材” state.
|
||||
|
||||
If `study.html?video=<id>` references a missing material:
|
||||
|
||||
- Select the first available material.
|
||||
- Do not crash.
|
||||
|
||||
## Testing
|
||||
|
||||
Automated checks:
|
||||
|
||||
- `node --check home.js`
|
||||
- `node --check app.js`
|
||||
- Existing helper tests still pass.
|
||||
|
||||
Manual/browser verification:
|
||||
|
||||
1. Open `http://127.0.0.1:8000/`.
|
||||
2. Confirm the home page appears, not the study workspace.
|
||||
3. Confirm materials render as cards.
|
||||
4. Confirm search filters by title/source/tag.
|
||||
5. Confirm category chips filter cards.
|
||||
6. Confirm each card has a generated preview cover.
|
||||
7. Click a card.
|
||||
8. Confirm `study.html?video=<id>` opens and selects that material.
|
||||
9. Confirm `admin.html` still works.
|
||||
10. Confirm logged-in admin users can see an admin entry on the home page.
|
||||
|
||||
## Future Extensions
|
||||
|
||||
Good follow-up features:
|
||||
|
||||
- Upload custom thumbnail in admin page.
|
||||
- Add `我的学习` section on the home page.
|
||||
- Add sorting by recently studied, newest, or most practiced.
|
||||
- Add collections or curated playlists.
|
||||
- Move search/filter to backend when the library becomes large.
|
||||
@@ -0,0 +1,78 @@
|
||||
# Speaking Lab Material Edit v1 Design
|
||||
|
||||
## Goal
|
||||
|
||||
Allow an admin to update already uploaded materials without deleting and recreating them.
|
||||
|
||||
## Scope
|
||||
|
||||
Material Edit v1 includes:
|
||||
|
||||
- Add an `编辑` action to each material in the admin list.
|
||||
- Load the selected material into the existing admin form.
|
||||
- Allow editing title, speaker/source, description, tags, and video URL.
|
||||
- Allow replacing the video file.
|
||||
- Allow replacing English and Chinese subtitle files independently.
|
||||
- Preserve existing files when no replacement file is selected.
|
||||
- Save changes through `PATCH /api/videos/{video_id}`.
|
||||
- Clean up old local uploaded files when they are replaced.
|
||||
- Add `取消编辑` to return the form to add mode.
|
||||
|
||||
Material Edit v1 excludes:
|
||||
|
||||
- Rich subtitle editing in the browser.
|
||||
- Removing a single subtitle without replacing it.
|
||||
- Server-side authentication or permissions.
|
||||
- Version history or undo.
|
||||
|
||||
## Backend Behavior
|
||||
|
||||
`PATCH /api/videos/{video_id}` accepts multipart form data:
|
||||
|
||||
- `title`
|
||||
- `speaker`
|
||||
- `description`
|
||||
- `tags`
|
||||
- `video_url`
|
||||
- optional `video_file`
|
||||
- optional `subtitle_en`
|
||||
- optional `subtitle_zh`
|
||||
|
||||
Rules:
|
||||
|
||||
- Title is required.
|
||||
- If a new video file is uploaded, it replaces the old video source.
|
||||
- If no new video file is uploaded, `video_url` is used as the video source.
|
||||
- If `video_url` is left empty during edit and no video file is uploaded, the existing video source is preserved.
|
||||
- Replaced local files under `/uploads/...` are deleted safely.
|
||||
- Remote `http://` / `https://` URLs are never deleted as files.
|
||||
|
||||
## Frontend Behavior
|
||||
|
||||
Admin page form has two modes:
|
||||
|
||||
- Add mode: submit creates a new material.
|
||||
- Edit mode: submit updates the selected material.
|
||||
|
||||
When entering edit mode:
|
||||
|
||||
- Form heading changes to `编辑素材`.
|
||||
- Submit button changes to `保存修改`.
|
||||
- Existing text fields are filled.
|
||||
- File buttons show that existing files are retained unless replaced.
|
||||
- Material being edited is visually highlighted in the list.
|
||||
|
||||
When update succeeds:
|
||||
|
||||
- Form resets to add mode.
|
||||
- Material list refreshes.
|
||||
- Success message says `素材已更新。`
|
||||
|
||||
## Verification
|
||||
|
||||
- Static checks pass.
|
||||
- Create a temporary material through API.
|
||||
- Patch its title/tags.
|
||||
- Patch its subtitle or video file when a local test file is available.
|
||||
- Confirm `GET /api/videos/{id}` returns updated data.
|
||||
- Delete the temporary material.
|
||||
@@ -0,0 +1,55 @@
|
||||
# Speaking Lab Study Focus Layout Design
|
||||
|
||||
## Goal
|
||||
|
||||
Make the study page focus on the active learning session by removing the left material rail. Material discovery now lives on the home page, so the study page should give more room to the video, subtitle controls, and transcript.
|
||||
|
||||
## Scope
|
||||
|
||||
Included:
|
||||
|
||||
- Remove the left material rail from `study.html`.
|
||||
- Let the video learning panel occupy the space previously used by the rail.
|
||||
- Keep the right transcript panel.
|
||||
- Keep video playback, line navigation, recording, subtitles, continue learning, favorites, and watch-later.
|
||||
- Keep admin access on the home page; the study page no longer needs the rail-side admin button.
|
||||
- Add JavaScript guards so removed rail elements do not cause runtime errors.
|
||||
|
||||
Excluded:
|
||||
|
||||
- Home page changes.
|
||||
- README changes.
|
||||
- Backend changes.
|
||||
- Admin page changes.
|
||||
- New navigation or routing.
|
||||
|
||||
## Behavior
|
||||
|
||||
The study page still opens the selected material from `study.html?video=<id>`.
|
||||
|
||||
If the user opens `study.html` directly:
|
||||
|
||||
- The page selects the previously active video or the first available video.
|
||||
- The user can return to the home page manually through browser navigation or direct URL.
|
||||
|
||||
The material list search and tag filtering UI is removed from the study page.
|
||||
|
||||
## Testing
|
||||
|
||||
Run:
|
||||
|
||||
```powershell
|
||||
node --check app.js
|
||||
node --check home.js
|
||||
node --check admin.js
|
||||
node tests\progress-helpers.test.mjs
|
||||
node tests\admin-file-input.test.mjs
|
||||
```
|
||||
|
||||
Manual checks:
|
||||
|
||||
1. Open `http://127.0.0.1:8000/study.html`.
|
||||
2. Confirm the left material rail is gone.
|
||||
3. Confirm the video panel starts near the left edge of the study layout.
|
||||
4. Confirm subtitle tabs and transcript still render.
|
||||
5. Open from a home card and confirm `study.html?video=<id>` still selects the material.
|
||||
@@ -0,0 +1,69 @@
|
||||
# Speaking Lab Subtitle Delete Cues Design
|
||||
|
||||
## Goal
|
||||
|
||||
Allow an admin to delete problematic subtitle cue blocks from an already uploaded material without editing cue text or timestamps.
|
||||
|
||||
## Scope
|
||||
|
||||
Included:
|
||||
|
||||
- Add subtitle cue deletion UI in the existing admin edit flow.
|
||||
- Support English and Chinese subtitle tracks independently.
|
||||
- Delete whole cue blocks only.
|
||||
- Save updated subtitle content through the existing material update request.
|
||||
- Keep existing subtitle file replacement support.
|
||||
|
||||
Excluded:
|
||||
|
||||
- Editing subtitle text.
|
||||
- Editing timestamps.
|
||||
- Reordering subtitle cues.
|
||||
- Deleting video materials.
|
||||
- Study page subtitle editing.
|
||||
- README changes.
|
||||
|
||||
## Backend
|
||||
|
||||
Extend `PATCH /api/videos/{video_id}` with optional form fields:
|
||||
|
||||
- `subtitle_en_content`
|
||||
- `subtitle_zh_content`
|
||||
|
||||
When those fields are provided and no replacement upload is provided for that language, update the corresponding subtitle row content in SQLite.
|
||||
|
||||
Existing uploaded subtitle file paths can stay unchanged because this local prototype reads subtitle content from the database response.
|
||||
|
||||
## Admin UI
|
||||
|
||||
When an admin clicks `编辑` on a material:
|
||||
|
||||
- Show an English subtitle deletion section if the material has English subtitle content.
|
||||
- Show a Chinese subtitle deletion section if the material has Chinese subtitle content.
|
||||
- Each cue shows time range and text.
|
||||
- Each cue has a `删除` button.
|
||||
- Deleted cues disappear from the list immediately.
|
||||
- Saving the material submits the remaining subtitle content.
|
||||
|
||||
When the admin cancels editing or starts editing another material, subtitle deletion state resets.
|
||||
|
||||
## Testing
|
||||
|
||||
Run:
|
||||
|
||||
```powershell
|
||||
python -m py_compile backend\main.py backend\db.py
|
||||
node --check admin.js
|
||||
node --check app.js
|
||||
node --check home.js
|
||||
node tests\admin-file-input.test.mjs
|
||||
node tests\progress-helpers.test.mjs
|
||||
```
|
||||
|
||||
Manual checks:
|
||||
|
||||
1. Log in as admin and open `admin.html`.
|
||||
2. Edit a material with subtitles.
|
||||
3. Delete one subtitle cue.
|
||||
4. Save.
|
||||
5. Reopen the material in study page and confirm the deleted cue is gone.
|
||||
Reference in new issue
Block a user