Fixed bug when importing public dataset

pull/1122/head
Luca Di Leo 2022-01-18 02:55:28 -08:00
rodzic 48e168e317
commit b05f98464b
3 zmienionych plików z 37 dodań i 55 usunięć

Wyświetl plik

@ -8,7 +8,7 @@ from app import models, pending_actions
from app.plugins.views import TaskView
from app.plugins.worker import run_function_async
from app.plugins import get_current_plugin
from coreplugins.dronedb.ddb import DroneDB, parse_url, verify_url
from coreplugins.dronedb.ddb import DEFAULT_HUB_URL, DroneDB, parse_url, verify_url
from worker.celery import app
from rest_framework.response import Response
@ -25,7 +25,7 @@ def is_valid(file):
def get_settings(request):
ds = get_current_plugin().get_user_data_store(request.user)
registry_url = ds.get_string('registry_url') or None
registry_url = ds.get_string('registry_url') or DEFAULT_HUB_URL
username = ds.get_string('username') or None
password = ds.get_string('password') or None
token = ds.get_string('token') or None
@ -60,13 +60,14 @@ class ImportDatasetTaskView(TaskView):
if ddb_url == None:
return Response({'error': 'DroneDB url must be set.'}, status=status.HTTP_400_BAD_REQUEST)
ddb = get_ddb(request)
info = parse_url(ddb_url)
registry_url, orgSlug, dsSlug, folder = parse_url(ddb_url).values()
_, username, password, token = get_settings(request).values()
ddb = DroneDB(registry_url, username, password, token, lambda token: update_token(request, token))
# Get the files from the folder
files = ddb.get_files_list(info['orgSlug'], info['dsSlug'], info['folder'])
files = [file for file in files if is_valid(file['path'])]
rawfiles = ddb.get_files_list(orgSlug, dsSlug, folder)
files = [file for file in rawfiles if is_valid(file['path'])]
# Verify that the folder url is valid
if len(files) == 0:
@ -169,16 +170,16 @@ class VerifyUrlTaskView(TaskView):
if url == None:
return Response({'error': 'Url must be set.'}, status=status.HTTP_400_BAD_REQUEST)
registry_url, username, password, token = get_settings(request).values()
if registry_url == None or username == None or password == None:
return Response({'error': 'Credentials must be set.'}, status=status.HTTP_400_BAD_REQUEST)
_, username, password, token = get_settings(request).values()
try:
org, ds, folder, count, size = verify_url(url, username, password)
result, org, ds, folder, count, size = verify_url(url, username, password).values()
return Response({'count': count, 'success': True, 'ds' : ds, 'org': org, 'folder': folder or None, 'size': size}
if (not result):
return Response({'error': 'Invalid url.'}, status=status.HTTP_400_BAD_REQUEST)
return Response({'count': count, 'success': result, 'ds' : ds, 'org': org, 'folder': folder or None, 'size': size}
if org else {'success': False}, status=status.HTTP_200_OK)
except Exception as e:
@ -187,7 +188,7 @@ class VerifyUrlTaskView(TaskView):
class InfoTaskView(TaskView):
def get(self, request):
registry_url, username, password, token = get_settings(request).values()
registry_url, username, _, _ = get_settings(request).values()
return Response({ 'hubUrl': registry_url, 'username': username }, status=status.HTTP_200_OK)

Wyświetl plik

@ -5,6 +5,7 @@ from app.plugins import logger
from urllib.parse import urlparse
VALID_IMAGE_EXTENSIONS = ['.tiff', '.tif', '.png', '.jpeg', '.jpg']
DEFAULT_HUB_URL = 'https://hub.droneDB.app'
class DroneDB:
@ -148,6 +149,8 @@ class DroneDB:
# Type 1 is folder
params = {'path': '' if folder is None else folder}
logger.info(self.__get_files_list_url.format(orgSlug, dsSlug))
# Get the folders
response = self.wrapped_call('GET', self.__get_files_list_url.format(orgSlug, dsSlug), params=params)
@ -172,18 +175,32 @@ def verify_url(url, username=None, password=None):
files = ddb.get_files_list(orgSlug, dsSlug, folder)
# return some info
return orgSlug, dsSlug, folder, len(files), sum(i['size'] for i in files)
return {
'success': True,
'orgSlug': orgSlug,
'dsSlug': dsSlug,
'folder': folder,
'count': len(files),
'size': sum(i['size'] for i in files)
}
except Exception as e:
logger.error(e)
return False
return {
'success': False,
'orgSlug': None,
'dsSlug': None,
'folder': None,
'count': None,
'size': None
}
def parse_url(url):
# Check if the url is valid
# Root folder of dataset: ddb://localhost:5001/admin/4uyyyaxcbvahd7qb
# 'test' folder of dataset: ddb://localhost:5001/admin/4uyyyaxcbvahd7qb/test
# using http instead of https: ddb+unsafe://localhost:5001/admin/4uyyyaxcbvahd7qb
# using http instead of https: ddb+unsafe://localhost:5000/admin/4uyyyaxcbvahd7qb
# using hub url: https://localhost:5001/r/admin/4uyyyaxcbvahd7qb
# using hub url without /r/ http://localhost:5000/admin/4uyyyaxcbvahd7qb/test
@ -216,37 +233,4 @@ def parse_url(url):
'folder': '/'.join(segments[3 + offset:])
}
# def verify_folder_url(self, folder_url):
# try:
# # Parse the url and get all necessary information
# information = self.parse_url(folder_url)
# # Define the API url we will call to assert that the folder exists and is valid
# folder_api_url = self.build_folder_api_url(information)
# # Call the API
# payload = self.call_api(folder_api_url)
# # Parse payload into a Folder instance
# return self.parse_payload_into_folder(folder_url, payload)
# except Exception as e:
# logger.error(str(e))
# return None
# def import_from_folder(folder_url):
# # Verify the url
# if self.verify_folder_url(folder_url) == None:
# raise Exception('Invalid URL')
# # Parse the url and get all necessary information
# information = self.parse_url(folder_url)
# # Define the API url we will call to get all the files in the folder
# folder_api_url = self.build_list_files_in_folder_api_url(information)
# # Call the API
# payload = self.call_api(folder_api_url)
# # Parse the payload into File instances
# files = self.parse_payload_into_files(payload)
# # Let the specific platform do some processing with the files (if necessary)
# files = self.platform_file_processing(files)
# # Return all the valid files
# return [file for file in files if file.is_valid()]

