Input validation work and error handling

This commit is contained in:
Bradley committed 2026-11-13 22:18:45 -05:00
1 parent 4e2520ee76
commit 554b7cc82c
20 files changed
+627 -96

No files matched your search

+7 -2
View File
@@ -8,6 +8,8 @@ import sqlite3
import subprocess
import time
from utilities.validation import ensure_catalog_name_available, validate_media_name
LOGGER = logging.getLogger(__name__)
@@ -74,9 +76,12 @@ def process_next_job(db, storage, max_retries=3):
try:
LOGGER.info('Downloading job %s: %s', job_id, url)
path, title = download_video(job_id, url, storage)
media_name = requested_name.strip() or title
# Insert the media and finish the job together, or roll both changes back.
media_name = validate_media_name(requested_name.strip() or title)
# Check existing catalog names under the same write lock as completion.
# The job's own reservation is intentionally not treated as a conflict.
with db:
db.execute('BEGIN IMMEDIATE')
ensure_catalog_name_available(db, media_name)
db.execute(
'INSERT INTO media (media_name, media_uri) VALUES (?, ?)',
[media_name, str(path)]