perf: settings logo (#10971)

Co-authored-by: feng <1304903146@qq.com>
pull/10972/head
fit2bot 2023-07-14 23:01:48 +08:00 committed by GitHub
parent f504413d7f
commit 8f6b8b5a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 3 deletions

View File

@ -2,7 +2,10 @@
#
from django.conf import settings
from django.http import HttpResponse
from django.views.static import serve
from rest_framework import generics
from rest_framework import status
from rest_framework.permissions import AllowAny
from rest_framework.views import APIView
@ -148,7 +151,6 @@ class SettingsLogoApi(APIView):
permission_classes = (AllowAny,)
def get(self, request, *args, **kwargs):
from django.views.static import serve
size = request.GET.get('size', 'small')
interface_data = get_interface_setting_or_default()
if size == 'small':
@ -156,5 +158,12 @@ class SettingsLogoApi(APIView):
else:
logo_path = interface_data['logo_index']
logo_path = logo_path.replace('/static/', '/')
return serve(request, logo_path, document_root=settings.STATIC_ROOT)
if logo_path.startswith('/media/'):
logo_path = logo_path.replace('/media/', '')
document_root = settings.MEDIA_ROOT
elif logo_path.startswith('/static/'):
logo_path = logo_path.replace('/static/', '/')
document_root = settings.STATIC_ROOT
else:
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
return serve(request, logo_path, document_root=document_root)