Skip to content

Commit

Permalink
Added FsNode.info.mimetype (#119)
Browse files Browse the repository at this point in the history
Now devs can easy check mimetype of a file 👍

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
  • Loading branch information
bigcat88 authored Sep 13, 2023
1 parent 5368265 commit f17c1dd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

All notable changes to this project will be documented in this file.

## [0.2.0 - 2023-09-11]
## [0.2.0 - 2023-09-13]

### Added

- FilesAPI: `FsNode.info` added `mimetype` property.

### Changed

Expand Down
1 change: 1 addition & 0 deletions nc_py_api/ex_app/ui/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def to_fs_node(self) -> FsNode:
file_id=file_id + self.instanceId if self.instanceId else file_id,
fileid=self.fileId,
last_modified=datetime.utcfromtimestamp(self.mtime).replace(tzinfo=timezone.utc),
mimetype=self.mime,
)


Expand Down
6 changes: 6 additions & 0 deletions nc_py_api/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, **kwargs):
"content_length": kwargs.get("content_length", 0),
"size": kwargs.get("size", 0),
"permissions": kwargs.get("permissions", ""),
"mimetype": kwargs.get("mimetype", ""),
}
self.favorite = kwargs.get("favorite", False)
self.is_version = False
Expand All @@ -48,6 +49,11 @@ def size(self) -> int:
"""In the case of directories it is the size of all content, for files it is equal to ``content_length``."""
return self._raw_data["size"]

@property
def mimetype(self) -> str:
"""Mimetype of a file. Empty for the directories."""
return self._raw_data["mimetype"]

@property
def permissions(self) -> str:
"""Permissions for the object."""
Expand Down
3 changes: 3 additions & 0 deletions nc_py_api/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"d:resourcetype",
"d:getlastmodified",
"d:getcontentlength",
"d:getcontenttype",
"d:getetag",
"oc:size",
"oc:id",
Expand Down Expand Up @@ -609,6 +610,8 @@ def _parse_record(full_path: str, prop_stats: list[dict]) -> FsNode:
fs_node_args["etag"] = prop["d:getetag"]
if "d:getlastmodified" in prop_keys:
fs_node_args["last_modified"] = prop["d:getlastmodified"]
if "d:getcontenttype" in prop_keys:
fs_node_args["mimetype"] = prop["d:getcontenttype"]
if "oc:permissions" in prop_keys:
fs_node_args["permissions"] = prop["oc:permissions"]
if "oc:favorite" in prop_keys:
Expand Down
4 changes: 4 additions & 0 deletions tests/actual_tests/files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def test_fs_node_fields(nc_any):
assert result.info.content_length == 0
assert result.info.permissions == "RGDNVCK"
assert result.info.favorite is False
assert not result.info.mimetype
elif result.name == "test_empty_child_dir":
assert result.user_path == "test_dir/test_empty_child_dir/"
assert result.is_dir
Expand All @@ -389,6 +390,7 @@ def test_fs_node_fields(nc_any):
assert result.info.content_length == 0
assert result.info.permissions == "RGDNVCK"
assert result.info.favorite is False
assert not result.info.mimetype
elif result.name == "test_generated_image.png":
assert result.user_path == "test_dir/test_generated_image.png"
assert not result.is_dir
Expand All @@ -397,6 +399,7 @@ def test_fs_node_fields(nc_any):
assert result.info.size == result.info.content_length
assert result.info.permissions == "RGDNVW"
assert result.info.favorite is True
assert result.info.mimetype == "image/png"
elif result.name == "test_empty_text.txt":
assert result.user_path == "test_dir/test_empty_text.txt"
assert not result.is_dir
Expand All @@ -405,6 +408,7 @@ def test_fs_node_fields(nc_any):
assert not result.info.content_length
assert result.info.permissions == "RGDNVW"
assert result.info.favorite is False
assert result.info.mimetype == "text/plain"

res_by_id = nc_any.files.by_id(result.file_id)
assert res_by_id
Expand Down
4 changes: 2 additions & 2 deletions tests/actual_tests/ui_files_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def ui_action_check(directory: str, fs_object: FsNode):
name=fs_object.name,
directory=directory,
etag=fs_object.etag,
mime="",
mime=fs_object.info.mimetype,
fileType="dir" if fs_object.is_dir else "file",
mtime=int(fs_object.info.last_modified.timestamp()),
size=fs_object.info.size,
Expand All @@ -105,7 +105,7 @@ def ui_action_check(directory: str, fs_object: FsNode):
assert fs_node.full_path == fs_object.full_path
assert fs_node.file_id == fs_object.file_id
assert fs_node.is_dir == fs_object.is_dir
# assert fs_node.mime == fs_object.mime
assert fs_node.info.mimetype == fs_object.info.mimetype
assert fs_node.info.permissions == fs_object.info.permissions
assert fs_node.info.last_modified == fs_object.info.last_modified
assert fs_node.info.favorite == fs_object.info.favorite
Expand Down

0 comments on commit f17c1dd

Please sign in to comment.