-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for chemical analysis workflow #1336
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
arches_for_science/media/js/bindings/uppy-django-storages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import BasePlugin from '@uppy/core/lib/BasePlugin.js'; | ||
|
||
export default class UppyDjangoStorages extends BasePlugin { | ||
constructor(uppy, opts) { | ||
super(uppy, opts); | ||
this.id = opts.id || 'UppyDjangoStorages'; | ||
this.type = 'django'; | ||
} | ||
|
||
install (){ | ||
this.uppy.addPreProcessor(async (fileIds) => { | ||
const uppyFiles = fileIds.map(fileId => { | ||
return uppy.getFile(fileId) | ||
}) | ||
const files = await this.opts.beforeUpload(uppyFiles); | ||
files.flat().map(file => { | ||
uppy.setFileState(file.clientId, {'name': file.path}); | ||
uppy.setFileMeta(file.clientId, {'name': file.path}) | ||
}) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,40 @@ | ||
|
||
import json | ||
from django.conf import settings | ||
from django.http import JsonResponse, HttpResponseNotAllowed | ||
from django.http import JsonResponse, HttpResponse | ||
from django.utils.decorators import method_decorator | ||
from arches.app.views.base import BaseManagerView | ||
from arches.app.utils.decorators import can_edit_resource_instance | ||
import boto3 | ||
|
||
KEY_BASE = "uploadedfiles/" | ||
|
||
KEY_BASE = settings.UPLOADED_FILES_DIR | ||
|
||
@method_decorator(can_edit_resource_instance, name="dispatch") | ||
class S3MultipartUploaderView(BaseManagerView): | ||
"""S3 Multipart uploader chunks files to allow for parallel uploads to S3""" | ||
|
||
def options(self, request): | ||
response = HttpResponse() | ||
response.headers['access-control-allow-headers'] = 'x-csrftoken,accept,content-type,uppy-auth-token,location' | ||
return response | ||
|
||
def post(self, request): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
except AttributeError: | ||
raise Exception("Django storages for AWS not configured") | ||
|
||
json_body = json.loads(request.body) | ||
file_name = json_body["filename"] | ||
if(file_name and file_name.startswith(KEY_BASE)): | ||
key = file_name | ||
else: | ||
key = KEY_BASE + file_name | ||
|
||
response_object = {} | ||
s3 = boto3.client("s3") | ||
resp = s3.create_multipart_upload( | ||
Bucket=storage_bucket, | ||
Key=KEY_BASE + json_body["filename"], | ||
Key=key, | ||
ContentType=json_body["type"], | ||
Metadata=json_body["metadata"], | ||
) | ||
|
@@ -35,8 +45,7 @@ def post(self, request): | |
|
||
@method_decorator(can_edit_resource_instance, name="dispatch") | ||
class S3MultipartUploadManagerView(BaseManagerView): | ||
"""doom""" | ||
|
||
"""Returns all of the parts of a given upload id""" | ||
def get(self, request, uploadid): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
|
@@ -57,14 +66,28 @@ def get_parts(client, uploadId, partNumber): | |
get_parts(s3, uploadid, 0) | ||
return JsonResponse(parts, safe=False) | ||
|
||
def delete(self, request): | ||
"""post""" | ||
def delete(self, request, uploadid): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
except AttributeError: | ||
raise Exception("Django storages for AWS not configured") | ||
|
||
|
||
return JsonResponse({}) | ||
s3 = boto3.client("s3") | ||
key = request.GET.get("key", "") | ||
|
||
s3.abort_multipart_upload( | ||
storage_bucket, | ||
key, | ||
uploadid | ||
) | ||
|
||
def batch_sign(request, uploadid): | ||
if request.method == "GET": | ||
return JsonResponse({}) | ||
|
||
@method_decorator(can_edit_resource_instance, name="dispatch") | ||
class S3BatchSignView(BaseManagerView): | ||
"""generates a batch of presigned urls for a group of part numbers""" | ||
def get(self, request, uploadid): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
except AttributeError: | ||
|
@@ -89,12 +112,43 @@ def batch_sign(request, uploadid): | |
) | ||
) | ||
return JsonResponse(urls, safe=False) | ||
else: | ||
return HttpResponseNotAllowed() | ||
|
||
@method_decorator(can_edit_resource_instance, name="dispatch") | ||
class S3UploadView(BaseManagerView): | ||
"""""" | ||
def get(self, request): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
except AttributeError: | ||
raise Exception("Django storages for AWS not configured") | ||
s3 = boto3.client("s3") | ||
|
||
file_name = request.GET.get("filename") | ||
|
||
if(file_name.startswith(KEY_BASE)): | ||
key = file_name | ||
else: | ||
key = KEY_BASE + "/" + file_name | ||
|
||
fields={} | ||
#fields = dict(('x-amz-meta-{}'.format(key[9:len(key)-1]), value) for (key, value) in all_items if key.startswith('metadata') and key != 'metadata[type]') | ||
#fields['content-type'] = content_type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this can be removed |
||
response = s3.generate_presigned_post( | ||
storage_bucket, | ||
key, | ||
fields, | ||
ExpiresIn=300, | ||
) | ||
return JsonResponse({ | ||
'method': 'post', | ||
'url': response['url'], | ||
'fields': response['fields'], | ||
'expires': 300 | ||
}, safe=False) | ||
|
||
def upload_part(request, uploadid, partnumber): | ||
if request.method == "GET": | ||
@method_decorator(can_edit_resource_instance, name="dispatch") | ||
class S3UploadPartView(BaseManagerView): | ||
def get(self, request, uploadid, partnumber): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
except AttributeError: | ||
|
@@ -111,13 +165,12 @@ def upload_part(request, uploadid, partnumber): | |
}, | ||
300, | ||
) | ||
return JsonResponse(url, safe=False) | ||
else: | ||
return HttpResponseNotAllowed() | ||
return JsonResponse({'url': url, 'expires': 300}, safe=False) | ||
|
||
|
||
def complete_upload(request, uploadid): | ||
if request.method == "POST": | ||
@method_decorator(can_edit_resource_instance, name="dispatch") | ||
class S3CompleteUploadView(BaseManagerView): | ||
def post(self, request, uploadid): | ||
try: | ||
storage_bucket = settings.AWS_STORAGE_BUCKET_NAME | ||
except AttributeError: | ||
|
@@ -130,6 +183,4 @@ def complete_upload(request, uploadid): | |
UploadId=uploadid, | ||
MultipartUpload={"Parts": json.loads(request.body.decode("utf-8"))["parts"]}, | ||
) | ||
return JsonResponse({"location": response["Location"]}) | ||
else: | ||
return HttpResponseNotAllowed() | ||
return JsonResponse({"location": response["Location"]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty docstring