Skip to content

Commit

Permalink
Add more APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshg999 committed Sep 15, 2024
1 parent 159019e commit 2aaf68b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 13 deletions.
35 changes: 35 additions & 0 deletions apps/filebrowser/src/filebrowser/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
SHOW_UPLOAD_BUTTON,
)
from filebrowser.lib import xxd
from filebrowser.utils import parse_broker_url
from filebrowser.views import (
BYTES_PER_LINE,
BYTES_PER_SENTENCE,
Expand Down Expand Up @@ -487,6 +488,14 @@ def stat(request):

return JsonResponse(_massage_stats(request, stat_absolute_path(path, stats)))

@api_error_handler
def upload_chunks(request):
pass

@api_error_handler
def upload_complete(request):
pass


@api_error_handler
def upload_file(request):
Expand Down Expand Up @@ -783,3 +792,29 @@ def compress_files_using_batch_job(request):
return HttpResponse('Output directory is not set.', status=500) # TODO: status code?

return JsonResponse(response)


@api_error_handler
def get_available_space_for_upload(request):
redis_client = parse_broker_url(TASK_SERVER_V2.BROKER_URL.get())
try:
upload_available_space = int(redis_client.get('upload_available_space'))
if upload_available_space is None:
return HttpResponse("upload_available_space key is not set in Redis.", status=500) # TODO: status code?

return JsonResponse({'upload_available_space': upload_available_space})
except Exception as e:
message = f"Failed to get available space from Redis: {str(e)}"
LOG.exception(message)
return HttpResponse(message, status=500) # TODO: status code?
finally:
redis_client.close()


@api_error_handler
def reserve_space_for_upload(request):
pass

@api_error_handler
def release_reserved_space_for_upload(request):
pass
29 changes: 29 additions & 0 deletions desktop/core/src/desktop/api_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ def storage_upload_file(request):
django_request = get_django_request(request)
return filebrowser_api.upload_file(django_request)

@api_view(["POST"])
def storage_upload_chunks(request):
django_request = get_django_request(request)
return filebrowser_api.upload_chunks(django_request)

@api_view(["POST"])
def storage_upload_complete(request):
django_request = get_django_request(request)
return filebrowser_api.upload_complete(django_request)


@api_view(["PUT"])
def storage_mkdir(request):
Expand Down Expand Up @@ -322,17 +332,36 @@ def storage_trash_purge(request):
django_request = get_django_request(request)
return filebrowser_api.trash_purge(django_request)


@api_view(["POST"])
def storage_compress_files_using_batch_job(request):
django_request = get_django_request(request)
return filebrowser_api.compress_files_using_batch_job(django_request)


@api_view(["POST"])
def storage_extract_archive_using_batch_job(request):
django_request = get_django_request(request)
return filebrowser_api.extract_archive_using_batch_job(django_request)


# Task Server

@api_view(["GET"])
def taskserver_get_available_space_for_upload(request):
django_request = get_django_request(request)
return filebrowser_api.get_available_space_for_upload(django_request)

@api_view(["POST"])
def taskserver_reserve_space_for_upload(request):
django_request = get_django_request(request)
return filebrowser_api.reserve_space_for_upload(django_request)

@api_view(["POST"])
def taskserver_release_reserved_space_for_upload(request):
django_request = get_django_request(request)
return filebrowser_api.release_reserved_space_for_upload(django_request)

# Importer


Expand Down
36 changes: 23 additions & 13 deletions desktop/core/src/desktop/api_public_urls_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
from django.urls import re_path

from desktop import api_public
from desktop.lib.botserver import api as botserver_api

if sys.version_info[0] > 2:
from django.urls import re_path
else:
from django.conf.urls import url as re_path


# "New" query API (i.e. connector based, lean arguments).
# e.g. https://demo.gethue.com/api/query/execute/hive
urlpatterns = [
Expand Down Expand Up @@ -87,14 +81,27 @@
name='editor_sample_data_column',
),
re_path(
r"^editor/sample/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/(?P<column>\w+)/(?P<nested>.+)/?$",
api_public.get_sample_data,
name="editor_sample_data_nested",
r"^editor/sample/(?P<database>[^/?]*)/(?P<table>[\w_\-]+)/(?P<column>\w+)/(?P<nested>.+)/?$",
api_public.get_sample_data,
name="editor_sample_data_nested",
),
]

urlpatterns += [
re_path(r'^storage/view=(?P<path>.*)$', api_public.storage_view, name='storage_view'),
re_path(
r'^taskserver/upload/available_space/?$',
api_public.taskserver_get_available_space_for_upload,
name='taskserver_get_available_space_for_upload',
),
re_path(
r'^taskserver/upload/reserve_space/?$', api_public.taskserver_reserve_space_for_upload, name='taskserver_reserve_space_for_upload'
),
re_path(
r'^taskserver/upload/release_reserved_space/?$',
api_public.taskserver_release_reserved_space_for_upload,
name='taskserver_release_reserved_space_for_upload',
),
]

urlpatterns += [
Expand All @@ -107,7 +114,8 @@
re_path(r'^storage/move/?$', api_public.storage_move, name='storage_move'),
re_path(r'^storage/copy/?$', api_public.storage_copy, name='storage_copy'),
re_path(r'^storage/upload/file/?$', api_public.storage_upload_file, name='storage_upload_file'),

re_path(r'^storage/upload/chunks/?$', api_public.storage_upload_chunks, name='storage_upload_chunks'),
re_path(r'^storage/upload/complete/?$', api_public.storage_upload_complete, name='storage_upload_complete'),
re_path(r'^storage/stat/?$', api_public.storage_stat, name='storage_stat'),
re_path(r'^storage/display/?$', api_public.storage_display, name='storage_display'),
re_path(r'^storage/download/?$', api_public.storage_download, name='storage_download'),
Expand All @@ -117,8 +125,10 @@
re_path(r'^storage/trash/path/?$', api_public.storage_get_trash_path, name='storage_get_trash_path'),
re_path(r'^storage/trash/restore/?$', api_public.storage_trash_restore, name='storage_trash_restore'),
re_path(r'^storage/trash/purge/?$', api_public.storage_trash_purge, name='storage_trash_purge'),
re_path(r'^storage/extract_archive/?', api_public.storage_extract_archive_using_batch_job, name='storage_extract_archive_using_batch_job'),
re_path(r'^storage/compress_files/?', api_public.storage_compress_files_using_batch_job, name='storage_compress_files_using_batch_job'),
re_path(
r'^storage/extract_archive/?$', api_public.storage_extract_archive_using_batch_job, name='storage_extract_archive_using_batch_job'
),
re_path(r'^storage/compress_files/?$', api_public.storage_compress_files_using_batch_job, name='storage_compress_files_using_batch_job'),
]

urlpatterns += [
Expand Down

0 comments on commit 2aaf68b

Please sign in to comment.