[PR #412] [MERGED] Refactor podcast media storage to lazy tenant resolver #721

Closed
opened 2026-03-13 21:05:37 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/412
Author: @AJaySi
Created: 3/12/2026
Status: Merged
Merged: 3/12/2026
Merged by: @AJaySi

Base: mainHead: codex/remove-global-mkdir-and-add-resolver-utility


📝 Commits (1)

  • d4baf88 Refactor podcast media storage to lazy tenant resolver

📊 Changes

4 files changed (+133 additions, -97 deletions)

View changed files

📝 backend/api/podcast/constants.py (+45 -5)
📝 backend/api/podcast/handlers/audio.py (+10 -18)
📝 backend/api/podcast/handlers/video.py (+50 -58)
📝 backend/api/podcast/utils.py (+28 -16)

📄 Description

Motivation

  • Remove module-import side effects that create directories eagerly and instead resolve media paths per-tenant at runtime to avoid filesystem operations during import.
  • Support tenant workspace media (workspace/workspace_/media/...) while maintaining compatibility reads from legacy data/media/podcast_* locations.
  • Ensure directories are created only when handlers or services actually need to write files.

Description

  • Removed global mkdir(...) calls and the eager audio_service initialization from backend/api/podcast/constants.py and added tenant-aware helpers: get_podcast_media_dir(...), get_podcast_media_read_dirs(...), get_podcast_audio_service(...), and _sanitize_user_id.
  • Added a shared resolver _resolve_podcast_media_file(...) and updated load_podcast_audio_bytes(...) in backend/api/podcast/utils.py to perform tenant-first lookups with legacy fallback and safe path traversal checks.
  • Updated backend/api/podcast/handlers/audio.py to use get_podcast_media_dir(...)/get_podcast_audio_service(...) for uploads, generated audio, combined audio output, and serving; reads/writes no longer reference static global directory constants.
  • Updated backend/api/podcast/handlers/video.py to read/write scene and final videos through the resolver helpers (get_podcast_media_dir(...), get_podcast_media_read_dirs(...), and _resolve_podcast_media_file(...)) and to prefer tenant workspace directories while falling back to legacy paths.

Testing

  • Compiled updated modules with python -m compileall backend/api/podcast/constants.py backend/api/podcast/utils.py backend/api/podcast/handlers/audio.py backend/api/podcast/handlers/video.py, which completed successfully.
  • Verified repository state and created a commit for the refactor (Refactor podcast media storage to lazy tenant resolver).

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/412 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 3/12/2026 **Status:** ✅ Merged **Merged:** 3/12/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/remove-global-mkdir-and-add-resolver-utility` --- ### 📝 Commits (1) - [`d4baf88`](https://github.com/AJaySi/ALwrity/commit/d4baf8828ee0630ff4541b45331bb33f920d9762) Refactor podcast media storage to lazy tenant resolver ### 📊 Changes **4 files changed** (+133 additions, -97 deletions) <details> <summary>View changed files</summary> 📝 `backend/api/podcast/constants.py` (+45 -5) 📝 `backend/api/podcast/handlers/audio.py` (+10 -18) 📝 `backend/api/podcast/handlers/video.py` (+50 -58) 📝 `backend/api/podcast/utils.py` (+28 -16) </details> ### 📄 Description ### Motivation - Remove module-import side effects that create directories eagerly and instead resolve media paths per-tenant at runtime to avoid filesystem operations during import. - Support tenant workspace media (workspace/workspace_<user>/media/...) while maintaining compatibility reads from legacy `data/media/podcast_*` locations. - Ensure directories are created only when handlers or services actually need to write files. ### Description - Removed global `mkdir(...)` calls and the eager `audio_service` initialization from `backend/api/podcast/constants.py` and added tenant-aware helpers: `get_podcast_media_dir(...)`, `get_podcast_media_read_dirs(...)`, `get_podcast_audio_service(...)`, and `_sanitize_user_id`. - Added a shared resolver `_resolve_podcast_media_file(...)` and updated `load_podcast_audio_bytes(...)` in `backend/api/podcast/utils.py` to perform tenant-first lookups with legacy fallback and safe path traversal checks. - Updated `backend/api/podcast/handlers/audio.py` to use `get_podcast_media_dir(...)`/`get_podcast_audio_service(...)` for uploads, generated audio, combined audio output, and serving; reads/writes no longer reference static global directory constants. - Updated `backend/api/podcast/handlers/video.py` to read/write scene and final videos through the resolver helpers (`get_podcast_media_dir(...)`, `get_podcast_media_read_dirs(...)`, and `_resolve_podcast_media_file(...)`) and to prefer tenant workspace directories while falling back to legacy paths. ### Testing - Compiled updated modules with `python -m compileall backend/api/podcast/constants.py backend/api/podcast/utils.py backend/api/podcast/handlers/audio.py backend/api/podcast/handlers/video.py`, which completed successfully. - Verified repository state and created a commit for the refactor (`Refactor podcast media storage to lazy tenant resolver`). ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_69afb0eafe7c8328bfa51d9a4a94a10b) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-13 21:05:37 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#721
No description provided.