update to get favicon from compontent by using the storage
Build and Push Docker Container / build-and-push (push) Successful in 1m36s

This commit is contained in:
2026-02-16 12:02:52 +01:00
parent e8e37e8967
commit 6137121209
4 changed files with 32 additions and 30 deletions
+7 -3
View File
@@ -2,6 +2,8 @@ from my_modules.functions import custom_limit_key, get_my_ip_address, get_local_
from my_modules.app.constens import SECRET_KEY, THE_IP_BOT_MANAGER from my_modules.app.constens import SECRET_KEY, THE_IP_BOT_MANAGER
from my_modules.AsyncCache import AsyncCache from my_modules.AsyncCache import AsyncCache
from my_modules.app.logger import logger from my_modules.app.logger import logger
from my_helpers.db.convex.ConvexRuntime import ConvexRuntime
from my_modules.db.ConvexDB import ConvexDB from my_modules.db.ConvexDB import ConvexDB
from quart_session import Session from quart_session import Session
@@ -64,10 +66,12 @@ LIMITER = Limiter(
strategy='moving-window' strategy='moving-window'
) )
convex_runtime = ConvexRuntime(os.getenv("CONVEX_URL"))
@app.before_serving @app.before_serving
async def init_convex(): async def init_convex():
app.convex = ConvexDB(os.getenv("CONVEX_URL")) await convex_runtime.start()
await app.convex.connect() app.convex = ConvexDB(runtime=convex_runtime)
THE_IP_BOT_MANAGER.add_always_allowed_ip('127.0.0.1') THE_IP_BOT_MANAGER.add_always_allowed_ip('127.0.0.1')
THE_IP_BOT_MANAGER.add_always_allowed_ip(await get_my_ip_address()) THE_IP_BOT_MANAGER.add_always_allowed_ip(await get_my_ip_address())
@@ -81,5 +85,5 @@ async def init_convex():
@app.after_serving @app.after_serving
async def close_convex(): async def close_convex():
if app.convex: if app.convex:
await app.convex.close() await convex_runtime.stop()
await logger.shutdown() await logger.shutdown()
+22 -25
View File
@@ -1,28 +1,30 @@
from my_helpers.ConvexDbBase import ConvexDbBase from my_helpers.db.convex.ConvexDbBase import ConvexDbBase
from my_helpers.db.convex.ConvexRuntime import ConvexRuntime
from my_modules.app.logger import logger from my_modules.app.logger import logger
from convex import ConvexError, ConvexExecutionError
from datetime import datetime from datetime import datetime
class ConvexDB(ConvexDbBase): class ConvexDB(ConvexDbBase):
service_namespace = 'nanoshare' service_namespace = 'nanoshare'
def __init__(self, dsn:str): def __init__(self, runtime:ConvexRuntime):
super().__init__(dsn=dsn, service=ConvexDB.service_namespace) super().__init__(
runtime=runtime,
service=ConvexDB.service_namespace
)
# File Quary Functions # File Quary Functions
async def get_file(self, file_id:str): async def get_file(self, file_id:str):
data = await self.run_query_with_reconnection( data = await self.run_query(
self.client.query, name='files:getByFileId',
f"{self.service_namespace}/files:getByFileId",
args={ 'file_id': file_id } args={ 'file_id': file_id }
) )
return data return data
async def get_files(self, user_id:str): async def get_files(self, user_id:str):
data = await self.run_query_with_reconnection( data = await self.run_query(
self.client.query, name='files:getAllNotExpired',
f"{self.service_namespace}/files:getAllNotExpired",
args={ 'user_id': user_id } args={ 'user_id': user_id }
) )
return [ { return [ {
@@ -43,24 +45,21 @@ class ConvexDB(ConvexDbBase):
if expires_at: if expires_at:
args['expires_at'] = expires_at.isoformat() args['expires_at'] = expires_at.isoformat()
data = await self.run_query_with_reconnection( data = await self.run_mutation(
self.client.mutation, name='files:addNewFile',
f"{self.service_namespace}/files:addNewFile",
args=args, args=args,
) )
return data return data
async def update_file(self, file_id:str, file_name:str, note:str, expires_at:datetime, user_id:str): async def update_file(self, file_id:str, file_name:str, note:str, expires_at:datetime, user_id:str):
await self.run_query_with_reconnection( await self.run_mutation(
self.client.mutation, name='files:updateFile',
f"{self.service_namespace}/files:updateFile",
args={ 'file_id': file_id, 'file_name': file_name, 'note': note, 'expires_at': expires_at.isoformat(), 'user_id': user_id } args={ 'file_id': file_id, 'file_name': file_name, 'note': note, 'expires_at': expires_at.isoformat(), 'user_id': user_id }
) )
async def delete_file(self, file_id:str, user_id:str): async def delete_file(self, file_id:str, user_id:str):
await self.run_query_with_reconnection( await self.run_mutation(
self.client.mutation, name='files:deleteFile',
f"{self.service_namespace}/files:deleteFile",
args={ 'file_id': file_id, 'user_id': user_id } args={ 'file_id': file_id, 'user_id': user_id }
) )
@@ -69,17 +68,15 @@ class ConvexDB(ConvexDbBase):
# File Access Quary Functions # File Access Quary Functions
async def add_file_access(self, file_id: str, ip_address:str, status:str, user_agent:str): async def add_file_access(self, file_id: str, ip_address:str, status:str, user_agent:str):
data = await self.run_query_with_reconnection( data = await self.run_mutation(
self.client.mutation, name='access:addNewAccess',
f"{self.service_namespace}/access:addNewAccess",
args={ 'file_id': file_id, 'ip_address': ip_address, 'user_agent': str(user_agent), 'status': status } args={ 'file_id': file_id, 'ip_address': ip_address, 'user_agent': str(user_agent), 'status': status }
) )
return data return data
async def get_all_access(self, user_id:str): async def get_all_access(self, user_id:str):
data = await self.run_query_with_reconnection( data = await self.run_query(
self.client.query, name='access:getAllByUser',
f"{self.service_namespace}/access:getAllByUser",
args={ 'user_id': user_id } args={ 'user_id': user_id }
) )
return data return data
+2 -1
View File
@@ -19,7 +19,8 @@ async def robots():
@basic_bp.route("/storage/<path:file_id>") @basic_bp.route("/storage/<path:file_id>")
async def convex_storage_proxy(file_id:str): async def convex_storage_proxy(file_id:str):
if not is_valid_uuid(file_id): clean_file_id = file_id.split("?", 1)[0]
if not is_valid_uuid(clean_file_id):
return abort(404, "Not a valid uuid") return abort(404, "Not a valid uuid")
return Response( return Response(