Skip to content

Social media: video upload and processing, weekly backup, disk warning (#113) - #122

Merged
Oceandek merged 1 commit into
mainfrom
feat/weekly-video
Nov 12, 2026
Merged

Oceandek merged 1 commit into
mainfrom
feat/weekly-video

Conversation

@Oceandek

Copy link
Copy Markdown
Collaborator

Closes #113, part of spec #110 (Social media posts).

What's new

  • One video per Weekly update:
    • MP4 or MOV, at most 200 MB and 90 seconds, uploaded on the Weekly update page after the same Consent tick as the photos.
    • Only the type, length and size are checked, with ffmpeg -i. A second video, a longer or larger file, or a file that isn't a video is refused with a clear message.
    • The upload is streamed to an incoming/ folder on the volume, never read into memory as a whole, and is deleted when it is refused.
  • Processing in the background (FastAPI background task):
    • The video shows "Preparing the video…", and the page checks again every 5 s until it is ready.
    • Two copies are made: an Instagram-friendly copy (H.264/AAC, long side at most 1920, +faststart) and a small AI copy (640 px, no sound) for Social media: AI Post suggestions from the school LLM #114.
    • The original is then deleted. If ffmpeg fails, the video shows as "couldn't be prepared" and can be removed.
    • After a restart, unfinished videos are processed again (resume_processing in the lifespan).
    • Removing a video deletes all of its files, also while it is still being processed.
  • ffmpeg comes with the imageio-ffmpeg package: a static build with libx264, for Linux, Windows and macOS. So the Docker image, CI and local runs need no apt install. ffmpeg is called with fixed arguments, and the uploaded name is never used.
  • Serving: GET /api/weekly-media/{id} now uses a FileResponse, and a video is only served once it is ready. Same access rules as photos.
  • Weekly backup: backup.sh archives the social-media volume (uncompressed tar, leaving out incoming/):
    • every Sunday night and on every restore-test, so after each deploy;
    • only the 2 newest archives are kept (KEEP_SOCIAL_MEDIA).
    • The restore test checks that the archive holds one main file per restored weekly_media row.
    • Tested locally with postgres:16 against the test database: it passes, it fails with an extra file (1 file vs 0 rows), it ignores AI copies and incoming/, and the 3rd archive deletes the oldest.
    • docs/backups.md has the restore steps.
  • Disk warning:
    • GET /api/social/storage (Teachers and the Superuser) returns the share of the disk in use.
    • The Superuser's Social media screen shows a Storage card ("The server's disk is N% full.").
    • Above 80%, a warning appears there and on the Weekly updates card of a Project's page.
  • Migration 0022: weekly_media.state (processing, ready or failed) and seconds.

Tests

  • Backend: 407 passed. New test_weekly_video.py covers:
    • an MP4 processed into two copies (640×360, about 2 s, served as video/mp4, original gone);
    • MOV accepted;
    • consent required;
    • a 95-second video refused, and a file that isn't a video refused;
    • a too-large video refused (limit patched) with incoming/ emptied;
    • one video per week, removable until the deadline, with all files deleted;
    • an ffmpeg failure showing as failed;
    • processing resuming after a "restart";
    • the disk endpoint.
  • Frontend: 131 passed. New tests cover:
    • uploading a video until it is ready;
    • the disk warning on the Social media screen.

Flaky test fixed: test_my_project.py::test_student_sees_their_projects_photo clicked Log out while the reloaded Project page was still loading. Its last backend calls then ran without a session, and NiceGUI logged "Your session has expired" at teardown. The extra cards on the Project page (#111, #113) made this happen every time, which is how the cause showed up. The test now waits for the page's last card first. It passed 3/3, and test_login.py 3/3.

Note on disk space: 2 weekly archives plus the live volume can take about 3× the media. With 10–15 Projects that is a few GB per month, which fits the 40 GB disk, and the warning shows at 80%.

🤖 Generated with Claude Code

#113)

One video per Weekly update (MP4/MOV, 200 MB, 90 s), re-encoded in the
background into a 1080p H.264/AAC copy and a small AI copy, with ffmpeg from
imageio-ffmpeg; resumed after a restart. backup.sh archives the social-media
volume weekly and on restore-test (2 newest kept) and compares it with the
weekly_media rows. Staff see a warning above 80% disk use. Migration 0022.
Also fixes the flaky My project photo test (it logged out mid-load).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Oceandek
Oceandek merged commit 25296d3 into main Nov 12, 2026
2 checks passed
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.

Social media: video upload and processing, weekly backup, disk warning

1 participant