Repository navigation
enh(relay): pass media paths on relative to the camera dir - #3379
Conversation
8b9953d to
9f3e441
Compare
9f3e441 to
0e11ca7
Compare
0e11ca7 to
1ddeb65
Compare
|
Hmm, I am not happy with adding a redundant argument to the relay event call. We could read the camera dir in camera_conf=$(awk -v "id=$motion_camera_id" '$1=="camera"{c++} c==id{print $2;exit}' "$motion_conf")
camera_dir=$(awk '/^target_dir /{print $2}' "$camera_conf")The same way, also the motionEye camera_id=$(awk '/^# @id /{print $3;exit}' "$camera_conf")But I am not sure sure anymore whether doing all this in shell really is the way to go, or whether we should accept that This is a design decision, I want to hear other opinions about. @zagrim @Marijn0 but also @JamBalaya56562 and @free-cup-holder-exe both incredibly active recently, be it with AI agent or not: Shall we require relative paths (and/or the motionEye camera ID) at the API already, outsource the conversion requirements to the relay shell script? Or shall we do that in the relay API, as a special case that is used by |
|
I'd rather not do this in the shell either, I would do the conversion in the relay API, so basically the way outlined above:
|
|
I'd go with the relay API (your second option). It already maps the motion camera ID to the motionEye one in Python ( |
motion calls relayevent.sh with its %f specifier, an absolute path, and the relay-event API passed that absolute filename on, so every consumer had to strip the camera dir off again for validation. The relay API now does that once: it strips the camera dir from the path motion sends, validates the remaining relative path and passes it on. The absolute path is joined again only where a file is accessed. motion's commands and relayevent.sh stay unchanged, so existing motion configs keep working. - relay_event.py: strip and validate once; pass the relative path to make_movie_preview and join it again for the upload subsystem. - mediafiles.make_movie_preview: take a relative path, validate it and join it with the camera dir; get_media_preview passes the relative path it already has. - tests: the make_movie_preview validation tests use relative paths; add a test that the absolute path is joined again for ffmpeg. The upload services (incl. S3) still receive an absolute path; making that relative is a separate upload-subsystem change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1ddeb65 to
9f315e2
Compare
Co-authored-by: MichaIng <micha@dietpi.com>
What
Pass media paths on relative to the camera dir inside motionEye.
motionstill calls the relay with its absolute%fpath; the relay-event API strips the camera dir once, validates the remaining relative path and passes it on. The absolute path is joined again only where a file is accessed (ffmpeg, upload).Follows the discussion in #3374 and #3379 (comment): the conversion lives in the API, where the motion → motionEye camera ID mapping already is, rather than in
relayevent.sh. motion's commands andrelayevent.share unchanged, so existing motion configs keep working.How
handlers/relay_event.py: strip the camera dir withremove_prefix, validate the relative path, pass it tomake_movie_preview, and join it again for the upload call, so the upload subsystem is unchanged.mediafiles.make_movie_preview: takes a relative path, validates it and joins it with the camera dir;get_media_previewpasses the relative path it already had.Scope / not included
The upload services (
UploadService.upload_file, incl. the S3 override) still receive an absolute path and keep deriving the cloud-relative name themselves; that naming is tied to@upload_subfolders. Making it relative would be a follow-up.Testing
tests/test_mediafiles.py: themake_movie_previewtraversal/escape tests pass relative malicious paths (the form it now receives); a new test asserts the absolute path is joined again for ffmpeg.ruff check/ruff format --checkpass.motionand camera.🤖 Generated with Claude Code