update to get favicon from compontent by using the storage
Build and Push Docker Container / build-and-push (push) Successful in 1m36s
Build and Push Docker Container / build-and-push (push) Successful in 1m36s
This commit is contained in:
+1
-1
Submodule my_helpers updated: 4b582a3610...f48c4e1b4f
@@ -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.AsyncCache import AsyncCache
|
||||
from my_modules.app.logger import logger
|
||||
|
||||
from my_helpers.db.convex.ConvexRuntime import ConvexRuntime
|
||||
from my_modules.db.ConvexDB import ConvexDB
|
||||
|
||||
from quart_session import Session
|
||||
@@ -64,10 +66,12 @@ LIMITER = Limiter(
|
||||
strategy='moving-window'
|
||||
)
|
||||
|
||||
convex_runtime = ConvexRuntime(os.getenv("CONVEX_URL"))
|
||||
|
||||
@app.before_serving
|
||||
async def init_convex():
|
||||
app.convex = ConvexDB(os.getenv("CONVEX_URL"))
|
||||
await app.convex.connect()
|
||||
await convex_runtime.start()
|
||||
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(await get_my_ip_address())
|
||||
@@ -81,5 +85,5 @@ async def init_convex():
|
||||
@app.after_serving
|
||||
async def close_convex():
|
||||
if app.convex:
|
||||
await app.convex.close()
|
||||
await convex_runtime.stop()
|
||||
await logger.shutdown()
|
||||
|
||||
+22
-25
@@ -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 convex import ConvexError, ConvexExecutionError
|
||||
from datetime import datetime
|
||||
|
||||
class ConvexDB(ConvexDbBase):
|
||||
service_namespace = 'nanoshare'
|
||||
|
||||
def __init__(self, dsn:str):
|
||||
super().__init__(dsn=dsn, service=ConvexDB.service_namespace)
|
||||
def __init__(self, runtime:ConvexRuntime):
|
||||
super().__init__(
|
||||
runtime=runtime,
|
||||
service=ConvexDB.service_namespace
|
||||
)
|
||||
|
||||
# File Quary Functions
|
||||
async def get_file(self, file_id:str):
|
||||
data = await self.run_query_with_reconnection(
|
||||
self.client.query,
|
||||
f"{self.service_namespace}/files:getByFileId",
|
||||
data = await self.run_query(
|
||||
name='files:getByFileId',
|
||||
args={ 'file_id': file_id }
|
||||
)
|
||||
return data
|
||||
|
||||
async def get_files(self, user_id:str):
|
||||
data = await self.run_query_with_reconnection(
|
||||
self.client.query,
|
||||
f"{self.service_namespace}/files:getAllNotExpired",
|
||||
data = await self.run_query(
|
||||
name='files:getAllNotExpired',
|
||||
args={ 'user_id': user_id }
|
||||
)
|
||||
return [ {
|
||||
@@ -43,24 +45,21 @@ class ConvexDB(ConvexDbBase):
|
||||
if expires_at:
|
||||
args['expires_at'] = expires_at.isoformat()
|
||||
|
||||
data = await self.run_query_with_reconnection(
|
||||
self.client.mutation,
|
||||
f"{self.service_namespace}/files:addNewFile",
|
||||
data = await self.run_mutation(
|
||||
name='files:addNewFile',
|
||||
args=args,
|
||||
)
|
||||
return data
|
||||
|
||||
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(
|
||||
self.client.mutation,
|
||||
f"{self.service_namespace}/files:updateFile",
|
||||
await self.run_mutation(
|
||||
name='files:updateFile',
|
||||
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):
|
||||
await self.run_query_with_reconnection(
|
||||
self.client.mutation,
|
||||
f"{self.service_namespace}/files:deleteFile",
|
||||
await self.run_mutation(
|
||||
name='files:deleteFile',
|
||||
args={ 'file_id': file_id, 'user_id': user_id }
|
||||
)
|
||||
|
||||
@@ -69,17 +68,15 @@ class ConvexDB(ConvexDbBase):
|
||||
|
||||
# File Access Quary Functions
|
||||
async def add_file_access(self, file_id: str, ip_address:str, status:str, user_agent:str):
|
||||
data = await self.run_query_with_reconnection(
|
||||
self.client.mutation,
|
||||
f"{self.service_namespace}/access:addNewAccess",
|
||||
data = await self.run_mutation(
|
||||
name='access:addNewAccess',
|
||||
args={ 'file_id': file_id, 'ip_address': ip_address, 'user_agent': str(user_agent), 'status': status }
|
||||
)
|
||||
return data
|
||||
|
||||
async def get_all_access(self, user_id:str):
|
||||
data = await self.run_query_with_reconnection(
|
||||
self.client.query,
|
||||
f"{self.service_namespace}/access:getAllByUser",
|
||||
data = await self.run_query(
|
||||
name='access:getAllByUser',
|
||||
args={ 'user_id': user_id }
|
||||
)
|
||||
return data
|
||||
|
||||
@@ -19,7 +19,8 @@ async def robots():
|
||||
|
||||
@basic_bp.route("/storage/<path:file_id>")
|
||||
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 Response(
|
||||
|
||||
Reference in New Issue
Block a user