> **Feature plan:** [Step 1](./audio_files_step1_solution_assessment.md) · [Step 2](./audio_files_step2_feature_description.md) · [Step 3](./audio_files_step3_development_plan.md) · [Step 4](./audio_files_step4_implementation_summary.md)

# Audio files: Step 2 feature description

Step 1 approved and committed on `plans/audio-files` (`61cdba4`). This step covers the first slice: MP3/M4A upload, the play bar with Download, and the Friday queue order. Browser conversion is the next cycle. Server conversion is a to-do.

## Problem

Rap Club members can't put their own recordings on the site. A verse, a beat or a voice memo has to go to SoundCloud or YouTube first, and only the link can be shared.

## Concepts touched

- [Image serving](../../concepts/image_serving.md): used unchanged as the pattern (stored outside Git under the hash a signed post names, with a size cap and a store cap).
- [Media embed](../../concepts/media_embed.md): changed. Its play bar also plays an attached file and offers Download.
- [Music section](../../concepts/music_section.md): changed. A track can be an upload, and the queue order changes.
- Audio attachment: new entry `docs/concepts/audio_attachment.md`, written with the work.

## User stories

- As a Rap Club member, I want to attach a recording from my phone to a post, so the club hears it without my uploading it somewhere else.
- As anyone reading the site, I want to press play and hear it right there, on my phone too, and download it if I want to keep it.
- As the person running Friday's meeting, I want this fortnight's uploads to play first, so new work gets heard before older links.
- As an operator, I want audio off by default and its storage capped, so a site doesn't fill its disk by surprise.

## Core requirements

- One audio file per post, MP3 or M4A only, at most three minutes and 8 MB. Anything else is refused with a plain message: "Export as MP3 or M4A, three minutes or less."
- The same people who can attach images can attach audio (approved members), behind its own flag, off by default on every site.
- The stored file is exactly the bytes the signed post names. It is served by its hash, removed with the post, and kept out of Git, like images.
- The site's play bar plays it: play/pause, a seek line, elapsed and total time, and a plain Download link. Only one thing plays at a time on a page. Without scripts, the browser's own player shows instead.
- The Friday queue plays uploads from the past 14 days first, then everything else, each group newest shared first as the queue does today (Ilya: "Newest first").

## Delivery scope

- Work type: application change.
- Completion boundary: a member on an iPhone attaches a voice memo (M4A) to a post on mitrapclub. The post shows the play bar in the thread and on `/tracks/`. A visitor on another phone plays it and downloads it. In the queue it plays before older tracks and links. Recovery: a refused file says why, and the draft and text stay put. Release: the flag stays off until Ilya turns it on for mitrapclub.

## Known user or environment

Ilya on an iPhone (Safari). Entry: the composer's … menu, "Attach audio". A file that is too long or the wrong format gets the export message before anything uploads; he trims or re-exports it and attaches again. Success shows as the play bar on his post, playing on the same phone. Evidence: a browser check at iPhone size, then Ilya's own check after deploy.

## Risks

- Safari's reading of M4A length and playback. Validate early with a real voice memo file in the browser check. Mitigation: if the length can't be read in the browser, the server's 8 MB cap still holds.
- Disk use. Images have a 256 MB store cap; audio needs its own. Decide the number in Step 3 and show usage in Tools.
- Rights: members may upload other people's songs. The same retract and moderation tools as images apply. Note it in the site's guidance; no new tooling.

## Shared component inventory

- Image upload: `public/assets/image_upload.js`, `templates/partials/image_compose_fields.php`, `ImageUploadValidator`, `ImageStore`, `ImageReference` (the signed `Image-v1:` header). Extend the same path with an audio sibling, not a new upload system, so permissions, hashing, removal and backup behave the same.
- Permission: the approved-member rule behind `Image-Upload-Allowed` (`ApiTextController`). Reuse it.
- Media embed: `MediaEmbedRenderer`, `media_embed_inline_player.js` and its "one player at a time" rule. Extend them for a local file instead of building a second player.
- Music: `MusicPageController` (rows, slides, queue additions) and `MUSIC_QUEUE_ENABLED`. Change only the ordering and let uploads count as playable.
- quill.py: `--image` exists. An `--audio` option is out of scope; note it for later.

## User flow

1. A member opens the composer, taps …, then "Attach audio", and picks a file.
2. The page checks type, length and size. A bad file gets the export message.
3. They post. The post shows the play bar.
4. Anyone taps play, scrubs, or taps Download.
5. On Friday, the queue opens with this fortnight's uploads, then the rest.

## Success criteria

- An iPhone voice memo and a desktop MP3 both attach, post and play, in Chromium and at iPhone size.
- A four-minute file, a WAV and a 9 MB file are each refused with the message, and the draft keeps its text.
- Download saves the original bytes; their hash matches the signed reference.
- With the flag off, nothing changes on any site.
- The queue's order matches the rule in a test with dated uploads and links.

*— Claude · 2026-12-04 UTC*

## Approval

Approved Step 2 on 2026-12-04 by Ilya, by voice while driving ("Approve step two").
