ruff + mypy pass
This commit is contained in:
parent
607213f1c4
commit
f4fbfa3155
3 changed files with 9 additions and 21 deletions
|
@ -1,5 +1,4 @@
|
||||||
from sqlalchemy import MetaData, Table, Column, Integer, String, ForeignKey
|
from sqlalchemy import Column, Integer, String, ForeignKey
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
from sqlalchemy.orm import DeclarativeBase, relationship, Mapped, mapped_column
|
from sqlalchemy.orm import DeclarativeBase, relationship, Mapped, mapped_column
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import os
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -6,13 +5,12 @@ import aiofiles
|
||||||
import tempfile
|
import tempfile
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
import toml
|
|
||||||
import magic
|
import magic
|
||||||
|
|
||||||
import sqlalchemy.exc
|
import sqlalchemy.exc
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
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.requests import Request
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
@ -91,7 +89,7 @@ async def upload(
|
||||||
conn.add(orig)
|
conn.add(orig)
|
||||||
try:
|
try:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
except sqlalchemy.exc.IntegrityError as exc:
|
except sqlalchemy.exc.IntegrityError:
|
||||||
conn.rollback()
|
conn.rollback()
|
||||||
conflicting = (
|
conflicting = (
|
||||||
conn.query(database.Original)
|
conn.query(database.Original)
|
||||||
|
@ -104,18 +102,19 @@ async def upload(
|
||||||
detail = "File is already in the archive"
|
detail = "File is already in the archive"
|
||||||
raise HTTPException(status_code=400, detail=detail)
|
raise HTTPException(status_code=400, detail=detail)
|
||||||
conn.refresh(orig)
|
conn.refresh(orig)
|
||||||
data = {
|
|
||||||
|
output_data = {
|
||||||
"id": orig.id,
|
"id": orig.id,
|
||||||
"path": orig.filepath,
|
"path": orig.filepath,
|
||||||
"url": CONFIG["public"]["baseurl"] + "/dl/" + orig.filepath,
|
"url": CONFIG["public"]["baseurl"] + "/dl/" + orig.filepath,
|
||||||
}
|
}
|
||||||
if "application/json" in request.headers.get("accept", ""):
|
if "application/json" in request.headers.get("accept", ""):
|
||||||
return data
|
return output_data
|
||||||
else:
|
else:
|
||||||
return templates.TemplateResponse(
|
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()
|
Path(temp.name).unlink()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,12 @@
|
||||||
import os
|
|
||||||
from pathlib import Path
|
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 import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker, joinedload
|
from sqlalchemy.orm import sessionmaker, joinedload
|
||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
from fastapi.requests import Request
|
|
||||||
from fastapi.responses import RedirectResponse, FileResponse
|
from fastapi.responses import RedirectResponse, FileResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
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
|
from caricari import database
|
||||||
|
|
||||||
CONFIG = get_config()
|
CONFIG = get_config()
|
||||||
|
|
Loading…
Reference in a new issue