mirror of
https://github.com/xpltdco/media-rip.git
synced 2026-04-03 02:53:58 -06:00
Fix ruff lint errors: unused imports, E402 import ordering
This commit is contained in:
parent
8eaeef6fcf
commit
aeb3238b84
18 changed files with 12 additions and 42 deletions
|
|
@ -14,6 +14,9 @@ from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
|
from starlette.requests import Request as StarletteRequest
|
||||||
|
from starlette.responses import Response
|
||||||
|
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
from app.core.database import close_db, init_db
|
from app.core.database import close_db, init_db
|
||||||
|
|
@ -109,9 +112,6 @@ app.add_middleware(SessionMiddleware)
|
||||||
|
|
||||||
|
|
||||||
# --- Security headers middleware (R020: zero outbound telemetry) ---
|
# --- Security headers middleware (R020: zero outbound telemetry) ---
|
||||||
from starlette.middleware.base import BaseHTTPMiddleware
|
|
||||||
from starlette.requests import Request as StarletteRequest
|
|
||||||
from starlette.responses import Response
|
|
||||||
|
|
||||||
|
|
||||||
class SecurityHeadersMiddleware(BaseHTTPMiddleware):
|
class SecurityHeadersMiddleware(BaseHTTPMiddleware):
|
||||||
|
|
@ -150,7 +150,6 @@ app.include_router(themes_router, prefix="/api")
|
||||||
# --- Static file serving (production: built frontend) ---
|
# --- Static file serving (production: built frontend) ---
|
||||||
_static_dir = Path(__file__).resolve().parent.parent / "static"
|
_static_dir = Path(__file__).resolve().parent.parent / "static"
|
||||||
if _static_dir.is_dir():
|
if _static_dir.is_dir():
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
|
||||||
@app.get("/{full_path:path}")
|
@app.get("/{full_path:path}")
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ class SessionMiddleware(BaseHTTPMiddleware):
|
||||||
|
|
||||||
# --- Resolve or create session ---
|
# --- Resolve or create session ---
|
||||||
cookie_value = request.cookies.get("mrip_session")
|
cookie_value = request.cookies.get("mrip_session")
|
||||||
new_session = False
|
|
||||||
|
|
||||||
if cookie_value and _is_valid_uuid4(cookie_value):
|
if cookie_value and _is_valid_uuid4(cookie_value):
|
||||||
session_id = cookie_value
|
session_id = cookie_value
|
||||||
|
|
@ -54,13 +53,11 @@ class SessionMiddleware(BaseHTTPMiddleware):
|
||||||
else:
|
else:
|
||||||
# Valid UUID but not in DB (expired/purged) — recreate
|
# Valid UUID but not in DB (expired/purged) — recreate
|
||||||
await create_session(db, session_id)
|
await create_session(db, session_id)
|
||||||
new_session = True
|
|
||||||
logger.info("Session recreated (cookie valid, DB miss): %s", session_id)
|
logger.info("Session recreated (cookie valid, DB miss): %s", session_id)
|
||||||
else:
|
else:
|
||||||
# Missing or invalid cookie — brand new session
|
# Missing or invalid cookie — brand new session
|
||||||
session_id = str(uuid.uuid4())
|
session_id = str(uuid.uuid4())
|
||||||
await create_session(db, session_id)
|
await create_session(db, session_id)
|
||||||
new_session = True
|
|
||||||
logger.info("New session created: %s", session_id)
|
logger.info("New session created: %s", session_id)
|
||||||
|
|
||||||
request.state.session_id = session_id
|
request.state.session_id = session_id
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Request, UploadFile
|
from fastapi import APIRouter, Depends, Request, UploadFile
|
||||||
|
|
||||||
from app.dependencies import get_session_id
|
from app.dependencies import get_session_id
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ async def cancel_download(
|
||||||
"""Delete a download job and remove its file."""
|
"""Delete a download job and remove its file."""
|
||||||
logger.debug("DELETE /downloads/%s", job_id)
|
logger.debug("DELETE /downloads/%s", job_id)
|
||||||
db = request.app.state.db
|
db = request.app.state.db
|
||||||
download_service = request.app.state.download_service
|
|
||||||
|
|
||||||
# Fetch the job first to get its session_id and filename
|
# Fetch the job first to get its session_id and filename
|
||||||
job = await get_job(db, job_id)
|
job = await get_job(db, job_id)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@ import yt_dlp
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
from app.core.database import (
|
from app.core.database import (
|
||||||
create_job,
|
create_job,
|
||||||
get_job,
|
|
||||||
update_job_progress,
|
update_job_progress,
|
||||||
update_job_status,
|
update_job_status,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import base64
|
import base64
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
|
|
@ -13,9 +12,8 @@ from fastapi import FastAPI
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
from app.core.database import close_db, init_db, create_session, create_job
|
from app.core.database import close_db, init_db
|
||||||
from app.middleware.session import SessionMiddleware
|
from app.middleware.session import SessionMiddleware
|
||||||
from app.models.job import Job
|
|
||||||
from app.routers.admin import router as admin_router
|
from app.routers.admin import router as admin_router
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,8 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
import tempfile
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import asyncio
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from app.core.database import (
|
from app.core.database import (
|
||||||
close_db,
|
close_db,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ and unit tests that only touch the database.
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
@ -104,7 +103,7 @@ async def test_real_download_produces_file_and_events(download_env):
|
||||||
|
|
||||||
# At least one event should have non-zero percent
|
# At least one event should have non-zero percent
|
||||||
downloading_events = [e for e in events if e.status == "downloading"]
|
downloading_events = [e for e in events if e.status == "downloading"]
|
||||||
has_progress = any(e.percent > 0 for e in downloading_events)
|
any(e.percent > 0 for e in downloading_events)
|
||||||
# Some very short videos may not report intermediate progress —
|
# Some very short videos may not report intermediate progress —
|
||||||
# we still assert downloading events exist
|
# we still assert downloading events exist
|
||||||
assert len(downloading_events) > 0
|
assert len(downloading_events) > 0
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import uuid
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
import pytest_asyncio
|
||||||
|
|
@ -12,9 +10,8 @@ from fastapi import FastAPI
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
from app.core.database import close_db, init_db, create_job
|
from app.core.database import close_db, init_db
|
||||||
from app.middleware.session import SessionMiddleware
|
from app.middleware.session import SessionMiddleware
|
||||||
from app.models.job import Job
|
|
||||||
from app.routers.cookies import router as cookies_router
|
from app.routers.cookies import router as cookies_router
|
||||||
from app.routers.files import router as files_router
|
from app.routers.files import router as files_router
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,10 @@ Covers:
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import json
|
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
|
||||||
|
|
||||||
from app.core.database import (
|
from app.core.database import (
|
||||||
create_job,
|
create_job,
|
||||||
|
|
@ -22,7 +20,7 @@ from app.core.database import (
|
||||||
get_jobs_by_mode,
|
get_jobs_by_mode,
|
||||||
get_queue_depth,
|
get_queue_depth,
|
||||||
)
|
)
|
||||||
from app.models.job import Job, JobStatus
|
from app.models.job import Job
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
@ -129,7 +127,6 @@ class TestPublicConfig:
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_public_config_reflects_actual_config(self, tmp_path):
|
async def test_public_config_reflects_actual_config(self, tmp_path):
|
||||||
"""Config values in the response match what AppConfig was built with."""
|
"""Config values in the response match what AppConfig was built with."""
|
||||||
import asyncio
|
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
@ -137,7 +134,6 @@ class TestPublicConfig:
|
||||||
|
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
from app.core.database import close_db, init_db
|
from app.core.database import close_db, init_db
|
||||||
from app.core.sse_broker import SSEBroker
|
|
||||||
from app.middleware.session import SessionMiddleware
|
from app.middleware.session import SessionMiddleware
|
||||||
from app.routers.system import router as system_router
|
from app.routers.system import router as system_router
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from app.models.job import (
|
from app.models.job import (
|
||||||
FormatInfo,
|
FormatInfo,
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,11 @@ from __future__ import annotations
|
||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import pytest_asyncio
|
|
||||||
|
|
||||||
from app.core.config import AppConfig
|
from app.core.config import AppConfig
|
||||||
from app.core.database import create_job, init_db, close_db
|
from app.core.database import create_job
|
||||||
from app.models.job import Job
|
from app.models.job import Job
|
||||||
from app.services.purge import run_purge
|
from app.services.purge import run_purge
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,12 @@ import contextlib
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from unittest.mock import AsyncMock, patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from app.core.database import create_job, create_session, get_active_jobs_by_session
|
from app.core.database import create_job, create_session, get_active_jobs_by_session
|
||||||
from app.core.sse_broker import SSEBroker
|
from app.models.job import Job, ProgressEvent
|
||||||
from app.models.job import Job, JobStatus, ProgressEvent
|
from app.routers.sse import event_generator
|
||||||
from app.routers.sse import KEEPALIVE_TIMEOUT, event_generator
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
||||||
import asyncio
|
import asyncio
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from app.core.sse_broker import SSEBroker
|
from app.core.sse_broker import SSEBroker
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue