Skip to content
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

Set mime type for imported girder files #995

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements
- Better control dtype on multi sources ([#993](../../pull/993))
- Don't use dask threads when using nd2 to fetch tiles ([#994](../../pull/994))
- Set mime type for imported girder files ([#995](../../pull/995))

### Bug Fixes
- Use open.read rather than download to access files in Girder ([#989](../../pull/989))
Expand Down
12 changes: 7 additions & 5 deletions girder/girder_large_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ def handleRemoveFile(event):
ImageItem().delete(item, [fileObj['_id']])


def handleFinalizeUploadBefore(event):
def handleFileSave(event):
"""
When a file is uploaded, mark its mime type based on its extension if we
When a file is first saved, mark its mime type based on its extension if we
would otherwise just mark it as generic application/octet-stream.
"""
fileObj = event.info['file']
if fileObj.get('mimeType', None) in {None, 'application/octet-stream'}:
fileObj = event.info
if fileObj.get('mimeType', None) in {None, ''} or (
'_id' not in fileObj and
fileObj.get('mimeType', None) in {'application/octet-stream'}):
global mimetypes

if not mimetypes:
Expand Down Expand Up @@ -483,7 +485,7 @@ def load(self, info):
events.bind('model.item.remove', 'large_image.removeThumbnails', removeThumbnails)
events.bind('server_fuse.unmount', 'large_image', large_image.cache_util.cachesClear)
events.bind('model.file.remove', 'large_image', handleRemoveFile)
events.bind('model.file.finalizeUpload.before', 'large_image', handleFinalizeUploadBefore)
events.bind('model.file.save', 'large_image', handleFileSave)

search._allowedSearchMode.pop('li_metadata', None)
search.addSearchMode('li_metadata', metadataSearchHandler)
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
= ' '
button.g-view-codemirror-revert-button.btn.btn-sm.btn-default Revert
= ' '
button.g-view-codemirror-format-button.btn.btn-sm.btn-default(title='This may remove comments') Format
= ' '
if formatRecord.format
button.g-view-codemirror-format-button.btn.btn-sm.btn-default(title='This may remove comments') Format
= ' '
button.g-view-codemirror-save-button.btn.btn-sm.btn-primary Save
i.icon-edit
span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ const Formats = {
* more work. */
format: (val) => jsyaml.dump(val, {lineWidth: -1, noRefs: true})
},
'text/plain': {
name: 'Text',
mode: 'text',
validator: (val) => val,
format: null
},
'application/x-girder-ini': {
name: 'Configuration',
mode: 'properties',
Expand Down Expand Up @@ -198,6 +204,7 @@ var CodemirrorEditWidget = View.extend({
formatName: Formats[this.mimeType].name,
accessLevel: this.accessLevel,
buttonList: Formats[this.mimeType].buttons || [],
formatRecord: Formats[this.mimeType],
AccessType: AccessType
}));
this.code = CodeMirror(this.$el.find('.editor')[0], {
Expand Down