diff --git a/my_modules/EdgeDB.py b/my_modules/EdgeDB.py index df94fc0..0a6aaac 100644 --- a/my_modules/EdgeDB.py +++ b/my_modules/EdgeDB.py @@ -276,6 +276,40 @@ class EdgeDB: "accessed_at": file.at, } for file in data] + async def get_all_access_of_user(self, user_id:str): + data = await self.run_query_with_reconnection( + self.client.query, + """ + select files { + file_id, + file_name, + note, + accesses: { + at, + status, + ip: { + value + }, + user_agent: { + value + } + } + order by .at desc + } + filter .user_id = $user_id + """, + user_id=user_id + ) + return sorted([{ + "file_id": file.file_id, + "file_name": file.file_name, + "file_note": file.note, + "status": access.status, + "ip": access.ip.value, + "user_agent": access.user_agent.value, + "accessed_at": access.at, + } for file in data for access in file.accesses], key=lambda x: x["accessed_at"], reverse=True) + async def get_file_access(self, file_id: str): data = await self.run_query_with_reconnection( self.client.query_single, diff --git a/routes/side/main.py b/routes/side/main.py index 05b198e..5dd66d2 100644 --- a/routes/side/main.py +++ b/routes/side/main.py @@ -19,7 +19,7 @@ async def index(): @side_main_bp.route('/access') @login_required async def access_list(user): - access_data = await current_app.edgedb.get_all_file_access() + access_data = await current_app.edgedb.get_all_access_of_user(user_id=user['sub']) return await render_template("views/webpage/access/list.htm", access_logs=access_data) @side_main_bp.route('/files') @@ -54,7 +54,7 @@ async def serve_file(file_id: str): disable_logging = True if is_expired(file_data.get("expires_at")): - if disable_logging: + if not disable_logging: 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", @@ -68,11 +68,11 @@ async def serve_file(file_id: str): path = current_app.upload_folder / file_name if not path.exists() or not path.is_file(): - if disable_logging: + if not disable_logging: 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) - if disable_logging: + if not disable_logging: 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, diff --git a/templates/side/views/webpage/access/list.htm b/templates/side/views/webpage/access/list.htm index 2b55b0b..cad8fc6 100644 --- a/templates/side/views/webpage/access/list.htm +++ b/templates/side/views/webpage/access/list.htm @@ -12,13 +12,15 @@

Accesslog

-

Your uploaded files at a glance. Click a filename to open, or use the actions on the right.

+

See when and how others accessed your shared files. Click a filename to open your files

+ + @@ -27,7 +29,11 @@ {% for access in access_logs %} - + + + diff --git a/templates/side/views/webpage/files/list.htm b/templates/side/views/webpage/files/list.htm index 0fc01a4..87e2593 100644 --- a/templates/side/views/webpage/files/list.htm +++ b/templates/side/views/webpage/files/list.htm @@ -19,7 +19,7 @@ - +
Accessed AtFilenameNote (Only Visible to You) Status IP Address User Agent
+ {{ access.file_name }} + {{ access.file_note }} {{ access.status }} {{ access.ip }} {{ access.user_agent }}
FilenameNoteNote (Only Visible to You) Size Uploaded Expires