file.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from drf_spectacular.types import OpenApiTypes
  2. from drf_spectacular.utils import OpenApiParameter
  3. from common.mixins.api_mixin import APIMixin
  4. from common.result import DefaultResultSerializer
  5. class FileUploadAPI(APIMixin):
  6. @staticmethod
  7. def get_request():
  8. return {
  9. 'multipart/form-data': {
  10. 'type': 'object',
  11. 'properties': {
  12. 'file': {
  13. 'type': 'string',
  14. 'format': 'binary',
  15. 'description': '要上传的文件'
  16. },
  17. "source_id": {
  18. 'type': 'string',
  19. 'description': '资源id 如果source_type为[TEMPORARY_30_MINUTE,TEMPORARY_120_MINUTE,TEMPORARY_1_DAY,SYSTEM] 其他的需要为对应资源的id'
  20. },
  21. "source_type": {
  22. 'type': 'string',
  23. 'description': '资源类型[KNOWLEDGE,APPLICATION,TOOL,DOCUMENT,CHAT,SYSTEM,TEMPORARY_30_MINUTE,TEMPORARY_120_MINUTE,TEMPORARY_1_DAY]'
  24. }
  25. }
  26. }
  27. }
  28. @staticmethod
  29. def get_response():
  30. return DefaultResultSerializer
  31. class FileGetAPI(APIMixin):
  32. @staticmethod
  33. def get_parameters():
  34. return [
  35. OpenApiParameter(
  36. name="file_id",
  37. description="文件id",
  38. type=OpenApiTypes.STR,
  39. location='path',
  40. required=True,
  41. ),
  42. ]
  43. @staticmethod
  44. def get_response():
  45. return DefaultResultSerializer
  46. class GetUrlContentAPI(APIMixin):
  47. @staticmethod
  48. def get_parameters():
  49. return [
  50. OpenApiParameter(
  51. name="url",
  52. description="文件url",
  53. type=OpenApiTypes.STR,
  54. location='query',
  55. required=True,
  56. ),
  57. ]
  58. @staticmethod
  59. def get_response():
  60. return DefaultResultSerializer