2024-04-23 11:03:34 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
|
"""
|
|
|
|
|
|
@project: maxkb
|
|
|
|
|
|
@Author:虎
|
|
|
|
|
|
@file: image.py
|
|
|
|
|
|
@date:2024/4/22 16:23
|
|
|
|
|
|
@desc:
|
|
|
|
|
|
"""
|
|
|
|
|
|
from drf_yasg import openapi
|
|
|
|
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
|
|
|
|
from rest_framework.decorators import action
|
|
|
|
|
|
from rest_framework.parsers import MultiPartParser
|
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
from rest_framework.views import Request
|
|
|
|
|
|
|
|
|
|
|
|
from common.auth import TokenAuth
|
2025-03-17 05:40:23 +00:00
|
|
|
|
from common.log.log import log
|
2024-04-23 11:03:34 +00:00
|
|
|
|
from common.response import result
|
|
|
|
|
|
from dataset.serializers.image_serializers import ImageSerializer
|
2025-01-13 08:38:28 +00:00
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-04-23 11:03:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Image(APIView):
|
|
|
|
|
|
authentication_classes = [TokenAuth]
|
|
|
|
|
|
parser_classes = [MultiPartParser]
|
|
|
|
|
|
|
|
|
|
|
|
@action(methods=['POST'], detail=False)
|
2025-01-13 08:38:28 +00:00
|
|
|
|
@swagger_auto_schema(operation_summary=_('Upload image'),
|
|
|
|
|
|
operation_id=_('Upload image'),
|
2024-04-23 11:03:34 +00:00
|
|
|
|
manual_parameters=[openapi.Parameter(name='file',
|
|
|
|
|
|
in_=openapi.IN_FORM,
|
|
|
|
|
|
type=openapi.TYPE_FILE,
|
|
|
|
|
|
required=True,
|
2025-01-13 08:38:28 +00:00
|
|
|
|
description=_('Upload image'))],
|
|
|
|
|
|
tags=[_('Image')])
|
2025-03-19 07:45:10 +00:00
|
|
|
|
@log(menu='Image', operate='Upload image')
|
2024-04-23 11:03:34 +00:00
|
|
|
|
def post(self, request: Request):
|
|
|
|
|
|
return result.success(ImageSerializer(data={'image': request.FILES.get('file')}).upload())
|
|
|
|
|
|
|
|
|
|
|
|
class Operate(APIView):
|
|
|
|
|
|
@action(methods=['GET'], detail=False)
|
2025-01-13 08:38:28 +00:00
|
|
|
|
@swagger_auto_schema(operation_summary=_('Get Image'),
|
|
|
|
|
|
operation_id=_('Get Image'),
|
|
|
|
|
|
tags=[_('Image')])
|
2024-04-23 11:03:34 +00:00
|
|
|
|
def get(self, request: Request, image_id: str):
|
|
|
|
|
|
return ImageSerializer.Operate(data={'id': image_id}).get()
|