diff --git a/clipwright/api/app.py b/clipwright/api/app.py index 1e49e65..c264ad0 100644 --- a/clipwright/api/app.py +++ b/clipwright/api/app.py @@ -53,8 +53,6 @@ MAX_FILE_SIZE_MB = int(os.environ.get("MAX_FILE_SIZE_MB", "0") or "0") # age-based sweep alone can't stop a burst of long videos from filling the disk. # 0 disables the cap. OUTPUT_MAX_GB = int(os.environ.get("OUTPUT_MAX_GB", "25")) -# Same idea for source uploads, which are the biggest single files on disk. -UPLOADS_MAX_GB = int(os.environ.get("UPLOADS_MAX_GB", "15")) # Pre-flight quality gate: warn before processing a YouTube source below this # height (0 disables). Only applies to URLs; uploads are whatever the user gave. QUALITY_GATE_MIN_HEIGHT = int(os.environ.get("QUALITY_GATE_MIN_HEIGHT", "720")) @@ -117,7 +115,7 @@ for _stream in (sys.stdout, sys.stderr): # Job/file retention (issue #46). Self-host defaults to 24h: the 1h sweep kept # deleting finished projects under users who never touched their env, and the -# OUTPUT_MAX_GB / UPLOADS_MAX_GB caps below already bound the disk. +# OUTPUT_MAX_GB cap below already bounds the disk. JOB_RETENTION_SECONDS = int( os.environ.get("JOB_RETENTION_SECONDS", "86400") ) @@ -1038,39 +1036,6 @@ def _sweep_expired_uploads(now): pass -def _enforce_uploads_size_cap(): - """Delete the oldest source uploads while UPLOAD_DIR is over UPLOADS_MAX_GB. - - Sources are only needed while a job runs (and for the preview afterwards), - but they're the biggest files on disk โ up to MAX_FILE_SIZE_MB each. - """ - cap = UPLOADS_MAX_GB * 1024 ** 3 - if cap <= 0: - return - used = _dir_size(UPLOAD_DIR) - if used <= cap: - return - files = [] - for name in os.listdir(UPLOAD_DIR): - p = os.path.join(UPLOAD_DIR, name) - if os.path.isfile(p) and not _job_is_active(_upload_job_id(name)): - try: - files.append((os.path.getmtime(p), p, os.path.getsize(p))) - except OSError: - pass - files.sort() - print(f"๐งน Uploads at {used / 1024**3:.1f} GB (cap {UPLOADS_MAX_GB} GB) โ trimming.") - for _mtime, path, size in files: - if used <= cap: - break - try: - os.remove(path) - used -= size - print(f"๐งน Size cap: removed upload {os.path.basename(path)}") - except OSError: - pass - - def _enforce_output_size_cap(): """Delete the oldest job dirs while OUTPUT_DIR is over OUTPUT_MAX_GB.""" cap = OUTPUT_MAX_GB * 1024 ** 3 @@ -1154,7 +1119,6 @@ async def cleanup_jobs(): # under the cap โ clips are already archived to R2 and get restored # on demand, so this only costs a re-download. _enforce_output_size_cap() - _enforce_uploads_size_cap() # Agent upload slots: expire with their file (the file sweep below # removes it; a slot whose file is gone or too old is dropped). @@ -2501,7 +2465,7 @@ async def process_endpoint( detail=f"{name} must be between {lo:g} and {hi:g}") return int(val) if integer else val - n_clips = _gen_control(target_clips, "target_clips", 1, 15, integer=True) + n_clips = _gen_control(target_clips, "target_clips", 1, 31, integer=True) min_secs = _gen_control(clip_min_seconds, "clip_min_seconds", 5, 175) max_secs = _gen_control(clip_max_seconds, "clip_max_seconds", 10, 180) if min_secs is not None and max_secs is not None and max_secs < min_secs + 5: diff --git a/dashboard/src/components/MediaInput.jsx b/dashboard/src/components/MediaInput.jsx index 564dd8f..e61c13d 100644 --- a/dashboard/src/components/MediaInput.jsx +++ b/dashboard/src/components/MediaInput.jsx @@ -413,7 +413,7 @@ export default function MediaInput({ onProcess, isProcessing }) {
clips to aim for
setTargetClips(e.target.value)} placeholder="auto" diff --git a/tests/e2e/api/test_process_submit.py b/tests/e2e/api/test_process_submit.py index 1a91c17..e02e664 100644 --- a/tests/e2e/api/test_process_submit.py +++ b/tests/e2e/api/test_process_submit.py @@ -261,7 +261,29 @@ async def test_target_clips_validation(client, media_factory): {"file": ("clip.mp4", media_factory.six.read_bytes(), "video/mp4")}, ) assert out_of_range.status_code == 400 - assert "target_clips must be between 1 and 15" in out_of_range.json()["detail"] + assert "target_clips must be between 1 and 31" in out_of_range.json()["detail"] + + +async def test_target_clips_accepts_raised_ceiling( + client, app_state, media_factory): + # The ceiling was raised from 15 to 31; the top of the new band must queue + # with the override the selector reads, and 32 must still be rejected. + resp = await _submit_file( + client, + {"acknowledged": "true", "target_clips": "31"}, + {"file": ("clip.mp4", media_factory.six.read_bytes(), "video/mp4")}, + ) + job_id = _job(client, resp) + env = app_state.app.jobs[job_id]["env"] + assert env["CLIP_TARGET_MIN"] == "31" and env["CLIP_TARGET_MAX"] == "31" + + too_many = await _submit_file( + client, + {"acknowledged": "true", "target_clips": "32"}, + {"file": ("clip.mp4", media_factory.six.read_bytes(), "video/mp4")}, + ) + assert too_many.status_code == 400 + assert "target_clips must be between 1 and 31" in too_many.json()["detail"] async def test_clip_range_validation(client, media_factory): diff --git a/tests/test_cleanup_live_jobs.py b/tests/test_cleanup_live_jobs.py index e0696a1..1ffae99 100644 --- a/tests/test_cleanup_live_jobs.py +++ b/tests/test_cleanup_live_jobs.py @@ -117,12 +117,3 @@ class TestUploadSweep: app_module.jobs["done"] = {"status": "failed"} app_module._sweep_expired_uploads(time.time()) assert not f.exists() - - def test_size_cap_skips_live_sources(self, disk, monkeypatch): - _, up = disk - live = _upload(up, "live") - app_module._running_jobs.add("live") - dead = _upload(up, "dead") - monkeypatch.setattr(app_module, "UPLOADS_MAX_GB", 1 / 1024 ** 3) - app_module._enforce_uploads_size_cap() - assert live.exists() and not dead.exists()