mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-23 12:49:41 +08:00
set model mimetype, even when content=False
This commit is contained in:
parent
6ec427b523
commit
f64aa490e3
@ -278,18 +278,20 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
|
||||
model['type'] = 'file'
|
||||
|
||||
os_path = self._get_os_path(path)
|
||||
model['mimetype'] = mimetypes.guess_type(os_path)[0]
|
||||
|
||||
if content:
|
||||
content, format = self._read_file(os_path, format)
|
||||
default_mime = {
|
||||
'text': 'text/plain',
|
||||
'base64': 'application/octet-stream'
|
||||
}[format]
|
||||
if model['mimetype'] is None:
|
||||
default_mime = {
|
||||
'text': 'text/plain',
|
||||
'base64': 'application/octet-stream'
|
||||
}[format]
|
||||
model['mimetype'] = default_mime
|
||||
|
||||
model.update(
|
||||
content=content,
|
||||
format=format,
|
||||
mimetype=mimetypes.guess_type(os_path)[0] or default_mime,
|
||||
)
|
||||
|
||||
return model
|
||||
|
@ -55,9 +55,6 @@ def validate_model(model, expect_content):
|
||||
)
|
||||
|
||||
maybe_none_keys = ['content', 'format']
|
||||
if model['type'] == 'file':
|
||||
# mimetype should be populated only for file models
|
||||
maybe_none_keys.append('mimetype')
|
||||
if expect_content:
|
||||
errors = [key for key in maybe_none_keys if model[key] is None]
|
||||
if errors:
|
||||
|
Loading…
Reference in New Issue
Block a user