Skip to content

New: /edit/ Service (for editing .txt and .src in /media/source) - #368

Open
calaldees wants to merge 3 commits into
masterfrom
edit_service
Open

New: /edit/ Service (for editing .txt and .src in /media/source)#368
calaldees wants to merge 3 commits into
masterfrom
edit_service

Conversation

@calaldees

Copy link
Copy Markdown
Collaborator

Added the new /edit/ service to edit .txt and .srt files on the live server without contributors having to download all of /media/source

Fings wot goin dan in diz PR:

  • /api_edit/ NEW!
    • litestar and uv
    • app.py (all the framework shit)
      • I want to get out of framework world and into our own model world as soon as possible (I hate being intertwined with a particular framework - I want to untangle sanic from the api_queue logic)
    • model.py an abstraction to list, read, write files in /media/source
      • It keeps 3 backups as ORIGINAL_FILENAME.1.old and cycles/overwrites these based on mtime
    • index.html zero dependency vanilla js mini POS frontend (but it works).
  • api_queue
    • The Docker tests never ran! it ran the tests for upload! Gah!
      • The test run in the shell, just not docker RUN. Sanic has some weirdness. I've disabled the tests on build (which is not ideal)
    • Moved the container to uv (in prep for litestar move)
    • all dependencies tracked in uv.lock rather than pyproject.toml (We can still lock major versions in pyproject if needed, but most dependencies can be fluid and
    • Fixed some sanic warnings
  • processmedia3
    • Added source to tracks.json.
      • This is currently unused but it there should we need it in future.
      • I think it will help us identify where the track source has come from.
      • We need to profile how much bigger the tracks.json is. My assumption is that it will compress very very well.
  • Other
    • updated the docs to include the new edit service
    • I think? I've updated caddy correctly. This will need checking as I was unable to run it locally (some cert issue? I will ask for some gudience)
    • jiggled /tools/index.html

Probably worth squashing the commits on merge because the commit messages are a mess.

@calaldees
calaldees requested a review from shish April 16, 2026 12:19

@shish shish left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cherry-picked and merged several smaller parts of this to make it easier to focus on the main code~


FYI

without sources

2.8M tracks.json
280K tracks.json.br
352K tracks.json.gz

with sources

3.2M tracks.json
328K tracks.json.br
412K tracks.json.gz

Comment thread api_edit/edit/app.py Outdated


@litestar.get(
path="/files.json",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the other backend bits I've found it easier to use full paths at all times (eg this being /api/edit/files.json rather than /files.json), then setting the frontend (eg Caddy) to pass the full path through instead of just the suffix -- that way the URL is always /api/edit/files.json, in both dev and prod, publicly and privately, internally and externally - and there's no need to handle special cases or configure it differently in different situations

Comment thread api_edit/edit/app.py Outdated
Comment on lines +50 to +53
tags=("Public",),
summary="Single File Contents",
description=textwrap.dedent("""
"""),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all the methods are public, the summary says the same as the method name, and it's simple enough to not need an extra description, I'd simplify this to just path and media_type 👀

Comment thread api_edit/edit/model.py Outdated
Comment on lines +55 to +56
file_path_backup = self._get_file_backup(file_path)
file_path.copy(file_path_backup)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git commit $path -m 'changed via webui' feels better to me than adding our own version control system on top of the existing version control system

  • full history
  • can include extra metadata like author
  • we aren't creating extra files which then need to be ignored by humans and code
  • one workflow for looking at older versions (as opposed to eg checking .old files for some changes, and checking git log for other changes, and trying to figure out which of the two version control systems has the most up to date data)
  • no need to create new tools (things like "revert to the version from $DATE" already exist)

(technically we already have two version control systems, because syncthing is set to do versioned backups of the whole source folder, including the .git folder, so this would be our third nested VCS)

Comment thread api_queue/Dockerfile Outdated
Comment on lines +10 to +22
FROM base AS dependencies
COPY pyproject.toml uv.lock ./
RUN UV_NO_SYNC=False uv sync --no-dev
FROM dependencies AS test_dependencies
RUN UV_NO_SYNC=False uv sync --all-extras

FROM base AS production
VOLUME /logs
VOLUME /queues
VOLUME /media/processed
EXPOSE 8000
CMD ["python", "-m", "sanic", "api_queue.server.app", "--host", "0.0.0.0", "--port", "8000", "--single-process"]
# "--workers", "4" # workers are python.multithreading rather than async. For now, we can just stick with single process
FROM dependencies AS code
COPY ./api_queue ./api_queue
COPY ./*.py ./

FROM test_dependencies AS test
COPY --from=code /app .
COPY ./tests .

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to write a diagram so that I understand the layers here:

base
  \- dependencies
       |- test_dependencies
       |    \- test (technically "test" is a child of "test_dependencies"
       |             _and_ a child of "code", because of "COPY --from")
       \- code
            \- production

What are each of the layers for? Why do we need to copy data sideways between different branches of the tree?

I like the simplicity of

base (includes prod-dependencies and prod-code)
  |- test (adds test-dependencies and test-code on top)
  \- production (no code changes)

Comment thread api_queue/Dockerfile
Comment thread api_queue/Dockerfile Outdated
Comment thread api_queue/pyproject.toml Outdated
Comment thread api_queue/Dockerfile Outdated
Comment thread api_edit/edit/index.html Outdated
$button_save.dataset.file = file
$file_title.textContent = file
$file_content.value = `Loading ${file}`
fetch(`/file/${file}`)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(An example of code which works when run stand-alone, but breaks in production, because in prod the url is /api/edit/file/...)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!💯
I will make this relative

Comment thread frontend/Caddyfile
calaldees added 2 commits June 4, 2026 17:52
Using uv and litestar

api_edit now lists files

Untangled litestar with file model
Tweaked tools title

Edit service now functions in a basic way

Added `source`filename to `tracks.json`

api_edit as part of stack

api_edit: Added backup file rotation
Error state in client
Some dockerignore tweaks for completleness

logger fix

Added api_edit build action
Corrected api_queue build path

api_edit now shows track being edited
Attempt to move api_queue to uv (unfinshed)
Updated docs to include api_edit
un-ignored `uv.lock` (we already use package-lock.json so why not go all in with python - modern dev tools and their bloat)

Trying to get api_queue to run tests again

Moved api_queue to uv
Had to disable tests on docker build, but the test work when shelling into the container

fix tests in docker

api_edit tests
(still need to fix the compose tests - can't access the container)
* paths are absolute from top level `/api/edit/`
* Deprecated file_rotation backup and moving towards `git commit xxx`
* Queue Dockerfile can now run tests (no idea what jibble was messin with it 2 months ago)
* api_edit now gives warning on startup for no files (and skips folders with '.' it was crawling all of .venv
* trying to pannelbeat the tests into working again
Working towards git backup
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