mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
Add private (non-published) tracks option (#403)
@coderabbitai ignore ## Summary - Add `is_private` flag to jobs that changes distribution behavior for non-published tracks - Private jobs upload to Dropbox `Tracks-NonPublished` folder with `NOMADNP` brand prefix - Private jobs skip YouTube and Google Drive uploads entirely - Completion emails omit YouTube section for private jobs - Available to all users at job creation; admin can toggle on existing jobs - When admin toggles completed job to private, existing outputs are auto-deleted ## Changes ### Backend - **Job model**: Added `is_private: bool = False` to `Job` and `JobCreate` - **Config**: Added `DEFAULT_PRIVATE_DROPBOX_PATH` and `DEFAULT_PRIVATE_BRAND_PREFIX` settings - **Distribution helper**: New `get_effective_distribution_for_job()` in `job_defaults_service.py` applies private overrides at runtime - **Orchestrator + native paths**: Both distribution code paths use the helper (per "Fix Both Sides" lesson) - **Email template**: YouTube section conditionally removed when `is_private=True` - **Credential pre-validation**: Skip YouTube/GDrive credential checks for private jobs - **API endpoints**: All 4 job creation endpoints accept `is_private`; admin can PATCH it - **Admin auto-delete**: Toggling completed job to private triggers output deletion ### Frontend - **Job creation form**: "Private (Non-Published)" checkbox on all 3 tabs (upload, URL, search) - **Admin dashboard**: Private toggle in job configuration section - **API interfaces**: Updated TypeScript interfaces and API methods ### Tests - 23 unit tests covering model, distribution overrides, email template, notification service, request models, admin toggle, and orchestrator config - Fixed MagicMock truthiness issue in existing tests ## Test plan - [x] All 23 private tracks tests pass - [x] All 1794 existing backend tests pass (1 flaky unrelated test) - [x] CodeRabbit review: credential pre-validation issue found and fixed - [ ] Manual: Create private job end-to-end, verify Dropbox folder - [ ] Manual: Verify completion email has Dropbox link but no YouTube section - [ ] Manual: Admin toggle on completed job deletes outputs 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
0cee5b8ae3
commit
fa9bc8eeeb
25 files changed
+1257
-45
No files matched your search
@@ -0,0 +1,279 @@
|
||||
# Plan: Private (Non-Published) Tracks
|
||||
|
||||
**Created:** 2026-02-24
|
||||
**Branch:** feat/sess-20260224-1149-private-tracks
|
||||
**Status:** Implemented
|
||||
|
||||
## Overview
|
||||
|
||||
Add a `is_private` flag to jobs that changes distribution behavior:
|
||||
- **Dropbox**: Uses `Tracks-NonPublished` folder (not `Tracks-Organized`) with brand code `NOMADNP` (not `NOMAD`)
|
||||
- **YouTube**: Skipped entirely
|
||||
- **Google Drive**: Skipped entirely
|
||||
- **Email**: Completion email includes Dropbox link but no YouTube section
|
||||
- **Discord**: Still notified (for internal tracking)
|
||||
|
||||
Available to all users at job creation and toggleable by admin on existing jobs.
|
||||
|
||||
## Requirements
|
||||
|
||||
- [ ] All users can mark a job as "Private (Non-Published)" when creating it
|
||||
- [ ] Admin can toggle `is_private` on any existing job via admin dashboard
|
||||
- [ ] Private jobs upload to Dropbox at `Tracks-NonPublished` with `NOMADNP-XXXX` brand codes
|
||||
- [ ] Private jobs skip YouTube and Google Drive uploads entirely
|
||||
- [ ] Completion emails omit YouTube section when no YouTube URL (private jobs + any other edge case)
|
||||
- [ ] When admin toggles a completed job to private, existing outputs are auto-deleted
|
||||
- [ ] Discord notifications still fire for private jobs
|
||||
- [ ] Existing (non-private) jobs are completely unaffected (backward compatible)
|
||||
|
||||
## Technical Approach
|
||||
|
||||
### Core Design: Single Boolean Flag with Runtime Overrides
|
||||
|
||||
Store `is_private: bool = False` on the job model. At distribution time, a helper function returns effective distribution parameters based on this flag. This means:
|
||||
|
||||
- **Toggling is_private automatically changes all distribution behavior** - no need to manually update dropbox_path, brand_prefix, enable_youtube_upload, gdrive_folder_id
|
||||
- **Job fields still store the "normal" defaults** - the override happens at the config-to-orchestrator boundary
|
||||
- **Admin can flip one field** and everything adapts
|
||||
|
||||
### Key Helper Function
|
||||
|
||||
```python
|
||||
# In job_defaults_service.py
|
||||
def get_effective_distribution_for_job(job) -> EffectiveDistributionSettings:
|
||||
"""Return distribution settings, applying private overrides if is_private=True."""
|
||||
if getattr(job, 'is_private', False):
|
||||
settings = get_settings()
|
||||
return EffectiveDistributionSettings(
|
||||
dropbox_path=settings.default_private_dropbox_path,
|
||||
brand_prefix=settings.default_private_brand_prefix,
|
||||
enable_youtube_upload=False,
|
||||
gdrive_folder_id=None,
|
||||
# Keep other settings from job (discord, youtube_description, etc.)
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
youtube_description=None,
|
||||
)
|
||||
# Non-private: return job's own settings
|
||||
return EffectiveDistributionSettings(
|
||||
dropbox_path=getattr(job, 'dropbox_path', None),
|
||||
brand_prefix=getattr(job, 'brand_prefix', None),
|
||||
enable_youtube_upload=getattr(job, 'enable_youtube_upload', False),
|
||||
gdrive_folder_id=getattr(job, 'gdrive_folder_id', None),
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
youtube_description=getattr(job, 'youtube_description_template', None),
|
||||
)
|
||||
```
|
||||
|
||||
This helper is used in both distribution paths (orchestrator and native fallback).
|
||||
|
||||
### Distribution Paths That Need Changes
|
||||
|
||||
Two code paths handle distribution (see LESSONS-LEARNED: "Fix Both Sides of Dual Code Paths"):
|
||||
|
||||
1. **Orchestrator path** (`video_worker_orchestrator.py`): Primary path. `create_orchestrator_config_from_job()` uses the helper to build config.
|
||||
2. **Native distribution path** (`video_worker.py` → `_handle_native_distribution()`): Fallback path. Also uses the helper instead of reading job fields directly.
|
||||
|
||||
### Email Template Change
|
||||
|
||||
Add conditional YouTube section removal in `render_template()`, matching the existing pattern for `feedback_url`:
|
||||
|
||||
```python
|
||||
# Remove YouTube section if no URL provided
|
||||
if not variables.get("youtube_url"):
|
||||
result = re.sub(
|
||||
r"\n*Here's the link for the karaoke video published to YouTube:\n\{youtube_url\}\n*",
|
||||
'\n',
|
||||
result,
|
||||
flags=re.DOTALL
|
||||
)
|
||||
variables["youtube_url"] = ""
|
||||
```
|
||||
|
||||
And change `render_job_completion()` to pass `None` instead of `"[YouTube URL not available]"` when youtube_url is empty.
|
||||
|
||||
### Admin Toggle Auto-Delete
|
||||
|
||||
When admin PATCH updates `is_private` from False to True on a job that has existing outputs, reuse the existing delete-outputs logic to remove YouTube + GDrive + Dropbox outputs. Admin can then "Reprocess" to re-distribute to the private Dropbox path.
|
||||
|
||||
## Implementation Steps
|
||||
|
||||
### Phase 1: Backend Model & Config (foundation)
|
||||
|
||||
1. [ ] **Add `is_private` to Job model** (`backend/models/job.py`)
|
||||
- Add `is_private: bool = False` field after `made_for_you` field
|
||||
- Add to `JobCreate` model as well
|
||||
|
||||
2. [ ] **Add private distribution config** (`backend/config.py`)
|
||||
- Add `default_private_dropbox_path: Optional[str] = os.getenv("DEFAULT_PRIVATE_DROPBOX_PATH")`
|
||||
- Add `default_private_brand_prefix: Optional[str] = os.getenv("DEFAULT_PRIVATE_BRAND_PREFIX", "NOMADNP")`
|
||||
|
||||
3. [ ] **Add helper function** (`backend/services/job_defaults_service.py`)
|
||||
- Add `get_effective_distribution_for_job(job)` function that returns distribution settings with private overrides applied
|
||||
|
||||
### Phase 2: Backend API (job creation + admin)
|
||||
|
||||
4. [ ] **Add `is_private` to request models** (`backend/models/requests.py`)
|
||||
- Add `is_private: Optional[bool] = None` to `URLSubmissionRequest`
|
||||
- Add `is_private: Optional[bool] = None` to `AudioSearchRequest`
|
||||
|
||||
5. [ ] **Update URL creation endpoint** (`backend/api/routes/jobs.py`)
|
||||
- Accept and pass through `is_private` field to `JobCreate`
|
||||
|
||||
6. [ ] **Update file upload endpoint** (`backend/api/routes/file_upload.py`)
|
||||
- Accept `is_private` Form parameter
|
||||
- Pass through to `JobCreate`
|
||||
|
||||
7. [ ] **Update audio search endpoint** (`backend/api/routes/audio_search.py`)
|
||||
- Accept `is_private` in `AudioSearchRequest`
|
||||
- Pass through to `JobCreate`
|
||||
|
||||
8. [ ] **Update admin endpoints** (`backend/api/routes/admin.py`)
|
||||
- Add `is_private: Optional[bool] = None` to `JobUpdateRequest`
|
||||
- Add `"is_private"` to `EDITABLE_JOB_FIELDS`
|
||||
- In the PATCH handler: detect when `is_private` changes from False→True on a completed job, auto-delete existing outputs (call existing delete-outputs service logic)
|
||||
|
||||
### Phase 3: Distribution Pipeline
|
||||
|
||||
9. [ ] **Update orchestrator config creation** (`backend/workers/video_worker_orchestrator.py`)
|
||||
- In `create_orchestrator_config_from_job()`: Use `get_effective_distribution_for_job()` helper to determine dropbox_path, brand_prefix, enable_youtube_upload, gdrive_folder_id instead of reading directly from job
|
||||
|
||||
10. [ ] **Update native distribution fallback** (`backend/workers/video_worker.py`)
|
||||
- In `_handle_native_distribution()`: Use `get_effective_distribution_for_job()` helper instead of reading directly from job fields
|
||||
|
||||
### Phase 4: Email Template
|
||||
|
||||
11. [ ] **Add YouTube section conditional removal** (`backend/services/template_service.py`)
|
||||
- In `render_template()`: Add regex to remove YouTube paragraph when `youtube_url` is empty (matching existing `feedback_url` pattern)
|
||||
- In `render_job_completion()`: Pass `None` for youtube_url when empty (instead of `"[YouTube URL not available]"`)
|
||||
|
||||
### Phase 5: Frontend
|
||||
|
||||
12. [ ] **Add private checkbox to job creation form** (`frontend/components/job/JobSubmission.tsx`)
|
||||
- Add "Private (Non-Published)" checkbox below the existing "Skip lyrics review" checkbox
|
||||
- Show for all users (not just admin)
|
||||
- Include brief description text: "Private tracks go to Dropbox only, not YouTube or Google Drive"
|
||||
|
||||
13. [ ] **Update API interfaces** (`frontend/lib/api.ts`)
|
||||
- Add `is_private?: boolean` to all job creation option interfaces
|
||||
- Add `is_private` to `JobUpdateRequest` interface
|
||||
- Pass through in `uploadJob()`, `createJobFromUrl()`, `searchAudio()` methods
|
||||
|
||||
14. [ ] **Add private toggle to admin job detail** (`frontend/app/admin/jobs/page.tsx`)
|
||||
- Add `is_private` as an inline-editable field in the job overview section (use Switch component)
|
||||
- Show current state with visual indicator (e.g., lock icon for private jobs)
|
||||
- When toggling to private on a completed job, show confirmation dialog about auto-deleting outputs
|
||||
|
||||
### Phase 6: Environment Configuration
|
||||
|
||||
15. [ ] **Update CI/deployment config** (`.github/workflows/ci.yml` or Cloud Run env)
|
||||
- Add `DEFAULT_PRIVATE_DROPBOX_PATH` environment variable (e.g., `/Karaoke/Tracks-NonPublished`)
|
||||
- Add `DEFAULT_PRIVATE_BRAND_PREFIX` environment variable (e.g., `NOMADNP`)
|
||||
- These should be configured in Cloud Run service and CI test environment
|
||||
|
||||
### Phase 7: Testing
|
||||
|
||||
16. [ ] **Unit tests for private distribution logic** (`backend/tests/test_private_tracks.py`)
|
||||
- Test `get_effective_distribution_for_job()` with private and non-private jobs
|
||||
- Test `create_orchestrator_config_from_job()` applies private overrides correctly
|
||||
- Test `_run_distribution()` skips YouTube and GDrive when private config applied
|
||||
- Test `_upload_to_dropbox()` uses private path and brand prefix
|
||||
- Test brand code generation with NOMADNP prefix in Tracks-NonPublished
|
||||
- Test `_handle_native_distribution()` respects private overrides
|
||||
- Test non-private jobs are completely unaffected (regression tests)
|
||||
|
||||
17. [ ] **Unit tests for email changes** (add to `backend/tests/test_email_service.py` or `test_template_service.py`)
|
||||
- Test YouTube section removed from email when youtube_url is None
|
||||
- Test YouTube section present when youtube_url is provided
|
||||
- Test Dropbox section still present for private jobs
|
||||
- Test full email rendering for private job scenario
|
||||
|
||||
18. [ ] **Unit tests for admin toggle** (add to `backend/tests/test_admin.py` or new file)
|
||||
- Test admin can update is_private field
|
||||
- Test toggling is_private to True on completed job triggers output deletion
|
||||
- Test toggling is_private to True on non-completed job does NOT delete outputs
|
||||
- Test toggling is_private to False does nothing special
|
||||
|
||||
19. [ ] **Integration test** (`backend/tests/emulator/` or `test_distribution_services.py`)
|
||||
- Test full distribution pipeline with is_private=True: verify Dropbox path, brand prefix, YouTube skip, GDrive skip
|
||||
|
||||
20. [ ] **Frontend E2E regression test** (`frontend/e2e/regression/`)
|
||||
- Test private checkbox appears in job creation form
|
||||
- Test private toggle in admin dashboard
|
||||
|
||||
## Files to Create/Modify
|
||||
|
||||
| File | Action | Description |
|
||||
|------|--------|-------------|
|
||||
| `backend/models/job.py` | Modify | Add `is_private: bool = False` to Job and JobCreate |
|
||||
| `backend/config.py` | Modify | Add `default_private_dropbox_path` and `default_private_brand_prefix` |
|
||||
| `backend/services/job_defaults_service.py` | Modify | Add `get_effective_distribution_for_job()` helper |
|
||||
| `backend/models/requests.py` | Modify | Add `is_private` to URL and AudioSearch request models |
|
||||
| `backend/api/routes/jobs.py` | Modify | Accept and pass `is_private` |
|
||||
| `backend/api/routes/file_upload.py` | Modify | Accept and pass `is_private` |
|
||||
| `backend/api/routes/audio_search.py` | Modify | Accept and pass `is_private` |
|
||||
| `backend/api/routes/admin.py` | Modify | Add `is_private` to editable fields + auto-delete logic |
|
||||
| `backend/workers/video_worker_orchestrator.py` | Modify | Use helper in `create_orchestrator_config_from_job()` |
|
||||
| `backend/workers/video_worker.py` | Modify | Use helper in `_handle_native_distribution()` |
|
||||
| `backend/services/template_service.py` | Modify | Conditional YouTube section removal |
|
||||
| `frontend/components/job/JobSubmission.tsx` | Modify | Add private checkbox |
|
||||
| `frontend/lib/api.ts` | Modify | Add `is_private` to interfaces and API calls |
|
||||
| `frontend/app/admin/jobs/page.tsx` | Modify | Add private toggle to admin detail |
|
||||
| `backend/tests/test_private_tracks.py` | Create | Comprehensive unit tests for private track logic |
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit Tests (~25-30 tests in `test_private_tracks.py`)
|
||||
- `get_effective_distribution_for_job()` with private=True and False
|
||||
- `create_orchestrator_config_from_job()` private overrides (YouTube=False, GDrive=None, private Dropbox path, NOMADNP brand)
|
||||
- Distribution stage skips: YouTube not called, GDrive not called, Dropbox IS called with correct path
|
||||
- Brand code generation uses NOMADNP prefix and Tracks-NonPublished path
|
||||
- Native distribution fallback applies same overrides
|
||||
- **Regression tests**: Non-private jobs have unchanged behavior (same paths, same brand code, YouTube+GDrive+Dropbox all fire)
|
||||
|
||||
### Email Template Tests (~5 tests)
|
||||
- YouTube section stripped when youtube_url is None
|
||||
- YouTube section preserved when youtube_url has value
|
||||
- Dropbox section always present
|
||||
- Full private job email rendering (Dropbox + no YouTube)
|
||||
- Full non-private job email rendering (both present) - regression
|
||||
|
||||
### Admin Toggle Tests (~5 tests)
|
||||
- is_private editable via PATCH
|
||||
- Toggle to private on completed job deletes outputs
|
||||
- Toggle to private on pending/in-progress job does NOT delete
|
||||
- Toggle to non-private does nothing special
|
||||
|
||||
### Frontend Tests
|
||||
- E2E: Private checkbox visible and functional in job creation
|
||||
- E2E: Admin toggle visible and includes confirmation dialog
|
||||
|
||||
### Manual Verification
|
||||
- Create a private job end-to-end, verify Dropbox folder in Tracks-NonPublished with NOMADNP code
|
||||
- Verify completion email has Dropbox link but no YouTube section
|
||||
- Toggle existing completed job to private, verify outputs deleted
|
||||
|
||||
## Regression Risk Analysis
|
||||
|
||||
| Risk | Mitigation |
|
||||
|------|-----------|
|
||||
| Non-private jobs affected | `is_private` defaults to `False`; helper returns unchanged values for non-private. Explicit regression tests. |
|
||||
| Dual code paths (orchestrator vs native) | Both paths use same helper function. Tests cover both paths. (Lesson: "Fix Both Sides of Dual Code Paths") |
|
||||
| Email template regex breaks other content | Regex targets specific YouTube paragraph text. Tests verify non-YouTube content untouched. |
|
||||
| Brand code namespace collision | NOMADNP codes are in a completely separate Dropbox folder (Tracks-NonPublished), no overlap with NOMAD codes in Tracks-Organized |
|
||||
| Admin auto-delete on wrong job | Only triggers when `is_private` changes from False→True AND job has terminal status (complete). Confirmation dialog in frontend. |
|
||||
| Made-for-you orders | MFY webhook doesn't set is_private (defaults False). Admin can toggle after. No change to MFY flow. |
|
||||
| Existing Firestore documents | Missing `is_private` field defaults to `False` via model default. No migration needed. |
|
||||
|
||||
## Open Questions
|
||||
|
||||
- [x] Who sees private toggle? → **Everyone** (all users at creation, admin on existing)
|
||||
- [x] Auto-delete on toggle? → **Yes**, auto-delete all outputs when toggling to private on completed job
|
||||
- [x] Email format? → **Remove YouTube section** when no YouTube URL (improves all edge cases)
|
||||
- [x] Discord? → **Still notify** (useful for internal tracking)
|
||||
|
||||
## Rollback Plan
|
||||
|
||||
1. **Feature flag**: The `is_private` field defaults to `False`, so setting `DEFAULT_PRIVATE_DROPBOX_PATH` to empty/None effectively disables private distribution
|
||||
2. **No schema migration needed**: Missing `is_private` field on existing Firestore documents defaults to `False`
|
||||
3. **Email change is backward-compatible**: The YouTube section removal only happens when youtube_url is None, which is already an edge case showing "[YouTube URL not available]"
|
||||
4. **Frontend**: Private checkbox is additive UI, removing it just means users can't create new private jobs
|
||||
@@ -1242,7 +1242,7 @@ jobs:
|
||||
--min-instances 4 \
|
||||
--vpc-connector projects/nomadkaraoke/locations/us-central1/connectors/cloud-run-connector \
|
||||
--vpc-egress private-ranges-only \
|
||||
--set-env-vars "GOOGLE_CLOUD_PROJECT=${{ env.PROJECT_ID }},GCS_BUCKET_NAME=karaoke-gen-storage-${{ env.PROJECT_ID }},FIRESTORE_COLLECTION=jobs,ENVIRONMENT=production,AUDIO_SEPARATOR_API_URL=https://nomadkaraoke--audio-separator-api.modal.run,KARAOKE_GEN_VERSION=$VERSION,DEFAULT_DROPBOX_PATH=/MediaUnsynced/Karaoke/Tracks-Organized,DEFAULT_GDRIVE_FOLDER_ID=1laRKAyxo0v817SstfM5XkpbWiNKNAMSX,ENABLE_CLOUD_TASKS=true,CLOUD_RUN_SERVICE_URL=https://api.nomadkaraoke.com,GCP_REGION=us-central1,DEFAULT_ENABLE_YOUTUBE_UPLOAD=true,DEFAULT_BRAND_PREFIX=NOMAD,USE_GCE_ENCODING=true,USE_GCE_PREVIEW_ENCODING=true,ENABLE_PUSH_NOTIFICATIONS=true" \
|
||||
--set-env-vars "GOOGLE_CLOUD_PROJECT=${{ env.PROJECT_ID }},GCS_BUCKET_NAME=karaoke-gen-storage-${{ env.PROJECT_ID }},FIRESTORE_COLLECTION=jobs,ENVIRONMENT=production,AUDIO_SEPARATOR_API_URL=https://nomadkaraoke--audio-separator-api.modal.run,KARAOKE_GEN_VERSION=$VERSION,DEFAULT_DROPBOX_PATH=/MediaUnsynced/Karaoke/Tracks-Organized,DEFAULT_GDRIVE_FOLDER_ID=1laRKAyxo0v817SstfM5XkpbWiNKNAMSX,ENABLE_CLOUD_TASKS=true,CLOUD_RUN_SERVICE_URL=https://api.nomadkaraoke.com,GCP_REGION=us-central1,DEFAULT_ENABLE_YOUTUBE_UPLOAD=true,DEFAULT_BRAND_PREFIX=NOMAD,DEFAULT_PRIVATE_DROPBOX_PATH=/MediaUnsynced/Karaoke/Tracks-NonPublished,DEFAULT_PRIVATE_BRAND_PREFIX=NOMADNP,USE_GCE_ENCODING=true,USE_GCE_PREVIEW_ENCODING=true,ENABLE_PUSH_NOTIFICATIONS=true" \
|
||||
--set-secrets "AUDIOSHAKE_API_TOKEN=audioshake-api-key:latest,GENIUS_API_TOKEN=genius-api-key:latest,SPOTIFY_COOKIE_SP_DC=spotify-cookie:latest,RAPIDAPI_KEY=rapidapi-key:latest,DEFAULT_DISCORD_WEBHOOK_URL=discord-releases-webhook:latest,ADMIN_TOKENS=admin-tokens:latest,RED_API_KEY=red-api-key:latest,RED_API_URL=red-api-url:latest,OPS_API_KEY=ops-api-key:latest,OPS_API_URL=ops-api-url:latest,FLACFETCH_API_URL=flacfetch-api-url:latest,FLACFETCH_API_KEY=flacfetch-api-key:latest,SENDGRID_API_KEY=sendgrid-api-key:latest,STRIPE_SECRET_KEY=stripe-secret-key:latest,STRIPE_WEBHOOK_SECRET=stripe-webhook-secret:latest,LANGFUSE_PUBLIC_KEY=langfuse-public-key:latest,LANGFUSE_SECRET_KEY=langfuse-secret-key:latest,LANGFUSE_HOST=langfuse-host:latest,ENCODING_WORKER_URL=encoding-worker-url:latest,ENCODING_WORKER_API_KEY=encoding-worker-api-key:latest,VAPID_PUBLIC_KEY=vapid-public-key:latest,VAPID_PRIVATE_KEY=vapid-private-key:latest,E2E_BYPASS_KEY=e2e-bypass-key:latest"
|
||||
|
||||
- name: Verify deployment and version
|
||||
|
||||
@@ -96,6 +96,7 @@ class JobUpdateRequest(BaseModel):
|
||||
enable_youtube_upload: Optional[bool] = None
|
||||
non_interactive: Optional[bool] = None
|
||||
prep_only: Optional[bool] = None
|
||||
is_private: Optional[bool] = None
|
||||
|
||||
|
||||
class JobUpdateResponse(BaseModel):
|
||||
@@ -123,6 +124,7 @@ EDITABLE_JOB_FIELDS = {
|
||||
"enable_youtube_upload",
|
||||
"non_interactive",
|
||||
"prep_only",
|
||||
"is_private",
|
||||
}
|
||||
|
||||
|
||||
@@ -912,6 +914,7 @@ async def update_job(
|
||||
- customer_email, customer_notes: Made-for-you order info
|
||||
- brand_prefix: Brand code prefix
|
||||
- non_interactive, prep_only: Workflow options
|
||||
- is_private: Private (non-published) track mode
|
||||
- discord_webhook_url: Notification URL
|
||||
- youtube_description, youtube_description_template: YouTube settings
|
||||
|
||||
@@ -950,6 +953,14 @@ async def update_job(
|
||||
if not job:
|
||||
raise HTTPException(status_code=404, detail=f"Job {job_id} not found")
|
||||
|
||||
# Check if we're toggling is_private from False to True on a completed job
|
||||
# If so, auto-delete existing outputs (YouTube, Dropbox, GDrive)
|
||||
toggling_to_private = (
|
||||
"is_private" in updates
|
||||
and updates["is_private"] is True
|
||||
and not getattr(job, 'is_private', False)
|
||||
)
|
||||
|
||||
# Perform the update
|
||||
success = job_manager.update_job(job_id, updates)
|
||||
|
||||
@@ -959,17 +970,46 @@ async def update_job(
|
||||
detail="Failed to update job. Please try again."
|
||||
)
|
||||
|
||||
# Auto-delete outputs when toggling to private on a job with existing outputs
|
||||
auto_deleted = False
|
||||
if toggling_to_private and job.status in TERMINAL_STATES and not job.outputs_deleted_at:
|
||||
state_data = job.state_data or {}
|
||||
has_outputs = (
|
||||
state_data.get('youtube_url')
|
||||
or state_data.get('dropbox_link')
|
||||
or state_data.get('gdrive_files')
|
||||
)
|
||||
if has_outputs:
|
||||
try:
|
||||
logger.info(
|
||||
f"Auto-deleting outputs for job {job_id} (toggled to private by {admin_email})"
|
||||
)
|
||||
# Call the delete-outputs endpoint directly (same module)
|
||||
await delete_job_outputs(job_id, auth_data)
|
||||
auto_deleted = True
|
||||
except HTTPException:
|
||||
# delete_job_outputs raises HTTPException on validation failures,
|
||||
# but we've already validated terminal state + not-already-deleted
|
||||
logger.warning(f"Auto-delete outputs skipped for job {job_id} (validation)")
|
||||
except Exception as e:
|
||||
logger.warning(f"Auto-delete outputs failed for job {job_id}: {e}")
|
||||
|
||||
# Log the admin action
|
||||
logger.info(
|
||||
f"Admin {admin_email} updated job {job_id}. "
|
||||
f"Updated fields: {list(updates.keys())}"
|
||||
f"{' (outputs auto-deleted)' if auto_deleted else ''}"
|
||||
)
|
||||
|
||||
message = f"Successfully updated {len(updates)} field(s)"
|
||||
if auto_deleted:
|
||||
message += ". Existing outputs were auto-deleted (job set to private)."
|
||||
|
||||
return JobUpdateResponse(
|
||||
status="success",
|
||||
job_id=job_id,
|
||||
updated_fields=list(updates.keys()),
|
||||
message=f"Successfully updated {len(updates)} field(s)",
|
||||
message=message,
|
||||
)
|
||||
|
||||
|
||||
@@ -1754,6 +1794,7 @@ async def get_job_completion_message(
|
||||
title=job.title,
|
||||
youtube_url=youtube_url,
|
||||
dropbox_url=dropbox_url,
|
||||
is_private=getattr(job, 'is_private', False),
|
||||
)
|
||||
|
||||
# Build subject: "NOMAD-1178: Artist - Title (Your karaoke video is ready!)"
|
||||
@@ -1818,6 +1859,7 @@ async def send_job_completion_email(
|
||||
title=job.title,
|
||||
youtube_url=youtube_url,
|
||||
dropbox_url=dropbox_url,
|
||||
is_private=getattr(job, 'is_private', False),
|
||||
)
|
||||
|
||||
# Send the email
|
||||
|
||||
@@ -134,6 +134,9 @@ class AudioSearchRequest(BaseModel):
|
||||
# Non-interactive mode
|
||||
non_interactive: bool = Field(False, description="Skip interactive steps (lyrics review, instrumental selection)")
|
||||
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = Field(False, description="Private track: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive")
|
||||
|
||||
@validator('artist', 'title', 'lyrics_artist', 'lyrics_title', 'display_artist', 'display_title')
|
||||
def normalize_text_fields(cls, v):
|
||||
"""Normalize text fields to standardize Unicode characters."""
|
||||
@@ -621,6 +624,7 @@ async def search_audio(
|
||||
auto_download=body.auto_download,
|
||||
request_metadata=request_metadata,
|
||||
non_interactive=body.non_interactive,
|
||||
is_private=body.is_private,
|
||||
# Tenant scoping
|
||||
tenant_id=tenant_config.id if tenant_config else None,
|
||||
)
|
||||
|
||||
@@ -111,6 +111,9 @@ class CreateJobFromUrlRequest(BaseModel):
|
||||
# Non-interactive mode
|
||||
non_interactive: bool = Field(False, description="Skip interactive steps (lyrics review, instrumental selection)")
|
||||
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = Field(False, description="Private track: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive")
|
||||
|
||||
|
||||
class CreateJobFromUrlResponse(BaseModel):
|
||||
"""Response from creating a job from URL."""
|
||||
@@ -172,6 +175,9 @@ class CreateJobWithUploadUrlsRequest(BaseModel):
|
||||
# Non-interactive mode
|
||||
non_interactive: bool = Field(False, description="Skip interactive steps (lyrics review, instrumental selection)")
|
||||
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = Field(False, description="Private track: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive")
|
||||
|
||||
|
||||
class SignedUploadUrl(BaseModel):
|
||||
"""Signed URL for uploading a file."""
|
||||
@@ -361,6 +367,8 @@ async def upload_and_create_job(
|
||||
other_stems_models: Optional[str] = Form(None, description="Comma-separated list of models for other stems (bass, drums, guitar, etc.)"),
|
||||
# Non-interactive mode
|
||||
non_interactive: bool = Form(False, description="Skip interactive steps (lyrics review, instrumental selection)"),
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = Form(False, description="Private track: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive"),
|
||||
):
|
||||
"""
|
||||
Upload an audio file and create a karaoke generation job with full style configuration.
|
||||
@@ -461,10 +469,11 @@ async def upload_and_create_job(
|
||||
|
||||
# Validate credentials for requested distribution services (including defaults)
|
||||
# This prevents accepting jobs that will fail later due to missing credentials
|
||||
# Skip YouTube/GDrive checks for private jobs (they won't use those services)
|
||||
invalid_services = []
|
||||
credential_manager = get_credential_manager()
|
||||
|
||||
if effective_enable_youtube_upload:
|
||||
if effective_enable_youtube_upload and not is_private:
|
||||
result = credential_manager.check_youtube_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"youtube ({result.message})")
|
||||
@@ -474,7 +483,7 @@ async def upload_and_create_job(
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"dropbox ({result.message})")
|
||||
|
||||
if dist.gdrive_folder_id:
|
||||
if dist.gdrive_folder_id and not is_private:
|
||||
result = credential_manager.check_gdrive_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"gdrive ({result.message})")
|
||||
@@ -574,6 +583,8 @@ async def upload_and_create_job(
|
||||
request_metadata=request_metadata,
|
||||
# Non-interactive mode
|
||||
non_interactive=non_interactive,
|
||||
# Private (non-published) track mode
|
||||
is_private=is_private,
|
||||
# Tenant scoping
|
||||
tenant_id=tenant_config.id if tenant_config else None,
|
||||
)
|
||||
@@ -876,6 +887,8 @@ class CreateFinaliseOnlyJobRequest(BaseModel):
|
||||
dropbox_path: Optional[str] = Field(None, description="Dropbox folder path for organized output")
|
||||
gdrive_folder_id: Optional[str] = Field(None, description="Google Drive folder ID for public share uploads")
|
||||
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = Field(False, description="Private track: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive")
|
||||
|
||||
|
||||
|
||||
@@ -1022,10 +1035,11 @@ async def create_job_with_upload_urls(
|
||||
effective_enable_youtube_upload = body.enable_youtube_upload if body.enable_youtube_upload is not None else settings.default_enable_youtube_upload
|
||||
|
||||
# Validate credentials for requested distribution services
|
||||
# Skip YouTube/GDrive checks for private jobs (they won't use those services)
|
||||
invalid_services = []
|
||||
credential_manager = get_credential_manager()
|
||||
|
||||
if effective_enable_youtube_upload:
|
||||
if effective_enable_youtube_upload and not body.is_private:
|
||||
result = credential_manager.check_youtube_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"youtube ({result.message})")
|
||||
@@ -1035,7 +1049,7 @@ async def create_job_with_upload_urls(
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"dropbox ({result.message})")
|
||||
|
||||
if dist.gdrive_folder_id:
|
||||
if dist.gdrive_folder_id and not body.is_private:
|
||||
result = credential_manager.check_gdrive_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"gdrive ({result.message})")
|
||||
@@ -1104,6 +1118,7 @@ async def create_job_with_upload_urls(
|
||||
other_stems_models=body.other_stems_models,
|
||||
request_metadata=request_metadata,
|
||||
non_interactive=body.non_interactive,
|
||||
is_private=body.is_private,
|
||||
# Tenant scoping
|
||||
tenant_id=tenant_config.id if tenant_config else None,
|
||||
)
|
||||
@@ -1464,10 +1479,11 @@ async def create_job_from_url(
|
||||
effective_enable_youtube_upload = body.enable_youtube_upload if body.enable_youtube_upload is not None else settings.default_enable_youtube_upload
|
||||
|
||||
# Validate credentials for requested distribution services
|
||||
# Skip YouTube/GDrive checks for private jobs (they won't use those services)
|
||||
invalid_services = []
|
||||
credential_manager = get_credential_manager()
|
||||
|
||||
if effective_enable_youtube_upload:
|
||||
if effective_enable_youtube_upload and not body.is_private:
|
||||
result = credential_manager.check_youtube_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"youtube ({result.message})")
|
||||
@@ -1477,7 +1493,7 @@ async def create_job_from_url(
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"dropbox ({result.message})")
|
||||
|
||||
if dist.gdrive_folder_id:
|
||||
if dist.gdrive_folder_id and not body.is_private:
|
||||
result = credential_manager.check_gdrive_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"gdrive ({result.message})")
|
||||
@@ -1544,6 +1560,7 @@ async def create_job_from_url(
|
||||
other_stems_models=body.other_stems_models,
|
||||
request_metadata=request_metadata,
|
||||
non_interactive=body.non_interactive,
|
||||
is_private=body.is_private,
|
||||
# Tenant scoping
|
||||
tenant_id=tenant_config.id if tenant_config else None,
|
||||
)
|
||||
@@ -1771,10 +1788,11 @@ async def create_finalise_only_job(
|
||||
effective_enable_youtube_upload = body.enable_youtube_upload if body.enable_youtube_upload is not None else settings.default_enable_youtube_upload
|
||||
|
||||
# Validate distribution credentials if services are requested
|
||||
# Skip YouTube/GDrive checks for private jobs (they won't use those services)
|
||||
invalid_services = []
|
||||
credential_manager = get_credential_manager()
|
||||
|
||||
if effective_enable_youtube_upload:
|
||||
if effective_enable_youtube_upload and not body.is_private:
|
||||
result = credential_manager.check_youtube_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"youtube ({result.message})")
|
||||
@@ -1784,7 +1802,7 @@ async def create_finalise_only_job(
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"dropbox ({result.message})")
|
||||
|
||||
if dist.gdrive_folder_id:
|
||||
if dist.gdrive_folder_id and not body.is_private:
|
||||
result = credential_manager.check_gdrive_credentials()
|
||||
if result.status != CredentialStatus.VALID:
|
||||
invalid_services.append(f"gdrive ({result.message})")
|
||||
@@ -1842,6 +1860,7 @@ async def create_finalise_only_job(
|
||||
finalise_only=True,
|
||||
keep_brand_code=body.keep_brand_code,
|
||||
request_metadata=request_metadata,
|
||||
is_private=body.is_private,
|
||||
# Tenant scoping
|
||||
tenant_id=tenant_config.id if tenant_config else None,
|
||||
)
|
||||
|
||||
@@ -116,7 +116,8 @@ async def create_job(
|
||||
enable_youtube_upload=effective_enable_youtube_upload,
|
||||
youtube_description=request.youtube_description,
|
||||
webhook_url=request.webhook_url,
|
||||
user_email=user_email
|
||||
user_email=user_email,
|
||||
is_private=request.is_private or False,
|
||||
)
|
||||
job = job_manager.create_job(job_create, is_admin=auth_result.is_admin)
|
||||
|
||||
|
||||
@@ -116,6 +116,10 @@ class Settings(BaseSettings):
|
||||
default_enable_youtube_upload: bool = os.getenv("DEFAULT_ENABLE_YOUTUBE_UPLOAD", "false").lower() in ("true", "1", "yes")
|
||||
default_brand_prefix: Optional[str] = os.getenv("DEFAULT_BRAND_PREFIX")
|
||||
|
||||
# Private (non-published) track distribution settings
|
||||
default_private_dropbox_path: Optional[str] = os.getenv("DEFAULT_PRIVATE_DROPBOX_PATH")
|
||||
default_private_brand_prefix: Optional[str] = os.getenv("DEFAULT_PRIVATE_BRAND_PREFIX", "NOMADNP")
|
||||
|
||||
# Rate Limiting Configuration
|
||||
# Enable/disable rate limiting system-wide (useful for development)
|
||||
enable_rate_limiting: bool = os.getenv("ENABLE_RATE_LIMITING", "true").lower() in ("true", "1", "yes")
|
||||
|
||||
@@ -299,6 +299,9 @@ class Job(BaseModel):
|
||||
customer_email: Optional[str] = None # Customer email for final delivery (job owned by admin during processing)
|
||||
customer_notes: Optional[str] = None # Notes provided by customer with their order
|
||||
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = False # Private tracks: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive
|
||||
|
||||
# Output deletion tracking (for admin cleanup without deleting job)
|
||||
outputs_deleted_at: Optional[datetime] = None # Timestamp when outputs were deleted by admin
|
||||
outputs_deleted_by: Optional[str] = None # Admin email who deleted outputs
|
||||
@@ -506,6 +509,9 @@ class JobCreate(BaseModel):
|
||||
customer_email: Optional[str] = None # Customer email for final delivery (job owned by admin during processing)
|
||||
customer_notes: Optional[str] = None # Notes provided by customer with their order
|
||||
|
||||
# Private (non-published) track mode
|
||||
is_private: bool = False # Private tracks: Dropbox only (Tracks-NonPublished/NOMADNP), no YouTube/GDrive
|
||||
|
||||
# Request metadata (set by API endpoint from request headers)
|
||||
request_metadata: Dict[str, Any] = Field(default_factory=dict)
|
||||
"""
|
||||
|
||||
@@ -10,7 +10,7 @@ class URLSubmissionRequest(BaseModel):
|
||||
url: HttpUrl
|
||||
artist: Optional[str] = None # Auto-detected if not provided
|
||||
title: Optional[str] = None # Auto-detected if not provided
|
||||
|
||||
|
||||
# Optional preferences
|
||||
enable_cdg: bool = False # Requires style config
|
||||
enable_txt: bool = False # Requires style config
|
||||
@@ -18,6 +18,7 @@ class URLSubmissionRequest(BaseModel):
|
||||
youtube_description: Optional[str] = None
|
||||
webhook_url: Optional[str] = None
|
||||
user_email: Optional[str] = None
|
||||
is_private: Optional[bool] = None # Private (non-published) track mode
|
||||
|
||||
|
||||
class UploadSubmissionRequest(BaseModel):
|
||||
|
||||
@@ -61,6 +61,45 @@ def get_effective_distribution_settings(
|
||||
)
|
||||
|
||||
|
||||
def get_effective_distribution_for_job(job) -> EffectiveDistributionSettings:
|
||||
"""
|
||||
Get effective distribution settings for a job, applying private overrides if is_private=True.
|
||||
|
||||
For private (non-published) jobs, this overrides:
|
||||
- dropbox_path → private Dropbox path (Tracks-NonPublished)
|
||||
- brand_prefix → private brand prefix (NOMADNP)
|
||||
- enable_youtube_upload → False (no YouTube for private)
|
||||
- gdrive_folder_id → None (no Google Drive for private)
|
||||
|
||||
For non-private jobs, returns the job's own distribution settings unchanged.
|
||||
|
||||
Args:
|
||||
job: Job object (or any object with distribution fields)
|
||||
|
||||
Returns:
|
||||
EffectiveDistributionSettings with private overrides applied if needed
|
||||
"""
|
||||
if getattr(job, 'is_private', False):
|
||||
settings = get_settings()
|
||||
return EffectiveDistributionSettings(
|
||||
dropbox_path=settings.default_private_dropbox_path,
|
||||
brand_prefix=settings.default_private_brand_prefix,
|
||||
enable_youtube_upload=False,
|
||||
gdrive_folder_id=None,
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
youtube_description=None,
|
||||
)
|
||||
# Non-private: return job's own settings
|
||||
return EffectiveDistributionSettings(
|
||||
dropbox_path=getattr(job, 'dropbox_path', None),
|
||||
brand_prefix=getattr(job, 'brand_prefix', None),
|
||||
enable_youtube_upload=getattr(job, 'enable_youtube_upload', False),
|
||||
gdrive_folder_id=getattr(job, 'gdrive_folder_id', None),
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
youtube_description=getattr(job, 'youtube_description_template', None),
|
||||
)
|
||||
|
||||
|
||||
def resolve_cdg_txt_defaults(
|
||||
theme_id: Optional[str],
|
||||
enable_cdg: Optional[bool] = None,
|
||||
|
||||
@@ -557,6 +557,7 @@ class JobManager:
|
||||
youtube_url=youtube_url,
|
||||
dropbox_url=dropbox_url,
|
||||
brand_code=brand_code,
|
||||
is_private=getattr(job, 'is_private', False),
|
||||
)
|
||||
|
||||
# Try to get existing event loop, create new one if none exists
|
||||
|
||||
@@ -71,6 +71,7 @@ class JobNotificationService:
|
||||
youtube_url: Optional[str] = None,
|
||||
dropbox_url: Optional[str] = None,
|
||||
brand_code: Optional[str] = None,
|
||||
is_private: bool = False,
|
||||
) -> bool:
|
||||
"""
|
||||
Send job completion email to user.
|
||||
@@ -84,6 +85,7 @@ class JobNotificationService:
|
||||
youtube_url: YouTube video URL
|
||||
dropbox_url: Dropbox folder URL
|
||||
brand_code: Release ID (e.g., "NOMAD-1178")
|
||||
is_private: If True, omit YouTube section (private/non-published tracks)
|
||||
|
||||
Returns:
|
||||
True if email was sent successfully
|
||||
@@ -106,6 +108,7 @@ class JobNotificationService:
|
||||
title=title,
|
||||
job_id=job_id,
|
||||
feedback_url=FEEDBACK_FORM_URL,
|
||||
is_private=is_private,
|
||||
)
|
||||
|
||||
# Send the email with CC to admin
|
||||
@@ -218,6 +221,7 @@ class JobNotificationService:
|
||||
title: Optional[str] = None,
|
||||
youtube_url: Optional[str] = None,
|
||||
dropbox_url: Optional[str] = None,
|
||||
is_private: bool = False,
|
||||
) -> str:
|
||||
"""
|
||||
Get the rendered completion message for a job (for admin copy functionality).
|
||||
@@ -229,6 +233,7 @@ class JobNotificationService:
|
||||
title: Song title
|
||||
youtube_url: YouTube video URL
|
||||
dropbox_url: Dropbox folder URL
|
||||
is_private: If True, omit YouTube section (private/non-published tracks)
|
||||
|
||||
Returns:
|
||||
Rendered message content as plain text
|
||||
@@ -241,6 +246,7 @@ class JobNotificationService:
|
||||
title=title,
|
||||
job_id=job_id,
|
||||
feedback_url=FEEDBACK_FORM_URL,
|
||||
is_private=is_private,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -212,6 +212,7 @@ class TemplateService:
|
||||
title: Optional[str] = None,
|
||||
job_id: Optional[str] = None,
|
||||
feedback_url: Optional[str] = None,
|
||||
is_private: bool = False,
|
||||
) -> str:
|
||||
"""
|
||||
Render the job completion email template.
|
||||
@@ -224,11 +225,21 @@ class TemplateService:
|
||||
title: Song title
|
||||
job_id: Job ID
|
||||
feedback_url: Feedback form URL (optional)
|
||||
is_private: If True, remove YouTube section entirely (private/non-published tracks)
|
||||
|
||||
Returns:
|
||||
Rendered email content
|
||||
"""
|
||||
template = self.get_job_completion_template()
|
||||
|
||||
# For private tracks, remove the YouTube section entirely
|
||||
if is_private:
|
||||
template = re.sub(
|
||||
r"\n*Here's the link for the karaoke video published to YouTube:\n\{youtube_url\}\n*",
|
||||
'\n',
|
||||
template,
|
||||
)
|
||||
|
||||
variables = {
|
||||
"name": name or "there",
|
||||
"youtube_url": youtube_url or "[YouTube URL not available]",
|
||||
|
||||
@@ -777,21 +777,22 @@ class TestVideoWorkerDistribution:
|
||||
async def test_handle_native_distribution_dropbox_not_configured(self):
|
||||
"""Test Dropbox upload skipped when service not configured."""
|
||||
from backend.workers.video_worker import _handle_native_distribution
|
||||
|
||||
|
||||
mock_job = MagicMock()
|
||||
mock_job.dropbox_path = "/test/path"
|
||||
mock_job.brand_prefix = "TEST"
|
||||
mock_job.gdrive_folder_id = None
|
||||
mock_job.is_private = False
|
||||
mock_job.artist = "Test"
|
||||
mock_job.title = "Song"
|
||||
mock_job.state_data = {}
|
||||
|
||||
|
||||
mock_job_log = MagicMock()
|
||||
mock_job_manager = MagicMock()
|
||||
|
||||
|
||||
mock_dropbox = MagicMock()
|
||||
mock_dropbox.is_configured = False
|
||||
|
||||
|
||||
with patch('backend.services.dropbox_service.get_dropbox_service', return_value=mock_dropbox):
|
||||
await _handle_native_distribution(
|
||||
job_id="test-123",
|
||||
@@ -801,7 +802,7 @@ class TestVideoWorkerDistribution:
|
||||
temp_dir="/tmp/test",
|
||||
result={},
|
||||
)
|
||||
|
||||
|
||||
# Should log warning about not configured
|
||||
mock_job_log.warning.assert_called()
|
||||
|
||||
@@ -809,21 +810,22 @@ class TestVideoWorkerDistribution:
|
||||
async def test_handle_native_distribution_gdrive_not_configured(self):
|
||||
"""Test Google Drive upload skipped when service not configured."""
|
||||
from backend.workers.video_worker import _handle_native_distribution
|
||||
|
||||
|
||||
mock_job = MagicMock()
|
||||
mock_job.dropbox_path = None
|
||||
mock_job.brand_prefix = None
|
||||
mock_job.gdrive_folder_id = "test_folder_id"
|
||||
mock_job.is_private = False
|
||||
mock_job.artist = "Test"
|
||||
mock_job.title = "Song"
|
||||
mock_job.state_data = {}
|
||||
|
||||
|
||||
mock_job_log = MagicMock()
|
||||
mock_job_manager = MagicMock()
|
||||
|
||||
|
||||
mock_gdrive = MagicMock()
|
||||
mock_gdrive.is_configured = False
|
||||
|
||||
|
||||
with patch('backend.services.gdrive_service.get_gdrive_service', return_value=mock_gdrive):
|
||||
await _handle_native_distribution(
|
||||
job_id="test-123",
|
||||
@@ -833,7 +835,7 @@ class TestVideoWorkerDistribution:
|
||||
temp_dir="/tmp/test",
|
||||
result={},
|
||||
)
|
||||
|
||||
|
||||
# Should log warning about not configured
|
||||
mock_job_log.warning.assert_called()
|
||||
|
||||
@@ -841,18 +843,19 @@ class TestVideoWorkerDistribution:
|
||||
async def test_handle_native_distribution_handles_import_error(self):
|
||||
"""Test that import errors for services are handled gracefully."""
|
||||
from backend.workers.video_worker import _handle_native_distribution
|
||||
|
||||
|
||||
mock_job = MagicMock()
|
||||
mock_job.dropbox_path = "/test/path"
|
||||
mock_job.brand_prefix = "TEST"
|
||||
mock_job.gdrive_folder_id = None
|
||||
mock_job.is_private = False
|
||||
mock_job.artist = "Test"
|
||||
mock_job.title = "Song"
|
||||
mock_job.state_data = {}
|
||||
|
||||
|
||||
mock_job_log = MagicMock()
|
||||
mock_job_manager = MagicMock()
|
||||
|
||||
|
||||
# Simulate import error
|
||||
with patch('backend.services.dropbox_service.get_dropbox_service', side_effect=ImportError("No module")):
|
||||
await _handle_native_distribution(
|
||||
@@ -863,6 +866,6 @@ class TestVideoWorkerDistribution:
|
||||
temp_dir="/tmp/test",
|
||||
result={},
|
||||
)
|
||||
|
||||
|
||||
# Should log warning about import error
|
||||
mock_job_log.warning.assert_called()
|
||||
@@ -0,0 +1,379 @@
|
||||
"""
|
||||
Tests for private (non-published) tracks feature.
|
||||
|
||||
Tests cover:
|
||||
- Job model is_private field
|
||||
- Distribution settings overrides for private jobs
|
||||
- Email template YouTube section removal
|
||||
- Admin toggle with auto-delete behavior
|
||||
"""
|
||||
import pytest
|
||||
from datetime import datetime
|
||||
from unittest.mock import Mock, patch, MagicMock
|
||||
from types import SimpleNamespace
|
||||
|
||||
from backend.models.job import Job, JobCreate
|
||||
from backend.services.job_defaults_service import (
|
||||
get_effective_distribution_for_job,
|
||||
EffectiveDistributionSettings,
|
||||
)
|
||||
from backend.services.template_service import TemplateService
|
||||
|
||||
|
||||
class TestJobModelIsPrivate:
|
||||
"""Tests for is_private field on Job and JobCreate models."""
|
||||
|
||||
def test_job_defaults_to_not_private(self):
|
||||
"""Job.is_private defaults to False."""
|
||||
now = datetime.utcnow().isoformat()
|
||||
job = Job(job_id="test-123", status="pending", created_at=now, updated_at=now)
|
||||
assert job.is_private is False
|
||||
|
||||
def test_job_can_be_created_as_private(self):
|
||||
"""Job can be explicitly set as private."""
|
||||
now = datetime.utcnow().isoformat()
|
||||
job = Job(job_id="test-123", status="pending", is_private=True, created_at=now, updated_at=now)
|
||||
assert job.is_private is True
|
||||
|
||||
def test_job_create_defaults_to_not_private(self):
|
||||
"""JobCreate.is_private defaults to False."""
|
||||
job_create = JobCreate(artist="Test", title="Song")
|
||||
assert job_create.is_private is False
|
||||
|
||||
def test_job_create_can_be_private(self):
|
||||
"""JobCreate can be explicitly set as private."""
|
||||
job_create = JobCreate(artist="Test", title="Song", is_private=True)
|
||||
assert job_create.is_private is True
|
||||
|
||||
|
||||
class TestGetEffectiveDistributionForJob:
|
||||
"""Tests for get_effective_distribution_for_job() helper."""
|
||||
|
||||
@patch('backend.services.job_defaults_service.get_settings')
|
||||
def test_private_job_uses_private_dropbox_path(self, mock_settings):
|
||||
"""Private job should use the private Dropbox path."""
|
||||
mock_settings.return_value = SimpleNamespace(
|
||||
default_private_dropbox_path="/Tracks-NonPublished",
|
||||
default_private_brand_prefix="NOMADNP",
|
||||
)
|
||||
job = SimpleNamespace(
|
||||
is_private=True,
|
||||
dropbox_path="/Tracks-Organized",
|
||||
brand_prefix="NOMAD",
|
||||
enable_youtube_upload=True,
|
||||
gdrive_folder_id="some-folder-id",
|
||||
discord_webhook_url="https://discord.com/hook",
|
||||
youtube_description_template="template",
|
||||
)
|
||||
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
assert dist.dropbox_path == "/Tracks-NonPublished"
|
||||
assert dist.brand_prefix == "NOMADNP"
|
||||
|
||||
@patch('backend.services.job_defaults_service.get_settings')
|
||||
def test_private_job_disables_youtube(self, mock_settings):
|
||||
"""Private job should have YouTube upload disabled."""
|
||||
mock_settings.return_value = SimpleNamespace(
|
||||
default_private_dropbox_path="/Tracks-NonPublished",
|
||||
default_private_brand_prefix="NOMADNP",
|
||||
)
|
||||
job = SimpleNamespace(
|
||||
is_private=True,
|
||||
enable_youtube_upload=True,
|
||||
discord_webhook_url=None,
|
||||
)
|
||||
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
assert dist.enable_youtube_upload is False
|
||||
assert dist.youtube_description is None
|
||||
|
||||
@patch('backend.services.job_defaults_service.get_settings')
|
||||
def test_private_job_disables_gdrive(self, mock_settings):
|
||||
"""Private job should have Google Drive folder ID set to None."""
|
||||
mock_settings.return_value = SimpleNamespace(
|
||||
default_private_dropbox_path="/Tracks-NonPublished",
|
||||
default_private_brand_prefix="NOMADNP",
|
||||
)
|
||||
job = SimpleNamespace(
|
||||
is_private=True,
|
||||
gdrive_folder_id="some-folder-id",
|
||||
discord_webhook_url=None,
|
||||
)
|
||||
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
assert dist.gdrive_folder_id is None
|
||||
|
||||
@patch('backend.services.job_defaults_service.get_settings')
|
||||
def test_private_job_preserves_discord(self, mock_settings):
|
||||
"""Private job should still have Discord webhook preserved."""
|
||||
mock_settings.return_value = SimpleNamespace(
|
||||
default_private_dropbox_path="/Tracks-NonPublished",
|
||||
default_private_brand_prefix="NOMADNP",
|
||||
)
|
||||
job = SimpleNamespace(
|
||||
is_private=True,
|
||||
discord_webhook_url="https://discord.com/webhook/123",
|
||||
)
|
||||
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
assert dist.discord_webhook_url == "https://discord.com/webhook/123"
|
||||
|
||||
def test_non_private_job_uses_job_settings(self):
|
||||
"""Non-private job should use its own distribution settings."""
|
||||
job = SimpleNamespace(
|
||||
is_private=False,
|
||||
dropbox_path="/Tracks-Organized",
|
||||
brand_prefix="NOMAD",
|
||||
enable_youtube_upload=True,
|
||||
gdrive_folder_id="folder-id",
|
||||
discord_webhook_url="https://discord.com/hook",
|
||||
youtube_description_template="description",
|
||||
)
|
||||
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
assert dist.dropbox_path == "/Tracks-Organized"
|
||||
assert dist.brand_prefix == "NOMAD"
|
||||
assert dist.enable_youtube_upload is True
|
||||
assert dist.gdrive_folder_id == "folder-id"
|
||||
assert dist.discord_webhook_url == "https://discord.com/hook"
|
||||
assert dist.youtube_description == "description"
|
||||
|
||||
def test_job_without_is_private_treated_as_non_private(self):
|
||||
"""Job object without is_private attribute should be treated as non-private."""
|
||||
job = SimpleNamespace(
|
||||
dropbox_path="/Tracks-Organized",
|
||||
brand_prefix="NOMAD",
|
||||
enable_youtube_upload=False,
|
||||
gdrive_folder_id=None,
|
||||
discord_webhook_url=None,
|
||||
youtube_description_template=None,
|
||||
)
|
||||
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
assert dist.dropbox_path == "/Tracks-Organized"
|
||||
assert dist.brand_prefix == "NOMAD"
|
||||
assert dist.enable_youtube_upload is False
|
||||
|
||||
|
||||
class TestTemplateServicePrivate:
|
||||
"""Tests for email template rendering with is_private flag."""
|
||||
|
||||
def test_private_job_removes_youtube_section(self):
|
||||
"""Private job completion email should not contain YouTube section."""
|
||||
service = TemplateService()
|
||||
service._storage_client = Mock()
|
||||
service._bucket = Mock()
|
||||
# Force use of default template
|
||||
service._bucket.blob.return_value.exists.return_value = False
|
||||
|
||||
result = service.render_job_completion(
|
||||
name="Test User",
|
||||
youtube_url=None,
|
||||
dropbox_url="https://dropbox.com/link",
|
||||
artist="Artist",
|
||||
title="Song",
|
||||
job_id="job-123",
|
||||
is_private=True,
|
||||
)
|
||||
|
||||
assert "YouTube" not in result
|
||||
assert "youtube_url" not in result
|
||||
assert "https://dropbox.com/link" in result
|
||||
|
||||
def test_non_private_job_includes_youtube_section(self):
|
||||
"""Non-private job completion email should include YouTube section."""
|
||||
service = TemplateService()
|
||||
service._storage_client = Mock()
|
||||
service._bucket = Mock()
|
||||
service._bucket.blob.return_value.exists.return_value = False
|
||||
|
||||
result = service.render_job_completion(
|
||||
name="Test User",
|
||||
youtube_url="https://youtube.com/watch?v=123",
|
||||
dropbox_url="https://dropbox.com/link",
|
||||
artist="Artist",
|
||||
title="Song",
|
||||
job_id="job-123",
|
||||
is_private=False,
|
||||
)
|
||||
|
||||
assert "https://youtube.com/watch?v=123" in result
|
||||
assert "YouTube" in result
|
||||
|
||||
def test_private_job_still_has_dropbox_link(self):
|
||||
"""Private job email should still contain the Dropbox link."""
|
||||
service = TemplateService()
|
||||
service._storage_client = Mock()
|
||||
service._bucket = Mock()
|
||||
service._bucket.blob.return_value.exists.return_value = False
|
||||
|
||||
result = service.render_job_completion(
|
||||
name="Test User",
|
||||
dropbox_url="https://dropbox.com/sh/abc123",
|
||||
artist="Artist",
|
||||
title="Song",
|
||||
job_id="job-123",
|
||||
is_private=True,
|
||||
)
|
||||
|
||||
assert "https://dropbox.com/sh/abc123" in result
|
||||
assert "dropbox" in result.lower()
|
||||
|
||||
def test_private_job_still_has_greeting(self):
|
||||
"""Private job email should still contain the greeting."""
|
||||
service = TemplateService()
|
||||
service._storage_client = Mock()
|
||||
service._bucket = Mock()
|
||||
service._bucket.blob.return_value.exists.return_value = False
|
||||
|
||||
result = service.render_job_completion(
|
||||
name="Jane",
|
||||
dropbox_url="https://dropbox.com/link",
|
||||
is_private=True,
|
||||
)
|
||||
|
||||
assert "Hi Jane" in result
|
||||
|
||||
|
||||
class TestNotificationServicePrivate:
|
||||
"""Tests for notification service passing is_private to template."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_completion_email_passes_is_private(self):
|
||||
"""send_job_completion_email should pass is_private to template renderer."""
|
||||
from backend.services.job_notification_service import JobNotificationService
|
||||
|
||||
service = JobNotificationService()
|
||||
service.email_service = Mock()
|
||||
service.email_service.send_job_completion.return_value = True
|
||||
service.template_service = Mock()
|
||||
service.template_service.render_job_completion.return_value = "Test message"
|
||||
|
||||
with patch('backend.services.job_notification_service.ENABLE_AUTO_EMAILS', True):
|
||||
await service.send_job_completion_email(
|
||||
job_id="job-123",
|
||||
user_email="user@example.com",
|
||||
is_private=True,
|
||||
)
|
||||
|
||||
# Verify is_private=True was passed to template renderer
|
||||
call_kwargs = service.template_service.render_job_completion.call_args
|
||||
assert call_kwargs[1].get('is_private') is True or \
|
||||
(call_kwargs[0] and True in call_kwargs[0]) # positional or keyword
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_completion_email_defaults_is_private_false(self):
|
||||
"""send_job_completion_email should default is_private to False."""
|
||||
from backend.services.job_notification_service import JobNotificationService
|
||||
|
||||
service = JobNotificationService()
|
||||
service.email_service = Mock()
|
||||
service.email_service.send_job_completion.return_value = True
|
||||
service.template_service = Mock()
|
||||
service.template_service.render_job_completion.return_value = "Test message"
|
||||
|
||||
with patch('backend.services.job_notification_service.ENABLE_AUTO_EMAILS', True):
|
||||
await service.send_job_completion_email(
|
||||
job_id="job-123",
|
||||
user_email="user@example.com",
|
||||
)
|
||||
|
||||
call_kwargs = service.template_service.render_job_completion.call_args
|
||||
assert call_kwargs[1].get('is_private') is False
|
||||
|
||||
def test_get_completion_message_passes_is_private(self):
|
||||
"""get_completion_message should pass is_private to template renderer."""
|
||||
from backend.services.job_notification_service import JobNotificationService
|
||||
|
||||
service = JobNotificationService()
|
||||
service.template_service = Mock()
|
||||
service.template_service.render_job_completion.return_value = "Test message"
|
||||
|
||||
service.get_completion_message(job_id="job-123", is_private=True)
|
||||
|
||||
call_kwargs = service.template_service.render_job_completion.call_args
|
||||
assert call_kwargs[1].get('is_private') is True
|
||||
|
||||
|
||||
class TestRequestModelIsPrivate:
|
||||
"""Tests for is_private on API request models."""
|
||||
|
||||
def test_url_submission_request_has_is_private(self):
|
||||
"""URLSubmissionRequest should accept is_private field."""
|
||||
from backend.models.requests import URLSubmissionRequest
|
||||
req = URLSubmissionRequest(url="https://youtube.com/watch?v=123", is_private=True)
|
||||
assert req.is_private is True
|
||||
|
||||
def test_url_submission_request_is_private_defaults_none(self):
|
||||
"""URLSubmissionRequest.is_private should default to None."""
|
||||
from backend.models.requests import URLSubmissionRequest
|
||||
req = URLSubmissionRequest(url="https://youtube.com/watch?v=123")
|
||||
assert req.is_private is None
|
||||
|
||||
|
||||
class TestAdminPrivateToggle:
|
||||
"""Tests for admin API handling of is_private toggle."""
|
||||
|
||||
def test_is_private_in_editable_fields(self):
|
||||
"""is_private should be in the EDITABLE_JOB_FIELDS set."""
|
||||
from backend.api.routes.admin import EDITABLE_JOB_FIELDS
|
||||
assert "is_private" in EDITABLE_JOB_FIELDS
|
||||
|
||||
def test_job_update_request_has_is_private(self):
|
||||
"""JobUpdateRequest model should accept is_private field."""
|
||||
from backend.api.routes.admin import JobUpdateRequest
|
||||
req = JobUpdateRequest(is_private=True)
|
||||
assert req.is_private is True
|
||||
|
||||
def test_job_update_request_is_private_optional(self):
|
||||
"""JobUpdateRequest.is_private should be optional."""
|
||||
from backend.api.routes.admin import JobUpdateRequest
|
||||
req = JobUpdateRequest()
|
||||
assert req.is_private is None
|
||||
|
||||
|
||||
class TestOrchestratorConfigPrivate:
|
||||
"""Tests for orchestrator config with private jobs."""
|
||||
|
||||
@patch('backend.services.job_defaults_service.get_settings')
|
||||
def test_private_job_config_disables_youtube_and_gdrive(self, mock_settings):
|
||||
"""Private job should produce config with no YouTube and no GDrive."""
|
||||
mock_settings.return_value = SimpleNamespace(
|
||||
default_private_dropbox_path="/Tracks-NonPublished",
|
||||
default_private_brand_prefix="NOMADNP",
|
||||
)
|
||||
from backend.workers.video_worker_orchestrator import create_orchestrator_config_from_job
|
||||
|
||||
job = MagicMock()
|
||||
job.job_id = "test-private"
|
||||
job.artist = "Artist"
|
||||
job.title = "Title"
|
||||
job.state_data = {"instrumental_selection": "clean"}
|
||||
job.enable_cdg = False
|
||||
job.enable_txt = False
|
||||
job.enable_youtube_upload = True # Would normally enable YouTube
|
||||
job.is_private = True # But private overrides it
|
||||
job.brand_prefix = "NOMAD"
|
||||
job.discord_webhook_url = None
|
||||
job.youtube_description_template = "desc"
|
||||
job.dropbox_path = "/Tracks-Organized"
|
||||
job.gdrive_folder_id = "folder-123"
|
||||
job.keep_brand_code = None
|
||||
job.existing_instrumental_gcs_path = None
|
||||
|
||||
config = create_orchestrator_config_from_job(
|
||||
job=job,
|
||||
temp_dir="/tmp/test",
|
||||
youtube_credentials={"token": "test"},
|
||||
)
|
||||
|
||||
assert config.enable_youtube_upload is False
|
||||
assert config.gdrive_folder_id is None
|
||||
assert config.brand_prefix == "NOMADNP"
|
||||
assert config.youtube_description_template is None
|
||||
@@ -855,6 +855,7 @@ class TestCreateOrchestratorConfigFromJob:
|
||||
job.enable_cdg = True
|
||||
job.enable_txt = False
|
||||
job.enable_youtube_upload = True
|
||||
job.is_private = False
|
||||
job.brand_prefix = "NOMAD"
|
||||
job.discord_webhook_url = "https://discord.com/api/webhooks/123/abc"
|
||||
job.youtube_description_template = "Test description"
|
||||
@@ -888,6 +889,7 @@ class TestCreateOrchestratorConfigFromJob:
|
||||
job.enable_cdg = False
|
||||
job.enable_txt = False
|
||||
job.enable_youtube_upload = False
|
||||
job.is_private = False
|
||||
job.brand_prefix = None
|
||||
job.discord_webhook_url = None
|
||||
job.youtube_description_template = None
|
||||
@@ -926,6 +928,7 @@ class TestCreateOrchestratorConfigFromJob:
|
||||
job.enable_cdg = False
|
||||
job.enable_txt = False
|
||||
job.enable_youtube_upload = False
|
||||
job.is_private = False
|
||||
job.brand_prefix = None
|
||||
job.discord_webhook_url = None
|
||||
job.youtube_description_template = None
|
||||
|
||||
@@ -237,15 +237,17 @@ async def generate_video_orchestrated(job_id: str) -> bool:
|
||||
if rclone_service.setup_rclone_config():
|
||||
job_log.info("Rclone config loaded for Dropbox upload")
|
||||
|
||||
# Load YouTube credentials if needed
|
||||
# Load YouTube credentials if needed (skip for private/non-published tracks)
|
||||
youtube_credentials = None
|
||||
if getattr(job, 'enable_youtube_upload', False):
|
||||
if getattr(job, 'enable_youtube_upload', False) and not getattr(job, 'is_private', False):
|
||||
youtube_service = get_youtube_service()
|
||||
if youtube_service.is_configured:
|
||||
youtube_credentials = youtube_service.get_credentials_dict()
|
||||
job_log.info("YouTube credentials loaded for video upload")
|
||||
else:
|
||||
job_log.warning("YouTube credentials not available - upload will be skipped")
|
||||
elif getattr(job, 'is_private', False):
|
||||
job_log.info("Private track - skipping YouTube upload")
|
||||
|
||||
try:
|
||||
# Wrap entire worker in a tracing span
|
||||
@@ -467,16 +469,18 @@ async def generate_video_legacy(job_id: str) -> bool:
|
||||
else:
|
||||
job_log.warning("Rclone config not available - Dropbox upload will be skipped")
|
||||
|
||||
# Load YouTube credentials if needed
|
||||
# Load YouTube credentials if needed (skip for private/non-published tracks)
|
||||
youtube_credentials = None
|
||||
if getattr(job, 'enable_youtube_upload', False):
|
||||
if getattr(job, 'enable_youtube_upload', False) and not getattr(job, 'is_private', False):
|
||||
youtube_service = get_youtube_service()
|
||||
if youtube_service.is_configured:
|
||||
youtube_credentials = youtube_service.get_credentials_dict()
|
||||
job_log.info("YouTube credentials loaded for video upload")
|
||||
else:
|
||||
job_log.warning("YouTube credentials not available - upload will be skipped")
|
||||
|
||||
elif getattr(job, 'is_private', False):
|
||||
job_log.info("Private track - skipping YouTube upload")
|
||||
|
||||
try:
|
||||
# Wrap entire worker in a tracing span
|
||||
with job_span("video-worker", job_id, {"artist": job.artist, "title": job.title}) as root_span:
|
||||
@@ -776,10 +780,14 @@ async def _handle_native_distribution(
|
||||
brand_code = keep_brand_code
|
||||
result['brand_code'] = brand_code
|
||||
job_log.info(f"Using preserved brand code: {brand_code}")
|
||||
|
||||
|
||||
# Get effective distribution settings (applies private track overrides if is_private=True)
|
||||
from backend.services.job_defaults_service import get_effective_distribution_for_job
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
# Upload to Dropbox using native SDK
|
||||
dropbox_path = getattr(job, 'dropbox_path', None)
|
||||
brand_prefix = getattr(job, 'brand_prefix', None)
|
||||
dropbox_path = dist.dropbox_path
|
||||
brand_prefix = dist.brand_prefix
|
||||
|
||||
if dropbox_path and brand_prefix:
|
||||
try:
|
||||
@@ -836,7 +844,7 @@ async def _handle_native_distribution(
|
||||
# Upload to Google Drive using native API
|
||||
# Skip if orchestrator already uploaded (gdrive_files already populated)
|
||||
# This prevents duplicate uploads when using the orchestrator path
|
||||
gdrive_folder_id = getattr(job, 'gdrive_folder_id', None)
|
||||
gdrive_folder_id = dist.gdrive_folder_id
|
||||
existing_gdrive_files = result.get('gdrive_files')
|
||||
|
||||
if gdrive_folder_id and not existing_gdrive_files:
|
||||
|
||||
@@ -731,6 +731,10 @@ def create_orchestrator_config_from_job(
|
||||
instrumental_suffix = "Clean" if instrumental_selection == 'clean' else "Backing"
|
||||
instrumental_path = os.path.join(temp_dir, f"{base_name} (Instrumental {instrumental_suffix}).flac")
|
||||
|
||||
# Get effective distribution settings (applies private track overrides if is_private=True)
|
||||
from backend.services.job_defaults_service import get_effective_distribution_for_job
|
||||
dist = get_effective_distribution_for_job(job)
|
||||
|
||||
return OrchestratorConfig(
|
||||
job_id=job.job_id,
|
||||
artist=job.artist,
|
||||
@@ -750,18 +754,18 @@ def create_orchestrator_config_from_job(
|
||||
# Feature flags
|
||||
enable_cdg=getattr(job, 'enable_cdg', False),
|
||||
enable_txt=getattr(job, 'enable_txt', False),
|
||||
enable_youtube_upload=getattr(job, 'enable_youtube_upload', False),
|
||||
enable_youtube_upload=dist.enable_youtube_upload,
|
||||
|
||||
# Service configurations
|
||||
brand_prefix=getattr(job, 'brand_prefix', None),
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
# Service configurations (distribution settings from helper, respects is_private)
|
||||
brand_prefix=dist.brand_prefix,
|
||||
discord_webhook_url=dist.discord_webhook_url,
|
||||
youtube_credentials=youtube_credentials,
|
||||
youtube_description_template=getattr(job, 'youtube_description_template', None),
|
||||
youtube_description_template=dist.youtube_description,
|
||||
cdg_styles=cdg_styles,
|
||||
|
||||
# Dropbox/GDrive
|
||||
dropbox_path=getattr(job, 'dropbox_path', None),
|
||||
gdrive_folder_id=getattr(job, 'gdrive_folder_id', None),
|
||||
# Dropbox/GDrive (overridden for private tracks)
|
||||
dropbox_path=dist.dropbox_path,
|
||||
gdrive_folder_id=dist.gdrive_folder_id,
|
||||
|
||||
# Keep existing brand code
|
||||
keep_brand_code=getattr(job, 'keep_brand_code', None),
|
||||
|
||||
+4
-1
@@ -77,6 +77,7 @@ Content-Type: multipart/form-data
|
||||
file: <audio file>
|
||||
artist: "Artist Name"
|
||||
title: "Song Title"
|
||||
is_private: false # Optional. If true, Dropbox uses Tracks-NonPublished/NOMADNP, no YouTube/GDrive
|
||||
```
|
||||
|
||||
Returns job ID. Triggers async processing.
|
||||
@@ -887,7 +888,9 @@ Content-Type: application/json
|
||||
}
|
||||
```
|
||||
|
||||
Updates editable job fields. Allowed fields: `artist`, `title`, `user_email`, `theme_id`, `brand_prefix`, `discord_webhook_url`, `youtube_description`, `youtube_description_template`, `customer_email`, `customer_notes`, `enable_cdg`, `enable_txt`, `enable_youtube_upload`, `non_interactive`, `prep_only`.
|
||||
Updates editable job fields. Allowed fields: `artist`, `title`, `user_email`, `theme_id`, `brand_prefix`, `discord_webhook_url`, `youtube_description`, `youtube_description_template`, `customer_email`, `customer_notes`, `enable_cdg`, `enable_txt`, `enable_youtube_upload`, `non_interactive`, `prep_only`, `is_private`.
|
||||
|
||||
**Note:** Setting `is_private=true` on a completed job with existing outputs triggers automatic output deletion.
|
||||
|
||||
Response:
|
||||
```json
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
| CI/CD self-hosted runner | Working (GCP) |
|
||||
| E2E happy path test | Working (~20-25 min full pipeline) |
|
||||
| **White-label B2B portals** | Working (Vocal Star first tenant) |
|
||||
| **Private (non-published) tracks** | Working |
|
||||
|
||||
## Known Issues
|
||||
|
||||
@@ -41,6 +42,8 @@
|
||||
|
||||
## Recent Changes
|
||||
|
||||
- **Private (Non-Published) Tracks** (2026-02-24): Added `is_private` flag on jobs for private/non-published track production. Private jobs upload to Dropbox `Tracks-NonPublished` folder with `NOMADNP` brand prefix, skip YouTube and Google Drive entirely, and send completion emails without the YouTube section. Available as a checkbox on all job creation tabs and as an admin toggle (auto-deletes outputs when toggling a completed job to private). See [archive/2026-02-24-private-tracks-plan.md](archive/2026-02-24-private-tracks-plan.md).
|
||||
|
||||
- **GCE Encoding Worker Version Sorting Fix** (2026-02-11): Fixed critical regression from PR #384 where alphabetical sorting caused encoder to use v0.99.9 instead of v0.116.1. **Root cause**: `sorted(wheels)[-1]` uses string comparison, not semantic versioning. String comparison puts "0.99.9" > "0.116.1" (because '9' > '1' in second position). **Impact**: Production encoder was running an extremely old version (v0.99.9 from months ago) instead of the latest (v0.116.1). **Fix**: Extract version from wheel filename using regex, sort by `packaging.version.Version` objects instead of strings. Added 10 comprehensive unit tests covering the exact regression case (0.99.9 vs 0.116.1), edge cases (empty list, invalid filenames), and complex version comparisons (major/minor/patch). Production now correctly selects the latest semantic version. See [LESSONS-LEARNED.md](LESSONS-LEARNED.md#semantic-version-sorting-feb-2026).
|
||||
|
||||
- **GCE Encoding Worker Wheel Fix** (2026-02-10): Fixed encoding worker crash caused by attempting to install `karaoke_gen-current.whl`, which is not a valid PEP 427 wheel filename (missing version and platform tags). **Root cause**: The `ensure_latest_wheel()` function downloaded all wheels including `karaoke_gen-current.whl`, then tried to install it. pip rejected it with "Invalid wheel filename (wrong number of parts)", causing encoding to fail and the service to restart, resulting in "Cannot connect" errors from Cloud Run. **Fix**: Filter out wheels containing '-current' before selecting which wheel to install. Only properly versioned wheels (e.g., `karaoke_gen-0.116.0-py3-none-any.whl`) are now considered. Added 5 comprehensive unit tests covering current wheel exclusion, empty results, version sorting, and path-agnostic filtering. Fixes job 749141f8 and prevents future encoding failures. See [LESSONS-LEARNED.md](LESSONS-LEARNED.md#pip-wheel-filename-validation-feb-2026).
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
# Plan: Private (Non-Published) Tracks
|
||||
|
||||
**Created:** 2026-02-24
|
||||
**Branch:** feat/sess-20260224-1149-private-tracks
|
||||
**Status:** Draft
|
||||
|
||||
## Overview
|
||||
|
||||
Add a `is_private` flag to jobs that changes distribution behavior:
|
||||
- **Dropbox**: Uses `Tracks-NonPublished` folder (not `Tracks-Organized`) with brand code `NOMADNP` (not `NOMAD`)
|
||||
- **YouTube**: Skipped entirely
|
||||
- **Google Drive**: Skipped entirely
|
||||
- **Email**: Completion email includes Dropbox link but no YouTube section
|
||||
- **Discord**: Still notified (for internal tracking)
|
||||
|
||||
Available to all users at job creation and toggleable by admin on existing jobs.
|
||||
|
||||
## Requirements
|
||||
|
||||
- [ ] All users can mark a job as "Private (Non-Published)" when creating it
|
||||
- [ ] Admin can toggle `is_private` on any existing job via admin dashboard
|
||||
- [ ] Private jobs upload to Dropbox at `Tracks-NonPublished` with `NOMADNP-XXXX` brand codes
|
||||
- [ ] Private jobs skip YouTube and Google Drive uploads entirely
|
||||
- [ ] Completion emails omit YouTube section when no YouTube URL (private jobs + any other edge case)
|
||||
- [ ] When admin toggles a completed job to private, existing outputs are auto-deleted
|
||||
- [ ] Discord notifications still fire for private jobs
|
||||
- [ ] Existing (non-private) jobs are completely unaffected (backward compatible)
|
||||
|
||||
## Technical Approach
|
||||
|
||||
### Core Design: Single Boolean Flag with Runtime Overrides
|
||||
|
||||
Store `is_private: bool = False` on the job model. At distribution time, a helper function returns effective distribution parameters based on this flag. This means:
|
||||
|
||||
- **Toggling is_private automatically changes all distribution behavior** - no need to manually update dropbox_path, brand_prefix, enable_youtube_upload, gdrive_folder_id
|
||||
- **Job fields still store the "normal" defaults** - the override happens at the config-to-orchestrator boundary
|
||||
- **Admin can flip one field** and everything adapts
|
||||
|
||||
### Key Helper Function
|
||||
|
||||
```python
|
||||
# In job_defaults_service.py
|
||||
def get_effective_distribution_for_job(job) -> EffectiveDistributionSettings:
|
||||
"""Return distribution settings, applying private overrides if is_private=True."""
|
||||
if getattr(job, 'is_private', False):
|
||||
settings = get_settings()
|
||||
return EffectiveDistributionSettings(
|
||||
dropbox_path=settings.default_private_dropbox_path,
|
||||
brand_prefix=settings.default_private_brand_prefix,
|
||||
enable_youtube_upload=False,
|
||||
gdrive_folder_id=None,
|
||||
# Keep other settings from job (discord, youtube_description, etc.)
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
youtube_description=None,
|
||||
)
|
||||
# Non-private: return job's own settings
|
||||
return EffectiveDistributionSettings(
|
||||
dropbox_path=getattr(job, 'dropbox_path', None),
|
||||
brand_prefix=getattr(job, 'brand_prefix', None),
|
||||
enable_youtube_upload=getattr(job, 'enable_youtube_upload', False),
|
||||
gdrive_folder_id=getattr(job, 'gdrive_folder_id', None),
|
||||
discord_webhook_url=getattr(job, 'discord_webhook_url', None),
|
||||
youtube_description=getattr(job, 'youtube_description_template', None),
|
||||
)
|
||||
```
|
||||
|
||||
This helper is used in both distribution paths (orchestrator and native fallback).
|
||||
|
||||
### Distribution Paths That Need Changes
|
||||
|
||||
Two code paths handle distribution (see LESSONS-LEARNED: "Fix Both Sides of Dual Code Paths"):
|
||||
|
||||
1. **Orchestrator path** (`video_worker_orchestrator.py`): Primary path. `create_orchestrator_config_from_job()` uses the helper to build config.
|
||||
2. **Native distribution path** (`video_worker.py` → `_handle_native_distribution()`): Fallback path. Also uses the helper instead of reading job fields directly.
|
||||
|
||||
### Email Template Change
|
||||
|
||||
Add conditional YouTube section removal in `render_template()`, matching the existing pattern for `feedback_url`:
|
||||
|
||||
```python
|
||||
# Remove YouTube section if no URL provided
|
||||
if not variables.get("youtube_url"):
|
||||
result = re.sub(
|
||||
r"\n*Here's the link for the karaoke video published to YouTube:\n\{youtube_url\}\n*",
|
||||
'\n',
|
||||
result,
|
||||
flags=re.DOTALL
|
||||
)
|
||||
variables["youtube_url"] = ""
|
||||
```
|
||||
|
||||
And change `render_job_completion()` to pass `None` instead of `"[YouTube URL not available]"` when youtube_url is empty.
|
||||
|
||||
### Admin Toggle Auto-Delete
|
||||
|
||||
When admin PATCH updates `is_private` from False to True on a job that has existing outputs, reuse the existing delete-outputs logic to remove YouTube + GDrive + Dropbox outputs. Admin can then "Reprocess" to re-distribute to the private Dropbox path.
|
||||
|
||||
## Implementation Steps
|
||||
|
||||
### Phase 1: Backend Model & Config (foundation)
|
||||
|
||||
1. [ ] **Add `is_private` to Job model** (`backend/models/job.py`)
|
||||
- Add `is_private: bool = False` field after `made_for_you` field
|
||||
- Add to `JobCreate` model as well
|
||||
|
||||
2. [ ] **Add private distribution config** (`backend/config.py`)
|
||||
- Add `default_private_dropbox_path: Optional[str] = os.getenv("DEFAULT_PRIVATE_DROPBOX_PATH")`
|
||||
- Add `default_private_brand_prefix: Optional[str] = os.getenv("DEFAULT_PRIVATE_BRAND_PREFIX", "NOMADNP")`
|
||||
|
||||
3. [ ] **Add helper function** (`backend/services/job_defaults_service.py`)
|
||||
- Add `get_effective_distribution_for_job(job)` function that returns distribution settings with private overrides applied
|
||||
|
||||
### Phase 2: Backend API (job creation + admin)
|
||||
|
||||
4. [ ] **Add `is_private` to request models** (`backend/models/requests.py`)
|
||||
- Add `is_private: Optional[bool] = None` to `URLSubmissionRequest`
|
||||
- Add `is_private: Optional[bool] = None` to `AudioSearchRequest`
|
||||
|
||||
5. [ ] **Update URL creation endpoint** (`backend/api/routes/jobs.py`)
|
||||
- Accept and pass through `is_private` field to `JobCreate`
|
||||
|
||||
6. [ ] **Update file upload endpoint** (`backend/api/routes/file_upload.py`)
|
||||
- Accept `is_private` Form parameter
|
||||
- Pass through to `JobCreate`
|
||||
|
||||
7. [ ] **Update audio search endpoint** (`backend/api/routes/audio_search.py`)
|
||||
- Accept `is_private` in `AudioSearchRequest`
|
||||
- Pass through to `JobCreate`
|
||||
|
||||
8. [ ] **Update admin endpoints** (`backend/api/routes/admin.py`)
|
||||
- Add `is_private: Optional[bool] = None` to `JobUpdateRequest`
|
||||
- Add `"is_private"` to `EDITABLE_JOB_FIELDS`
|
||||
- In the PATCH handler: detect when `is_private` changes from False→True on a completed job, auto-delete existing outputs (call existing delete-outputs service logic)
|
||||
|
||||
### Phase 3: Distribution Pipeline
|
||||
|
||||
9. [ ] **Update orchestrator config creation** (`backend/workers/video_worker_orchestrator.py`)
|
||||
- In `create_orchestrator_config_from_job()`: Use `get_effective_distribution_for_job()` helper to determine dropbox_path, brand_prefix, enable_youtube_upload, gdrive_folder_id instead of reading directly from job
|
||||
|
||||
10. [ ] **Update native distribution fallback** (`backend/workers/video_worker.py`)
|
||||
- In `_handle_native_distribution()`: Use `get_effective_distribution_for_job()` helper instead of reading directly from job fields
|
||||
|
||||
### Phase 4: Email Template
|
||||
|
||||
11. [ ] **Add YouTube section conditional removal** (`backend/services/template_service.py`)
|
||||
- In `render_template()`: Add regex to remove YouTube paragraph when `youtube_url` is empty (matching existing `feedback_url` pattern)
|
||||
- In `render_job_completion()`: Pass `None` for youtube_url when empty (instead of `"[YouTube URL not available]"`)
|
||||
|
||||
### Phase 5: Frontend
|
||||
|
||||
12. [ ] **Add private checkbox to job creation form** (`frontend/components/job/JobSubmission.tsx`)
|
||||
- Add "Private (Non-Published)" checkbox below the existing "Skip lyrics review" checkbox
|
||||
- Show for all users (not just admin)
|
||||
- Include brief description text: "Private tracks go to Dropbox only, not YouTube or Google Drive"
|
||||
|
||||
13. [ ] **Update API interfaces** (`frontend/lib/api.ts`)
|
||||
- Add `is_private?: boolean` to all job creation option interfaces
|
||||
- Add `is_private` to `JobUpdateRequest` interface
|
||||
- Pass through in `uploadJob()`, `createJobFromUrl()`, `searchAudio()` methods
|
||||
|
||||
14. [ ] **Add private toggle to admin job detail** (`frontend/app/admin/jobs/page.tsx`)
|
||||
- Add `is_private` as an inline-editable field in the job overview section (use Switch component)
|
||||
- Show current state with visual indicator (e.g., lock icon for private jobs)
|
||||
- When toggling to private on a completed job, show confirmation dialog about auto-deleting outputs
|
||||
|
||||
### Phase 6: Environment Configuration
|
||||
|
||||
15. [ ] **Update CI/deployment config** (`.github/workflows/ci.yml` or Cloud Run env)
|
||||
- Add `DEFAULT_PRIVATE_DROPBOX_PATH` environment variable (e.g., `/Karaoke/Tracks-NonPublished`)
|
||||
- Add `DEFAULT_PRIVATE_BRAND_PREFIX` environment variable (e.g., `NOMADNP`)
|
||||
- These should be configured in Cloud Run service and CI test environment
|
||||
|
||||
### Phase 7: Testing
|
||||
|
||||
16. [ ] **Unit tests for private distribution logic** (`backend/tests/test_private_tracks.py`)
|
||||
- Test `get_effective_distribution_for_job()` with private and non-private jobs
|
||||
- Test `create_orchestrator_config_from_job()` applies private overrides correctly
|
||||
- Test `_run_distribution()` skips YouTube and GDrive when private config applied
|
||||
- Test `_upload_to_dropbox()` uses private path and brand prefix
|
||||
- Test brand code generation with NOMADNP prefix in Tracks-NonPublished
|
||||
- Test `_handle_native_distribution()` respects private overrides
|
||||
- Test non-private jobs are completely unaffected (regression tests)
|
||||
|
||||
17. [ ] **Unit tests for email changes** (add to `backend/tests/test_email_service.py` or `test_template_service.py`)
|
||||
- Test YouTube section removed from email when youtube_url is None
|
||||
- Test YouTube section present when youtube_url is provided
|
||||
- Test Dropbox section still present for private jobs
|
||||
- Test full email rendering for private job scenario
|
||||
|
||||
18. [ ] **Unit tests for admin toggle** (add to `backend/tests/test_admin.py` or new file)
|
||||
- Test admin can update is_private field
|
||||
- Test toggling is_private to True on completed job triggers output deletion
|
||||
- Test toggling is_private to True on non-completed job does NOT delete outputs
|
||||
- Test toggling is_private to False does nothing special
|
||||
|
||||
19. [ ] **Integration test** (`backend/tests/emulator/` or `test_distribution_services.py`)
|
||||
- Test full distribution pipeline with is_private=True: verify Dropbox path, brand prefix, YouTube skip, GDrive skip
|
||||
|
||||
20. [ ] **Frontend E2E regression test** (`frontend/e2e/regression/`)
|
||||
- Test private checkbox appears in job creation form
|
||||
- Test private toggle in admin dashboard
|
||||
|
||||
## Files to Create/Modify
|
||||
|
||||
| File | Action | Description |
|
||||
|------|--------|-------------|
|
||||
| `backend/models/job.py` | Modify | Add `is_private: bool = False` to Job and JobCreate |
|
||||
| `backend/config.py` | Modify | Add `default_private_dropbox_path` and `default_private_brand_prefix` |
|
||||
| `backend/services/job_defaults_service.py` | Modify | Add `get_effective_distribution_for_job()` helper |
|
||||
| `backend/models/requests.py` | Modify | Add `is_private` to URL and AudioSearch request models |
|
||||
| `backend/api/routes/jobs.py` | Modify | Accept and pass `is_private` |
|
||||
| `backend/api/routes/file_upload.py` | Modify | Accept and pass `is_private` |
|
||||
| `backend/api/routes/audio_search.py` | Modify | Accept and pass `is_private` |
|
||||
| `backend/api/routes/admin.py` | Modify | Add `is_private` to editable fields + auto-delete logic |
|
||||
| `backend/workers/video_worker_orchestrator.py` | Modify | Use helper in `create_orchestrator_config_from_job()` |
|
||||
| `backend/workers/video_worker.py` | Modify | Use helper in `_handle_native_distribution()` |
|
||||
| `backend/services/template_service.py` | Modify | Conditional YouTube section removal |
|
||||
| `frontend/components/job/JobSubmission.tsx` | Modify | Add private checkbox |
|
||||
| `frontend/lib/api.ts` | Modify | Add `is_private` to interfaces and API calls |
|
||||
| `frontend/app/admin/jobs/page.tsx` | Modify | Add private toggle to admin detail |
|
||||
| `backend/tests/test_private_tracks.py` | Create | Comprehensive unit tests for private track logic |
|
||||
|
||||
## Testing Strategy
|
||||
|
||||
### Unit Tests (~25-30 tests in `test_private_tracks.py`)
|
||||
- `get_effective_distribution_for_job()` with private=True and False
|
||||
- `create_orchestrator_config_from_job()` private overrides (YouTube=False, GDrive=None, private Dropbox path, NOMADNP brand)
|
||||
- Distribution stage skips: YouTube not called, GDrive not called, Dropbox IS called with correct path
|
||||
- Brand code generation uses NOMADNP prefix and Tracks-NonPublished path
|
||||
- Native distribution fallback applies same overrides
|
||||
- **Regression tests**: Non-private jobs have unchanged behavior (same paths, same brand code, YouTube+GDrive+Dropbox all fire)
|
||||
|
||||
### Email Template Tests (~5 tests)
|
||||
- YouTube section stripped when youtube_url is None
|
||||
- YouTube section preserved when youtube_url has value
|
||||
- Dropbox section always present
|
||||
- Full private job email rendering (Dropbox + no YouTube)
|
||||
- Full non-private job email rendering (both present) - regression
|
||||
|
||||
### Admin Toggle Tests (~5 tests)
|
||||
- is_private editable via PATCH
|
||||
- Toggle to private on completed job deletes outputs
|
||||
- Toggle to private on pending/in-progress job does NOT delete
|
||||
- Toggle to non-private does nothing special
|
||||
|
||||
### Frontend Tests
|
||||
- E2E: Private checkbox visible and functional in job creation
|
||||
- E2E: Admin toggle visible and includes confirmation dialog
|
||||
|
||||
### Manual Verification
|
||||
- Create a private job end-to-end, verify Dropbox folder in Tracks-NonPublished with NOMADNP code
|
||||
- Verify completion email has Dropbox link but no YouTube section
|
||||
- Toggle existing completed job to private, verify outputs deleted
|
||||
|
||||
## Regression Risk Analysis
|
||||
|
||||
| Risk | Mitigation |
|
||||
|------|-----------|
|
||||
| Non-private jobs affected | `is_private` defaults to `False`; helper returns unchanged values for non-private. Explicit regression tests. |
|
||||
| Dual code paths (orchestrator vs native) | Both paths use same helper function. Tests cover both paths. (Lesson: "Fix Both Sides of Dual Code Paths") |
|
||||
| Email template regex breaks other content | Regex targets specific YouTube paragraph text. Tests verify non-YouTube content untouched. |
|
||||
| Brand code namespace collision | NOMADNP codes are in a completely separate Dropbox folder (Tracks-NonPublished), no overlap with NOMAD codes in Tracks-Organized |
|
||||
| Admin auto-delete on wrong job | Only triggers when `is_private` changes from False→True AND job has terminal status (complete). Confirmation dialog in frontend. |
|
||||
| Made-for-you orders | MFY webhook doesn't set is_private (defaults False). Admin can toggle after. No change to MFY flow. |
|
||||
| Existing Firestore documents | Missing `is_private` field defaults to `False` via model default. No migration needed. |
|
||||
|
||||
## Open Questions
|
||||
|
||||
- [x] Who sees private toggle? → **Everyone** (all users at creation, admin on existing)
|
||||
- [x] Auto-delete on toggle? → **Yes**, auto-delete all outputs when toggling to private on completed job
|
||||
- [x] Email format? → **Remove YouTube section** when no YouTube URL (improves all edge cases)
|
||||
- [x] Discord? → **Still notify** (useful for internal tracking)
|
||||
|
||||
## Rollback Plan
|
||||
|
||||
1. **Feature flag**: The `is_private` field defaults to `False`, so setting `DEFAULT_PRIVATE_DROPBOX_PATH` to empty/None effectively disables private distribution
|
||||
2. **No schema migration needed**: Missing `is_private` field on existing Firestore documents defaults to `False`
|
||||
3. **Email change is backward-compatible**: The YouTube section removal only happens when youtube_url is None, which is already an edge case showing "[YouTube URL not available]"
|
||||
4. **Frontend**: Private checkbox is additive UI, removing it just means users can't create new private jobs
|
||||
@@ -1210,6 +1210,41 @@ function AdminJobsPageContent() {
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
{/* Private (non-published) toggle */}
|
||||
<div className="flex items-center gap-2 pt-2 border-t">
|
||||
<span className="text-[10px] font-medium text-muted-foreground uppercase w-20 shrink-0">Private</span>
|
||||
<div className="flex items-center gap-2 flex-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="admin-is-private"
|
||||
checked={selectedJob.is_private || false}
|
||||
onChange={async (e) => {
|
||||
const newValue = e.target.checked
|
||||
try {
|
||||
await adminApi.updateJob(selectedJobId!, { is_private: newValue })
|
||||
setSelectedJob({ ...selectedJob, is_private: newValue })
|
||||
toast({
|
||||
title: "Updated",
|
||||
description: newValue
|
||||
? "Job set to private (outputs will be auto-deleted if completed)"
|
||||
: "Job set to public",
|
||||
})
|
||||
} catch (err: any) {
|
||||
toast({
|
||||
title: "Error",
|
||||
description: err.message || "Failed to update private flag",
|
||||
variant: "destructive",
|
||||
})
|
||||
}
|
||||
}}
|
||||
className="w-3.5 h-3.5 rounded border-border accent-orange-500"
|
||||
/>
|
||||
<label htmlFor="admin-is-private" className="text-xs cursor-pointer">
|
||||
Non-published (Dropbox only, no YouTube/GDrive)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
@@ -64,6 +64,9 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
// Non-interactive mode (shared across all tabs)
|
||||
const [nonInteractive, setNonInteractive] = useState(false)
|
||||
|
||||
// Private (non-published) mode - Dropbox only, no YouTube/GDrive
|
||||
const [isPrivate, setIsPrivate] = useState(false)
|
||||
|
||||
async function handleUploadSubmit(e: React.FormEvent) {
|
||||
e.preventDefault()
|
||||
setError("")
|
||||
@@ -81,6 +84,7 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
try {
|
||||
await api.uploadJob(uploadFile, uploadArtist.trim(), uploadTitle.trim(), {
|
||||
non_interactive: nonInteractive,
|
||||
is_private: isPrivate,
|
||||
})
|
||||
setUploadFile(null)
|
||||
setUploadArtist("")
|
||||
@@ -118,6 +122,7 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
youtubeTitle.trim(),
|
||||
{
|
||||
non_interactive: nonInteractive,
|
||||
is_private: isPrivate,
|
||||
}
|
||||
)
|
||||
setYoutubeUrl("")
|
||||
@@ -148,6 +153,7 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
try {
|
||||
await api.searchAudio(searchArtist.trim(), searchTitle.trim(), false, {
|
||||
non_interactive: nonInteractive,
|
||||
is_private: isPrivate,
|
||||
// Display overrides (empty string means use search values)
|
||||
display_artist: displayArtist.trim() || undefined,
|
||||
display_title: displayTitle.trim() || undefined,
|
||||
@@ -307,6 +313,28 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Private (non-published) mode */}
|
||||
<div className="space-y-2 pt-4 border-t" style={{ borderColor: 'var(--card-border)' }}>
|
||||
<div className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="private-upload"
|
||||
checked={isPrivate}
|
||||
onChange={(e) => setIsPrivate(e.target.checked)}
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 w-4 h-4 rounded border-border bg-secondary accent-[var(--brand-pink)] focus:ring-[var(--brand-pink)] focus:ring-offset-background"
|
||||
/>
|
||||
<div>
|
||||
<Label htmlFor="private-upload" className="cursor-pointer" style={{ color: 'var(--text)' }}>
|
||||
Private (non-published)
|
||||
</Label>
|
||||
<p className="text-xs mt-1" style={{ color: 'var(--text-muted)' }}>
|
||||
Files delivered via Dropbox only. No YouTube or Google Drive upload.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && activeTab === "upload" && (
|
||||
<p className="text-sm text-red-400 bg-red-500/10 rounded p-2">{error}</p>
|
||||
)}
|
||||
@@ -402,6 +430,28 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Private (non-published) mode */}
|
||||
<div className="space-y-2 pt-4 border-t" style={{ borderColor: 'var(--card-border)' }}>
|
||||
<div className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="private-url"
|
||||
checked={isPrivate}
|
||||
onChange={(e) => setIsPrivate(e.target.checked)}
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 w-4 h-4 rounded border-border bg-secondary accent-[var(--brand-pink)] focus:ring-[var(--brand-pink)] focus:ring-offset-background"
|
||||
/>
|
||||
<div>
|
||||
<Label htmlFor="private-url" className="cursor-pointer" style={{ color: 'var(--text)' }}>
|
||||
Private (non-published)
|
||||
</Label>
|
||||
<p className="text-xs mt-1" style={{ color: 'var(--text-muted)' }}>
|
||||
Files delivered via Dropbox only. No YouTube or Google Drive upload.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && activeTab === "url" && (
|
||||
<p className="text-sm text-red-400 bg-red-500/10 rounded p-2">{error}</p>
|
||||
)}
|
||||
@@ -535,6 +585,28 @@ export function JobSubmission({ onJobCreated }: JobSubmissionProps) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Private (non-published) mode */}
|
||||
<div className="space-y-2 pt-4 border-t" style={{ borderColor: 'var(--card-border)' }}>
|
||||
<div className="flex items-start gap-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
id="private-search"
|
||||
checked={isPrivate}
|
||||
onChange={(e) => setIsPrivate(e.target.checked)}
|
||||
disabled={isSubmitting}
|
||||
className="mt-1 w-4 h-4 rounded border-border bg-secondary accent-[var(--brand-pink)] focus:ring-[var(--brand-pink)] focus:ring-offset-background"
|
||||
/>
|
||||
<div>
|
||||
<Label htmlFor="private-search" className="cursor-pointer" style={{ color: 'var(--text)' }}>
|
||||
Private (non-published)
|
||||
</Label>
|
||||
<p className="text-xs mt-1" style={{ color: 'var(--text-muted)' }}>
|
||||
Files delivered via Dropbox only. No YouTube or Google Drive upload.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && activeTab === "search" && (
|
||||
<p className="text-sm text-red-400 bg-red-500/10 rounded p-2">{error}</p>
|
||||
)}
|
||||
|
||||
@@ -71,6 +71,7 @@ export interface Job {
|
||||
instrumental_token?: string;
|
||||
audio_hash?: string;
|
||||
non_interactive?: boolean;
|
||||
is_private?: boolean;
|
||||
user_email?: string;
|
||||
outputs_deleted_at?: string;
|
||||
outputs_deleted_by?: string;
|
||||
@@ -315,6 +316,7 @@ export const api = {
|
||||
theme_id?: string;
|
||||
color_overrides?: ColorOverrides;
|
||||
non_interactive?: boolean;
|
||||
is_private?: boolean;
|
||||
}
|
||||
): Promise<UploadJobResponse> {
|
||||
const formData = new FormData();
|
||||
@@ -343,6 +345,9 @@ export const api = {
|
||||
if (options?.non_interactive !== undefined) {
|
||||
formData.append('non_interactive', String(options.non_interactive));
|
||||
}
|
||||
if (options?.is_private !== undefined) {
|
||||
formData.append('is_private', String(options.is_private));
|
||||
}
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/jobs/upload`, {
|
||||
method: 'POST',
|
||||
@@ -368,6 +373,7 @@ export const api = {
|
||||
theme_id?: string;
|
||||
color_overrides?: ColorOverrides;
|
||||
non_interactive?: boolean;
|
||||
is_private?: boolean;
|
||||
}
|
||||
): Promise<{ status: string; job_id: string; message: string }> {
|
||||
const body: Record<string, any> = { url };
|
||||
@@ -380,6 +386,7 @@ export const api = {
|
||||
if (options?.theme_id) body.theme_id = options.theme_id;
|
||||
if (options?.color_overrides) body.color_overrides = options.color_overrides;
|
||||
if (options?.non_interactive !== undefined) body.non_interactive = options.non_interactive;
|
||||
if (options?.is_private !== undefined) body.is_private = options.is_private;
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/api/jobs/create-from-url`, {
|
||||
method: 'POST',
|
||||
@@ -564,6 +571,7 @@ export const api = {
|
||||
theme_id?: string;
|
||||
color_overrides?: ColorOverrides;
|
||||
non_interactive?: boolean;
|
||||
is_private?: boolean;
|
||||
// Display overrides - if provided, these appear on title screens/filenames instead of search values
|
||||
display_artist?: string;
|
||||
display_title?: string;
|
||||
@@ -577,6 +585,7 @@ export const api = {
|
||||
if (options?.theme_id) body.theme_id = options.theme_id;
|
||||
if (options?.color_overrides) body.color_overrides = options.color_overrides;
|
||||
if (options?.non_interactive !== undefined) body.non_interactive = options.non_interactive;
|
||||
if (options?.is_private !== undefined) body.is_private = options.is_private;
|
||||
// Display overrides
|
||||
if (options?.display_artist) body.display_artist = options.display_artist;
|
||||
if (options?.display_title) body.display_title = options.display_title;
|
||||
@@ -1717,6 +1726,7 @@ export interface JobUpdateRequest {
|
||||
enable_youtube_upload?: boolean;
|
||||
non_interactive?: boolean;
|
||||
prep_only?: boolean;
|
||||
is_private?: boolean;
|
||||
}
|
||||
|
||||
export interface JobUpdateResponse {
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "karaoke-gen"
|
||||
version = "0.118.6"
|
||||
version = "0.118.7"
|
||||
description = "Generate karaoke videos with synchronized lyrics. Handles the entire process from downloading audio and lyrics to creating the final video with title screens."
|
||||
authors = ["Andrew Beveridge <andrew@beveridge.uk>"]
|
||||
license = "MIT"
|
||||
|
||||
Reference in new issue
Block a user