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

api: get file extension from key #544

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

jrcastro2
Copy link
Contributor

@jrcastro2 jrcastro2 commented Nov 10, 2023

⚠️ IMPORTANT: For this change to have effect it requires to reindex all records as the file types are indexed in OS

@jrcastro2 jrcastro2 force-pushed the update-file-extension branch from 95c3c6a to 09e6c53 Compare November 10, 2023 10:11
@@ -177,7 +178,9 @@ def dumps(self):
@property
def ext(self):
"""File extension."""
ext = mimetypes.guess_extension(self.object_model.mimetype)
Copy link
Member

@lnielsen lnielsen Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# The ``ext`` property is used to in search to aggregate file types and we want e.g. both ``.jpeg`` and ``.jpg`` to be aggregated under ``.jpg``
ext = mimetypes.guess_extension(self.object_model.mimetype)
if ext is not None:
    return ext[1:]

# Support non-standard file extensions that cannot be guessed
_, ext = os.path.splitext(self.key)
if ext and len(ext) <= 5:
    return ext.lower()

return None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the clarification.
However to make this work we would also need to change this to not return "application/octet-stream". I will do the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided not to remove the fallback mimetype as it might cause issues on files serving, instead we check if the mimetype is set to the fallback to try to get the extenstion from the filename or not.

@jrcastro2 jrcastro2 force-pushed the update-file-extension branch 3 times, most recently from 2df0478 to 4c8ed3c Compare November 13, 2023 10:06
@jrcastro2 jrcastro2 force-pushed the update-file-extension branch from 4c8ed3c to d24b872 Compare November 20, 2023 09:00
@jrcastro2 jrcastro2 force-pushed the update-file-extension branch from d24b872 to 8b7d597 Compare November 20, 2023 09:19
@slint slint merged commit 026b9f5 into inveniosoftware:master Nov 20, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants