コード例 #1
0
ファイル: models.py プロジェクト: BalloonInc/label-studio
 def resolve_uri(self, task_data, proxy=True):
     if proxy and self.project.task_data_login and self.project.task_data_password:
         protected_data = {}
         for key, value in task_data.items():
             if isinstance(value, str) and string_is_url(value):
                 path = reverse('projects-file-proxy',
                                kwargs={'pk': self.project.pk
                                        }) + '?url=' + quote(value)
                 value = urljoin(settings.HOSTNAME, path)
             protected_data[key] = value
         return protected_data
     else:
         # Try resolve URLs via storage associated with that task
         storage = self.storage
         for field in task_data:
             storage = storage or self._get_storage_by_url(task_data[field])
             if storage:
                 try:
                     resolved_uri = storage.resolve_uri(task_data[field])
                 except Exception as exc:
                     logger.error(exc, exc_info=True)
                     resolved_uri = None
                 if resolved_uri:
                     task_data[field] = resolved_uri
         return task_data
コード例 #2
0
ファイル: models.py プロジェクト: g-simmons/label-studio-gs
 def resolve_uri(self, task_data, proxy=True):
     if proxy and self.project.task_data_login and self.project.task_data_password:
         protected_data = {}
         for key, value in task_data.items():
             if isinstance(value, str) and string_is_url(value):
                 path = reverse('projects-file-proxy', kwargs={'pk': self.project.pk}) + '?url=' + value
                 value = urljoin(settings.HOSTNAME, path)
             protected_data[key] = value
         return protected_data
     else:
         # Try resolve URLs via storage associated with that task
         storage = self._get_task_storage(task_data)
         if storage:
             return storage.resolve_task_data_uri(task_data)
         return task_data
コード例 #3
0
ファイル: models.py プロジェクト: stjordanis/label-studio
    def resolve_uri(self, task_data, project):
        if project.task_data_login and project.task_data_password:
            protected_data = {}
            for key, value in task_data.items():
                if isinstance(value, str) and string_is_url(value):
                    path = reverse('projects-file-proxy',
                                   kwargs={'pk': project.pk
                                           }) + '?url=' + quote(value)
                    value = urljoin(settings.HOSTNAME, path)
                protected_data[key] = value
            return protected_data
        else:
            storage_objects = project.get_all_storage_objects(type_='import')

            # try resolve URLs via storage associated with that task
            for field in task_data:
                # file saved in django file storage
                if settings.CLOUD_FILE_STORAGE_ENABLED and self.is_upload_file(
                        task_data[field]):
                    # permission check: resolve uploaded files to the project only
                    file_upload = FileUpload.objects.filter(
                        project=project, file=task_data[field])
                    if file_upload.exists():
                        task_data[field] = default_storage.url(
                            name=task_data[field])
                    # it's very rare case, e.g. user tried to reimport exported file from another project
                    # or user wrote his django storage path manually
                    else:
                        task_data[field] = task_data[
                            field] + '?not_uploaded_project_file'
                    continue

                # project storage
                storage = self.storage or self._get_storage_by_url(
                    task_data[field], storage_objects)
                if storage:
                    try:
                        resolved_uri = storage.resolve_uri(task_data[field])
                    except Exception as exc:
                        logger.error(exc, exc_info=True)
                        resolved_uri = None
                    if resolved_uri:
                        task_data[field] = resolved_uri
            return task_data