From f4fbfa3155157d015e5280e774a4116979b7bf61 Mon Sep 17 00:00:00 2001 From: boyska Date: Mon, 2 Dec 2024 17:49:42 +0100 Subject: [PATCH] ruff + mypy pass --- caricari/database.py | 3 +-- caricari/private.py | 15 +++++++-------- caricari/public.py | 12 +----------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/caricari/database.py b/caricari/database.py index 3c4b798..fce0b52 100644 --- a/caricari/database.py +++ b/caricari/database.py @@ -1,5 +1,4 @@ -from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy import Column, Integer, String, ForeignKey from sqlalchemy.orm import DeclarativeBase, relationship, Mapped, mapped_column diff --git a/caricari/private.py b/caricari/private.py index 1b6c457..ac1f83f 100644 --- a/caricari/private.py +++ b/caricari/private.py @@ -1,4 +1,3 @@ -import os from pathlib import Path from typing import Annotated import datetime @@ -6,13 +5,12 @@ import aiofiles import tempfile import hashlib -import toml import magic import sqlalchemy.exc from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from fastapi import FastAPI, UploadFile, File, Header, Form, HTTPException +from fastapi import FastAPI, UploadFile, Header, Form, HTTPException from fastapi.requests import Request from fastapi.responses import RedirectResponse from fastapi.templating import Jinja2Templates @@ -91,7 +89,7 @@ async def upload( conn.add(orig) try: conn.commit() - except sqlalchemy.exc.IntegrityError as exc: + except sqlalchemy.exc.IntegrityError: conn.rollback() conflicting = ( conn.query(database.Original) @@ -104,18 +102,19 @@ async def upload( detail = "File is already in the archive" raise HTTPException(status_code=400, detail=detail) conn.refresh(orig) - data = { + + output_data = { "id": orig.id, "path": orig.filepath, "url": CONFIG["public"]["baseurl"] + "/dl/" + orig.filepath, } if "application/json" in request.headers.get("accept", ""): - return data + return output_data else: return templates.TemplateResponse( - name="ok.html", request=request, context=data + name="ok.html", request=request, context=output_data ) - except Exception as exc: + except Exception: Path(temp.name).unlink() raise diff --git a/caricari/public.py b/caricari/public.py index 14956b8..5a5372a 100644 --- a/caricari/public.py +++ b/caricari/public.py @@ -1,22 +1,12 @@ -import os from pathlib import Path -from typing import Annotated -import datetime -import aiofiles -import tempfile -import hashlib - -import magic from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, joinedload from fastapi import FastAPI, HTTPException -from fastapi.requests import Request from fastapi.responses import RedirectResponse, FileResponse from fastapi.templating import Jinja2Templates -from pydantic import BaseModel -from caricari.httpcommon import ProxyInfo, get_config +from caricari.httpcommon import get_config from caricari import database CONFIG = get_config()