Wyświetl plik

@ -1,5 +1,6 @@
from app.plugins import PluginBase, Menu, MountPoint, logger
from coreplugins.dronedb.app_views import LoadButtonsView
from coreplugins.dronedb.ddb import DEFAULT_HUB_URL
from .api_views import FoldersTaskView, ImportDatasetTaskView, CheckCredentialsTaskView, OrganizationsTaskView, DatasetsTaskView, VerifyUrlTaskView, InfoTaskView
@ -30,10 +31,6 @@ class Plugin(PluginBase):
return ["ImportView.jsx", "TaskView.jsx"]
def api_mount_points(self):
#api_views = [api_view for platform in get_all_extended_platforms() for api_view in platform.get_api_views()]
# mount_points = [MountPoint(path, view) for (path, view) in api_views]
# Add mount points for each extended platform that might require us to do so
return [
MountPoint("projects/(?P<project_pk>[^/.]+)/tasks/(?P<pk>[^/.]+)/import", ImportDatasetTaskView.as_view()),
MountPoint("checkcredentials", CheckCredentialsTaskView.as_view()),
@ -61,7 +58,7 @@ class Plugin(PluginBase):
form = SettingsForm(initial={'username': ds.get_string('username', default=""),
'password': ds.get_string('password', default=""),
'registry_url': ds.get_string('registry_url', default="https://hub.dronedb.app")})
'registry_url': ds.get_string('registry_url', default=DEFAULT_HUB_URL)})
return render(request, self.template_path("app.html"), {
'title': 'DroneDB',