1
0
mirror of https://github.com/aquatix/digimarks.git synced 2025-12-06 22:05:09 +01:00

Merge branch 'fastapi' of github.com:aquatix/digimarks into fastapi

This commit is contained in:
2025-05-04 13:18:12 +02:00

View File

@@ -51,6 +51,7 @@ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
@asynccontextmanager
async def lifespan(the_app: FastAPI):
"""Upon start, initialise an AsyncClient and assign it to an attribute named requests_client on the app object."""
@@ -58,6 +59,7 @@ async def lifespan(the_app: FastAPI):
yield
await the_app.requests_client.aclose()
app = FastAPI(lifespan=lifespan)
templates = Jinja2Templates(directory='templates')
@@ -110,9 +112,9 @@ def unique_ever_seen(iterable, key=None):
def clean_tags(tags_list):
"""Generate unique list of the tags.
"""Generate a unique list of the tags.
:param list tags_list: list with all tags
:param list tags_list: List with all tags
:return: deduplicated list of the tags, without leading or trailing whitespace
:rtype: list
"""
@@ -233,7 +235,9 @@ class Bookmark(Base):
def set_status_code(self, request: Request) -> int:
"""Check the HTTP status of the url, as it might not exist for example."""
try:
result = request.app.requests_client.head(self.url, headers={'User-Agent': DIGIMARKS_USER_AGENT}, timeout=30)
result = request.app.requests_client.head(
self.url, headers={'User-Agent': DIGIMARKS_USER_AGENT}, timeout=30
)
self.http_status = result.status_code
except httpx.HTTPError as err:
logger.error('Failed to do head info fetching for %s: %s', self.url, str(err))
@@ -994,7 +998,7 @@ def add_user(system_key):
new_user.save()
all_tags[new_user.key] = []
return {'user': f'/{new_user.key.decode("utf-8")}'}
raise HTTPException(status_code=404, detail='I can\'t let you do that Dave')
raise HTTPException(status_code=404, detail="I can't let you do that Dave")
@app.route('/<system_key>/refreshfavicons')
@@ -1011,7 +1015,7 @@ def refresh_favicons(system_key):
print(e)
bookmark.set_favicon()
return {'message': 'Done refreshing icons'}
raise HTTPException(status_code=404, detail='I can\'t let you do that Dave')
raise HTTPException(status_code=404, detail="I can't let you do that Dave")
@app.route('/<system_key>/findmissingfavicons')
@@ -1034,7 +1038,8 @@ def find_missing_favicons(request: Request, system_key: str):
except OSError as e:
print(e)
return {'message': 'Done finding missing icons'}
raise HTTPException(status_code=404, detail='I can\'t let you do that Dave')
raise HTTPException(status_code=404, detail="I can't let you do that Dave")
# Initialisation == create the bookmark, user and public tag tables if they do not exist
# TODO: switch to alembic migrations