You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.4 KiB

3 years ago
  1. from django.conf import settings
  2. from rest_framework.permissions import IsAuthenticated
  3. from rest_framework.response import Response
  4. from rest_framework.views import APIView
  5. class Features(APIView):
  6. permission_classes = (IsAuthenticated,)
  7. def get(self, request, *args, **kwargs):
  8. return Response({
  9. 'cloud_upload': bool(settings.CLOUD_BROWSER_APACHE_LIBCLOUD_PROVIDER),
  10. })
  11. # class CloudUploadAPI(APIView):
  12. # permission_classes = TextUploadAPI.permission_classes
  13. #
  14. # def get(self, request, *args, **kwargs):
  15. # try:
  16. # project_id = request.query_params['project_id']
  17. # file_format = request.query_params['upload_format']
  18. # cloud_container = request.query_params['container']
  19. # cloud_object = request.query_params['object']
  20. # except KeyError as ex:
  21. # raise ValidationError('query parameter {} is missing'.format(ex))
  22. #
  23. # try:
  24. # cloud_file = self.get_cloud_object_as_io(cloud_container, cloud_object)
  25. # except ContainerDoesNotExistError:
  26. # raise ValidationError('cloud container {} does not exist'.format(cloud_container))
  27. # except ObjectDoesNotExistError:
  28. # raise ValidationError('cloud object {} does not exist'.format(cloud_object))
  29. #
  30. # TextUploadAPI.save_file(
  31. # user=request.user,
  32. # file=cloud_file,
  33. # file_format=file_format,
  34. # project_id=project_id,
  35. # )
  36. #
  37. # next_url = request.query_params.get('next')
  38. #
  39. # if next_url == 'about:blank':
  40. # return Response(data='', content_type='text/plain', status=status.HTTP_201_CREATED)
  41. #
  42. # if next_url:
  43. # return redirect(next_url)
  44. #
  45. # return Response(status=status.HTTP_201_CREATED)
  46. #
  47. # @classmethod
  48. # def get_cloud_object_as_io(cls, container_name, object_name):
  49. # provider = settings.CLOUD_BROWSER_APACHE_LIBCLOUD_PROVIDER.lower()
  50. # account = settings.CLOUD_BROWSER_APACHE_LIBCLOUD_ACCOUNT
  51. # key = settings.CLOUD_BROWSER_APACHE_LIBCLOUD_SECRET_KEY
  52. #
  53. # driver = get_driver(DriverType.STORAGE, provider)
  54. # client = driver(account, key)
  55. #
  56. # cloud_container = client.get_container(container_name)
  57. # cloud_object = cloud_container.get_object(object_name)
  58. #
  59. # return iterable_to_io(cloud_object.as_stream())