add code to convert datetime into localtime into file list and add access quarys
This commit is contained in:
+7
-12
@@ -1,5 +1,6 @@
|
||||
from my_modules.file_helper_functions import verify_signed_url
|
||||
from my_modules.file_helper_functions import is_expired, verify_signed_url
|
||||
from my_modules.decoratory.header import login_required
|
||||
from my_modules.functions import get_ip
|
||||
from my_modules.app.setup import LIMITER
|
||||
from my_modules.app.logger import logger
|
||||
|
||||
@@ -22,29 +23,20 @@ async def files(user):
|
||||
files_data = await current_app.edgedb.get_files(current_datetime=datetime.now(timezone.utc), user_id=user['sub'])
|
||||
return await render_template("views/webpage/files_list.htm", files=files_data)
|
||||
|
||||
@side_main_bp.route('/files/<file_id>/info')
|
||||
@side_main_bp.route('/files/<path:file_id>/info')
|
||||
@LIMITER.limit("10 per minute")
|
||||
@login_required
|
||||
async def file_info(file_id, user):
|
||||
files_data = await current_app.edgedb.get_files(user_id=user['sub'])
|
||||
return await render_template("views/webpage/.htm", files=files_data)
|
||||
|
||||
@side_main_bp.route('/files/<file_id>/edit')
|
||||
@side_main_bp.route('/files/<path:file_id>/edit')
|
||||
@LIMITER.limit("10 per minute")
|
||||
@login_required
|
||||
async def file_edit(file_id, user):
|
||||
files_data = await current_app.edgedb.get_files(user_id=user['sub'])
|
||||
return await render_template("views/webpage/.htm", files=files_data)
|
||||
|
||||
def is_expired(expires_at):
|
||||
if not expires_at:
|
||||
return False
|
||||
if expires_at.tzinfo is None:
|
||||
expires_at = expires_at.replace(tzinfo=timezone.utc)
|
||||
else:
|
||||
expires_at = expires_at.astimezone(timezone.utc)
|
||||
return expires_at <= datetime.now(timezone.utc)
|
||||
|
||||
@side_main_bp.route("/-<file_id>")
|
||||
@LIMITER.limit("10 per minute")
|
||||
async def serve_file(file_id: str):
|
||||
@@ -53,6 +45,7 @@ async def serve_file(file_id: str):
|
||||
abort(404)
|
||||
|
||||
if is_expired(file_data.get("expires_at")):
|
||||
await current_app.edgedb.add_file_access(file_id=file_id, ip_address=get_ip(), user_agent=request.user_agent, status="expired", accessed_at=datetime.now(timezone.utc))
|
||||
return Response("This file has expired.", status=410, headers={
|
||||
"Cache-Control": "no-store",
|
||||
"X-Content-Type-Options": "nosniff",
|
||||
@@ -65,8 +58,10 @@ async def serve_file(file_id: str):
|
||||
|
||||
path = current_app.upload_folder / file_name
|
||||
if not path.exists() or not path.is_file():
|
||||
await current_app.edgedb.add_file_access(file_id=file_id, ip_address=get_ip(), user_agent=request.user_agent, status="error", accessed_at=datetime.now(timezone.utc))
|
||||
abort(404)
|
||||
|
||||
await current_app.edgedb.add_file_access(file_id=file_id, ip_address=get_ip(), user_agent=request.user_agent, status="ok", accessed_at=datetime.now(timezone.utc))
|
||||
return await send_from_directory(
|
||||
directory=current_app.upload_folder,
|
||||
file_name=file_name,
|
||||
|
||||
Reference in New Issue
Block a user