stash
This commit is contained in:
parent
306fdf50ad
commit
cb735e7880
3 changed files with 13 additions and 12 deletions
|
@ -12,10 +12,10 @@ from files.models import File
|
|||
|
||||
@swagger_auto_schema(method='GET', auto_schema=None)
|
||||
@api_view(['GET'])
|
||||
def media_urls(request, hash_path):
|
||||
def media_urls(request, hash):
|
||||
try:
|
||||
file = File.objects.get(file=hash_path)
|
||||
|
||||
file = File.objects.get(hash=hash)
|
||||
hash_path = file.file
|
||||
return HttpResponse(status=status.HTTP_200_OK,
|
||||
content_type=file.mime_type,
|
||||
headers={
|
||||
|
@ -29,16 +29,17 @@ def media_urls(request, hash_path):
|
|||
|
||||
@swagger_auto_schema(method='GET', auto_schema=None)
|
||||
@api_view(['GET'])
|
||||
def thumbnail_urls(request, size, hash_path):
|
||||
def thumbnail_urls(request, size, hash):
|
||||
if size not in [32, 64, 256]:
|
||||
return Response(status=status.HTTP_404_NOT_FOUND)
|
||||
try:
|
||||
file = File.objects.get(file=hash_path)
|
||||
file = File.objects.get(hash=hash)
|
||||
hash_path = file.file
|
||||
if not os.path.exists(MEDIA_ROOT + f'/thumbnails/{size}/{hash_path}'):
|
||||
from PIL import Image
|
||||
iamge = Image.open(file.file)
|
||||
iamge.thumbnail((size, size))
|
||||
iamge.save(MEDIA_ROOT + f'/media/thumbnails/{size}/{hash_path}', quality=90)
|
||||
image = Image.open(file.file)
|
||||
image.thumbnail((size, size))
|
||||
image.save(MEDIA_ROOT + f'/media/thumbnails/{size}/{hash_path}', quality=90)
|
||||
|
||||
return HttpResponse(status=status.HTTP_200_OK,
|
||||
content_type=file.mime_type,
|
||||
|
@ -52,6 +53,6 @@ def thumbnail_urls(request, size, hash_path):
|
|||
|
||||
|
||||
urlpatterns = [
|
||||
path('<int:size>/<path:hash_path>/', thumbnail_urls),
|
||||
path('<path:hash_path>/', media_urls),
|
||||
path('<int:size>/<path:hash>/', thumbnail_urls),
|
||||
path('<path:hash>/', media_urls),
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue