-
Notifications
You must be signed in to change notification settings - Fork 78
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
[SVCS-528] [Blocked] Improve gdoc rendering - WB Part #304
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
'ext': '.gdoc', | ||
'download_ext': '.docx', | ||
'type': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | ||
'alt_download_ext': '.pdf', | ||
'alt_type': 'application/pdf', | ||
}, | ||
{ | ||
'mime_type': 'application/vnd.google-apps.drawing', | ||
|
@@ -24,6 +26,7 @@ | |
'type': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | ||
}, | ||
] | ||
|
||
DOCS_DEFAULT_FORMAT = { | ||
'ext': '', | ||
'download_ext': '.pdf', | ||
|
@@ -37,28 +40,42 @@ def is_docs_file(metadata): | |
|
||
|
||
def get_mimetype_from_ext(ext): | ||
for format in DOCS_FORMATS: | ||
if format['ext'] == ext: | ||
return format['mime_type'] | ||
for format_type in DOCS_FORMATS: | ||
if format_type.get('ext') == ext: | ||
return format_type.get('mime_type') | ||
|
||
|
||
def get_format(metadata): | ||
for format in DOCS_FORMATS: | ||
if format['mime_type'] == metadata['mimeType']: | ||
return format | ||
for format_type in DOCS_FORMATS: | ||
if format_type.get('mime_type') == metadata.get('mimeType'): | ||
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. metadata.get('mimeType') should be outside the for loop so it doesn't need to be accessed each iteration. Given that this data structure is tiny so I doubt there will be any perf. difference. |
||
return format_type | ||
return DOCS_DEFAULT_FORMAT | ||
|
||
|
||
def get_extension(metadata): | ||
format = get_format(metadata) | ||
return format['ext'] | ||
format_type = get_format(metadata) | ||
return format_type.get('ext') | ||
|
||
|
||
def get_download_extension(metadata): | ||
format = get_format(metadata) | ||
return format['download_ext'] | ||
format_type = get_format(metadata) | ||
return format_type.get('download_ext') | ||
|
||
|
||
def get_alt_download_extension(metadata): | ||
format_type = get_format(metadata) | ||
return format_type.get('alt_download_ext', None) or format_type.get('download_ext') | ||
|
||
|
||
def get_alt_export_link(metadata): | ||
format_type = get_format(metadata) | ||
export_links = metadata.get('exportLinks') | ||
if format_type.get('alt_type'): | ||
return export_links.get(format_type.get('alt_type')) | ||
else: | ||
return export_links.get(format_type.get('type')) | ||
|
||
|
||
def get_export_link(metadata): | ||
format = get_format(metadata) | ||
return metadata['exportLinks'][format['type']] | ||
format_type = get_format(metadata) | ||
return metadata.get('exportLinks').get(format_type.get('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. What if metadata doesn't have an |
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.
FYI, fixed. Need to check
metadata.raw.get('downloadUrl')
first. There are file types on gdrive (e.g..txt
) that do not haveexport_links
.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.
what about
Also I don't get the
or
here.