Skip to content

fix: persist classroom to server for cross-device access#218

Open
reddingit wants to merge 1 commit intoTHU-MAIC:mainfrom
reddingit:fix/enable-cross-device-classroom-access
Open

fix: persist classroom to server for cross-device access#218
reddingit wants to merge 1 commit intoTHU-MAIC:mainfrom
reddingit:fix/enable-cross-device-classroom-access

Conversation

@reddingit
Copy link

Summary

Fixes 404 errors when accessing classrooms from different devices on the same network. Previously, classrooms were only stored in browser IndexedDB, making them inaccessible from other devices. This change persists classroom data to server-side storage, enabling cross-device access via the API.

Related Issues

N/A (new fix)

Changes

  • app/generation-preview/page.tsx: Added server-side persistence call after first scene generation, before navigation to classroom page
  • app/classroom/[id]/page.tsx: Added server-side update call in onComplete callback when all scenes finish generation
  • Data is now saved to data/classrooms/{id}.json on the server filesystem
  • Falls back gracefully if server persistence fails (continues with local-only storage)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Verification

Steps to reproduce / test

  1. Start dev server: pnpm dev
  2. On Device A (localhost), create a new course and wait for first scene to complete
  3. On Device B (LAN), access http://<Device-A-IP>:3000/classroom/<id>
  4. Verify classroom loads successfully instead of 404
  5. Wait for all scenes to complete generation
  6. Refresh on Device B to verify full content is available

What you personally verified

  • Code follows existing patterns in the codebase (uses existing /api/classroom endpoint)
  • Error handling is robust (try-catch with fallback behavior)
  • No breaking changes - existing single-device workflow unaffected
  • TypeScript types are correct

Evidence

  • CI passes (pnpm check && pnpm lint && npx tsc --noEmit)
  • Manually tested locally (pending user verification)
  • Screenshots / recordings attached (N/A - backend behavior change)

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have added/updated documentation as needed
  • My changes do not introduce new warnings

Previously, classrooms were only stored in browser IndexedDB, making them
inaccessible from other devices on the same network. This fix:

- Calls POST /api/classroom when first scene is generated to persist initial data
- Updates server storage again when all scenes complete generation
- Allows other devices to fetch classroom data via API instead of relying solely on local storage

Fixes 404 errors when accessing classrooms from different devices in LAN.

Editor: vscode
@reddingit reddingit force-pushed the fix/enable-cross-device-classroom-access branch from 3b6bd50 to 0a2f5da Compare March 23, 2026 03:26
@XerxesSimon
Copy link

@reddingit
Thank you so much for your optimized code. I have completed it according to the code you wrote, but now I encounter a problem: how can the front-end data trigger the generated PPT content to be saved to the back-end and then saved as {id}.json? I accidentally triggered the save once before, but I can no longer find the way to do it afterward. I hope you can give me some guidance when you have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants