fix(dashboard): PUT the handoff bundle through the app's API base #9
5 changed files with 90 additions and 18 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from clipwright.pipeline import llm_backend, profiles
|
from clipwright.pipeline import llm_backend, profiles
|
||||||
import re
|
import re
|
||||||
|
|
@ -1470,6 +1471,25 @@ async def lifespan(app: FastAPI):
|
||||||
yield
|
yield
|
||||||
# Cleanup (optional: cancel worker)
|
# Cleanup (optional: cancel worker)
|
||||||
|
|
||||||
|
# Health probes (Docker, every 5 s) and the dashboard's 2 s job-status poll would
|
||||||
|
# otherwise fill uvicorn's access log with thousands of identical lines and bury
|
||||||
|
# the real job output. Drop those from the access logger only: the requests are
|
||||||
|
# still served normally, just not echoed to the console.
|
||||||
|
_QUIET_ACCESS_PREFIXES = ("/health", "/api/status/")
|
||||||
|
|
||||||
|
|
||||||
|
class _QuietAccessPaths(logging.Filter):
|
||||||
|
"""Suppress access-log lines for health checks and job-status polling."""
|
||||||
|
|
||||||
|
def filter(self, record: logging.LogRecord) -> bool:
|
||||||
|
args = record.args
|
||||||
|
path = args[2] if isinstance(args, tuple) and len(args) >= 3 else ""
|
||||||
|
return not str(path).startswith(_QUIET_ACCESS_PREFIXES)
|
||||||
|
|
||||||
|
|
||||||
|
logging.getLogger("uvicorn.access").addFilter(_QuietAccessPaths())
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(lifespan=lifespan)
|
app = FastAPI(lifespan=lifespan)
|
||||||
|
|
||||||
# Free public tools behind the /tools SEO pages: YouTube transcript (existing
|
# Free public tools behind the /tools SEO pages: YouTube transcript (existing
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,9 @@ def _detect_transnetv2(video_path):
|
||||||
threshold = float(os.environ.get("TRANSNETV2_THRESHOLD", "0.5"))
|
threshold = float(os.environ.get("TRANSNETV2_THRESHOLD", "0.5"))
|
||||||
|
|
||||||
with _TN2_LOCK, torch.no_grad():
|
with _TN2_LOCK, torch.no_grad():
|
||||||
tensor = torch.from_numpy(np.ascontiguousarray(frames)).to(model.device)
|
# frombuffer() yields a read-only array; copy so torch stops warning and
|
||||||
|
# writing to the tensor is well-defined.
|
||||||
|
tensor = torch.from_numpy(np.array(frames, copy=True)).to(model.device)
|
||||||
single_frame_pred, _ = model.predict_frames(tensor, quiet=True)
|
single_frame_pred, _ = model.predict_frames(tensor, quiet=True)
|
||||||
single_frame_pred = single_frame_pred.cpu()
|
single_frame_pred = single_frame_pred.cpu()
|
||||||
del tensor
|
del tensor
|
||||||
|
|
|
||||||
33
dashboard/package-lock.json
generated
33
dashboard/package-lock.json
generated
|
|
@ -1469,12 +1469,16 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/baseline-browser-mapping": {
|
"node_modules/baseline-browser-mapping": {
|
||||||
"version": "2.9.11",
|
"version": "2.11.27",
|
||||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.11.tgz",
|
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.27.tgz",
|
||||||
"integrity": "sha512-Sg0xJUNDU1sJNGdfGWhVHX0kkZ+HWcvmVymJbj6NSgZZmW/8S9Y2HQ5euytnIgakgxN6papOAWiwDo1ctFDcoQ==",
|
"integrity": "sha512-ElY12DaROGuan+lMmZ8Cvo/ZUbXPe7Enc/9VU/b1T3Kp4dwytRcNdR8DoSJN5SNJT/CuvcCA0DHDVmMOCePdRQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"baseline-browser-mapping": "dist/cli.js"
|
"baseline-browser-mapping": "dist/cli.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/binary-extensions": {
|
"node_modules/binary-extensions": {
|
||||||
|
|
@ -1614,9 +1618,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001761",
|
"version": "1.0.30001814",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001814.tgz",
|
||||||
"integrity": "sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==",
|
"integrity": "sha512-/Uaf1lAzr59XcMpW0o96WoEfr+VXK2OX4U9AgFoiSHsVJ4HppnIFUjtYzsyDH2+tgANaQb2/oxYGwCPapN1FpA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|
@ -1631,7 +1635,8 @@
|
||||||
"type": "github",
|
"type": "github",
|
||||||
"url": "https://github.com/sponsors/ai"
|
"url": "https://github.com/sponsors/ai"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"license": "CC-BY-4.0"
|
||||||
},
|
},
|
||||||
"node_modules/chalk": {
|
"node_modules/chalk": {
|
||||||
"version": "4.1.2",
|
"version": "4.1.2",
|
||||||
|
|
@ -6174,9 +6179,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"baseline-browser-mapping": {
|
"baseline-browser-mapping": {
|
||||||
"version": "2.9.11",
|
"version": "2.11.27",
|
||||||
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.9.11.tgz",
|
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.11.27.tgz",
|
||||||
"integrity": "sha512-Sg0xJUNDU1sJNGdfGWhVHX0kkZ+HWcvmVymJbj6NSgZZmW/8S9Y2HQ5euytnIgakgxN6papOAWiwDo1ctFDcoQ==",
|
"integrity": "sha512-ElY12DaROGuan+lMmZ8Cvo/ZUbXPe7Enc/9VU/b1T3Kp4dwytRcNdR8DoSJN5SNJT/CuvcCA0DHDVmMOCePdRQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"binary-extensions": {
|
"binary-extensions": {
|
||||||
|
|
@ -6262,9 +6267,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"caniuse-lite": {
|
"caniuse-lite": {
|
||||||
"version": "1.0.30001761",
|
"version": "1.0.30001814",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001761.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001814.tgz",
|
||||||
"integrity": "sha512-JF9ptu1vP2coz98+5051jZ4PwQgd2ni8A+gYSN7EA7dPKIMf0pDlSUxhdmVOaV3/fYK5uWBkgSXJaRLr4+3A6g==",
|
"integrity": "sha512-/Uaf1lAzr59XcMpW0o96WoEfr+VXK2OX4U9AgFoiSHsVJ4HppnIFUjtYzsyDH2+tgANaQb2/oxYGwCPapN1FpA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"chalk": {
|
"chalk": {
|
||||||
|
|
|
||||||
|
|
@ -474,9 +474,11 @@ function App() {
|
||||||
let interval;
|
let interval;
|
||||||
if ((status === 'processing' || status === 'completed') && jobId) {
|
if ((status === 'processing' || status === 'completed') && jobId) {
|
||||||
interval = setInterval(async () => {
|
interval = setInterval(async () => {
|
||||||
|
// Skip a backgrounded tab: with the dashboard open in several tabs the
|
||||||
|
// hidden ones kept polling /api/status and flooding the access log.
|
||||||
|
if (document.hidden) return;
|
||||||
try {
|
try {
|
||||||
const data = await pollJob(jobId);
|
const data = await pollJob(jobId);
|
||||||
console.log("Job status:", data);
|
|
||||||
|
|
||||||
// Update results if available (real-time)
|
// Update results if available (real-time)
|
||||||
if (data.result) {
|
if (data.result) {
|
||||||
|
|
@ -705,8 +707,12 @@ function App() {
|
||||||
});
|
});
|
||||||
if (!createRes.ok) throw new Error(`Handoff upload failed: ${readableError(await createRes.text())}`);
|
if (!createRes.ok) throw new Error(`Handoff upload failed: ${readableError(await createRes.text())}`);
|
||||||
const slot = await createRes.json();
|
const slot = await createRes.json();
|
||||||
if (!slot?.upload_url) throw new Error('Handoff upload failed: the server returned no upload URL.');
|
if (!slot?.upload_id) throw new Error('Handoff upload failed: the server returned no upload id.');
|
||||||
const putRes = await apiFetch(slot.upload_url, {
|
// PUT through the app's own API base rather than the absolute
|
||||||
|
// `upload_url` the server returns: behind the dev proxy that URL's host
|
||||||
|
// is the Docker-internal `backend:8000`, which the browser cannot
|
||||||
|
// resolve, so the request dies with a bare "Failed to fetch".
|
||||||
|
const putRes = await apiFetch(`/api/uploads/${encodeURIComponent(slot.upload_id)}`, {
|
||||||
method: slot.method || 'PUT',
|
method: slot.method || 'PUT',
|
||||||
headers: { 'Content-Type': 'application/zip' },
|
headers: { 'Content-Type': 'application/zip' },
|
||||||
body: data.handoffFile,
|
body: data.handoffFile,
|
||||||
|
|
@ -716,6 +722,11 @@ function App() {
|
||||||
handoffId = putData.upload_id || slot.upload_id || null;
|
handoffId = putData.upload_id || slot.upload_id || null;
|
||||||
if (!handoffId) throw new Error('Handoff upload failed: the server returned no upload id.');
|
if (!handoffId) throw new Error('Handoff upload failed: the server returned no upload id.');
|
||||||
setLogs((l) => [...l, 'Handoff bundle attached — transcription will be skipped.']);
|
setLogs((l) => [...l, 'Handoff bundle attached — transcription will be skipped.']);
|
||||||
|
} catch (e) {
|
||||||
|
const msg = e?.message || String(e);
|
||||||
|
throw new Error(
|
||||||
|
msg.startsWith('Handoff upload failed') ? msg : `Handoff upload failed: ${msg}`,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
setHandoffUploading(false);
|
setHandoffUploading(false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
tests/test_access_log_filter.py
Normal file
34
tests/test_access_log_filter.py
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
"""The access-log filter that hides health checks and job-status polling."""
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from clipwright.api.app import _QuietAccessPaths
|
||||||
|
|
||||||
|
|
||||||
|
def _record(path):
|
||||||
|
return logging.LogRecord(
|
||||||
|
"uvicorn.access", logging.INFO, __file__, 1, "msg",
|
||||||
|
("1.2.3.4", "GET", path, "HTTP/1.1", 200), None,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_drops_health_and_status_lines():
|
||||||
|
f = _QuietAccessPaths()
|
||||||
|
assert f.filter(_record("/health")) is False
|
||||||
|
assert f.filter(_record("/health/ready")) is False
|
||||||
|
assert f.filter(_record("/api/status/4c533b81-ef05-4b51-80a3-137046577888")) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_keeps_real_requests():
|
||||||
|
f = _QuietAccessPaths()
|
||||||
|
assert f.filter(_record("/api/config")) is True
|
||||||
|
assert f.filter(_record("/api/uploads/abc")) is True
|
||||||
|
assert f.filter(_record("/videos/job/clip.mp4")) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_survives_unexpected_record_args():
|
||||||
|
# uvicorn access records always carry the args tuple, but a filter must never
|
||||||
|
# raise on a differently-shaped record.
|
||||||
|
f = _QuietAccessPaths()
|
||||||
|
rec = logging.LogRecord("uvicorn.access", logging.INFO, __file__, 1, "msg", None, None)
|
||||||
|
assert f.filter(rec) is True
|
||||||
Loading…
Reference in a new issue