Skip to content

Commit

Permalink
Merge pull request #995 from girder/mime-type-on-import
Browse files Browse the repository at this point in the history
Set mime type for imported girder files
  • Loading branch information
manthey authored Nov 21, 2022
2 parents d9ac2f0 + bf82150 commit 9a28d0e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
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

0 comments on commit 9a28d0e

Please sign in to comment.