MaxKB/apps/dataset/views/file.py
shaohuzhang1 90f4d59ec5
Some checks are pending
sync2gitee / repo-sync (push) Waiting to run
Typos Check / Spell Check with Typos (push) Waiting to run
feat: Generate i18n file (#2022)
2025-01-14 10:37:00 +08:00

45 lines
1.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# coding=utf-8
"""
@project: maxkb
@Author
@file image.py
@date2024/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
from common.response import result
from dataset.serializers.file_serializers import FileSerializer
from django.utils.translation import gettext_lazy as _
class FileView(APIView):
authentication_classes = [TokenAuth]
parser_classes = [MultiPartParser]
@action(methods=['POST'], detail=False)
@swagger_auto_schema(operation_summary=_('Upload file'),
operation_id=_('Upload file'),
manual_parameters=[openapi.Parameter(name='file',
in_=openapi.IN_FORM,
type=openapi.TYPE_FILE,
required=True,
description=_('Upload file'))],
tags=[_('file')])
def post(self, request: Request):
return result.success(FileSerializer(data={'file': request.FILES.get('file')}).upload())
class Operate(APIView):
@action(methods=['GET'], detail=False)
@swagger_auto_schema(operation_summary=_('Get file'),
operation_id=_('Get file'),
tags=[_('file')])
def get(self, request: Request, file_id: str):
return FileSerializer.Operate(data={'id': file_id}).get()