Skip to content

Commit

Permalink
Add endpoint to download server log
Browse files Browse the repository at this point in the history
  • Loading branch information
derneuere committed Feb 12, 2025
1 parent 4fa48be commit 9ba0060
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/directory_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def scan_faces(user, job_id: UUID, full_scan=False):
photo._extract_faces()
except Exception as err:
util.logger.exception("An error occurred: ")
print("[ERR]: {}".format(err))
print(f"[ERR]: {err}")
failed = True
update_scan_counter(job_id, failed)
except Exception as err:
Expand Down
17 changes: 16 additions & 1 deletion api/views/dataviz.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.http import HttpResponseForbidden
import os

from django.http import FileResponse, HttpResponseForbidden
from drf_spectacular.utils import extend_schema
from rest_framework.response import Response
from rest_framework.views import APIView
Expand Down Expand Up @@ -37,6 +39,19 @@ def get(self, request, format=None):
res = build_social_graph(request.user)
return Response(res)

class ServerLogsView(APIView):
def get(self, request, format=None):
if not (request.user and request.user.is_staff):
return HttpResponseForbidden()

BASE_LOGS = os.environ.get("BASE_LOGS", "/logs/")
log_file = os.path.join(BASE_LOGS, "ownphotos.log")

if os.path.exists(log_file):
return FileResponse(open(log_file, "rb"), as_attachment=True, filename="ownphotos.log")
else:
return Response({"error": "Log file not found"}, status=404)


class ServerStatsView(APIView):
def get(self, request, format=None):
Expand Down
1 change: 1 addition & 0 deletions librephotos/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def post(self, request, *args, **kwargs):
re_path(r"^api/storagestats", views.StorageStatsView.as_view()),
re_path(r"^api/imagetag", views.ImageTagView.as_view()),
re_path(r"^api/serverstats", dataviz.ServerStatsView.as_view()),
re_path(r"^api/serverlogs", dataviz.ServerLogsView.as_view()),
re_path(r"^api/locclust", dataviz.LocationClustersView.as_view()),
re_path(r"^api/photomonthcounts", dataviz.PhotoMonthCountsView.as_view()),
re_path(r"^api/wordcloud", dataviz.SearchTermWordCloudView.as_view()),
Expand Down

0 comments on commit 9ba0060

Please sign in to comment.