Repository navigation
server: Implement the AAS thumbnail endpoints - #618
paul-gerber-svg wants to merge 5 commits into
Conversation
…ation thumbnail endpoint." This reverts commit 496190f, which held the content of eclipse-basyx#618. This was added for testing purpose only. Merge `develop` into this branch, after the PR was closed to obtain the same result.
|
This needs to be adapted when #627 is merged. |
|
@paul-gerber-svg can you add the tests here? |
| def put_aas_thumbnail( | ||
| self, request: Request, url_args: Dict, response_t: Type[APIResponse], **_kwargs | ||
| ) -> Response: | ||
| shell = self._get_shell(url_args) | ||
| filename = request.form.get("fileName") | ||
| if filename is None: | ||
| raise BadRequest("No 'fileName' specified!") | ||
| elif not filename.startswith("/"): | ||
| raise BadRequest(f"Given 'fileName' doesn't start with a slash (/): {filename}") | ||
|
|
||
| file_storage: Optional[FileStorage] = request.files.get("file") | ||
| if file_storage is None: | ||
| raise BadRequest("Missing file to upload") | ||
|
|
||
| old_thumbnail = shell.asset_information.default_thumbnail | ||
| new_path = self.file_store.add_file(filename, file_storage.stream, file_storage.mimetype) | ||
| if old_thumbnail is not None and old_thumbnail.path and old_thumbnail.path.startswith("/") \ | ||
| and old_thumbnail.path != new_path: | ||
| try: | ||
| self.file_store.delete_file(old_thumbnail.path) | ||
| except KeyError: | ||
| pass | ||
|
|
||
| shell.asset_information.default_thumbnail = model.Resource(new_path, file_storage.mimetype) | ||
| self.object_store.commit(shell) | ||
| return response_t() |
There was a problem hiding this comment.
This should check, for empty strings in mimetype == ''.
If the mimetype is an empty string, the resulting contentType also becomes an empty stirng, when it should be None.
There was a problem hiding this comment.
Fixed: an empty mimetype is now stored as None. In fact, the empty string didn't even get stored.
ContentType rejects it, so the request failed with 500, after the previous thumbnail file had already been deleted.
PUT now validates its input first and deletes the old file only once the shell points to the new one.
test_shell_thumbnail_put_without_content_type_stores_none covers this.
Currently, server endpoint `/asset-information/thumbnail`, methods=["GET", "PUT", "DELETE"], endpoint=self.not_implemented is not implemented. According to the AAS Repository Service OpenAPI Specification, the endpoint should return, replace or delete the thumbnail file of a selected AAS. This issue specifies eclipse-basyx#439. This change implements `GET`, `PUT` and `DELETE` for `/shells/{aasIdentifier}/asset-information/thumbnail` according to the specification. `GET` returns the thumbnail file referenced by `AssetInformation.default_thumbnail`. `PUT` accepts a `multipart/form-data` upload (`fileName` and `file`), stores it via the file store, and updates `default_thumbnail` accordingly, removing the previous thumbnail file if the path changes. `DELETE` removes the stored file and clears `default_thumbnail`. All three reject external (non-local) thumbnail references, since the server cannot serve or manage files it does not store itself. Fixes eclipse-basyx#493
Previously, the "Currently Unimplemented" section of the server README
listed the `/shells/{aasIdentifier}/asset-information/thumbnail` route.
This change implements that route, so the entry is removed.
The section is also changed from a numbered list to bullet points.
This way, adding or removing an entry no longer means renumbering all
the entries after it.
bb1f945 to
a46f92c
Compare
GET/PUT/DELETE for /shells/asset-information/thumbnail|
Rebased onto |
Currently, the server endpoint
/asset-information/thumbnailis notimplemented; all three methods (
GET,PUT,DELETE) are mapped toself.not_implemented.According to the AAS Repository Service OpenAPI Specification, the
endpoint should return, replace or delete the thumbnail file of a
selected AAS.
This change implements
GET,PUTandDELETEfor/shells/{aasIdentifier}/asset-information/thumbnailaccording tothe specification.
GETreturns the thumbnail file referenced byAssetInformation.default_thumbnail.PUTaccepts amultipart/form-dataupload (fileNameandfile), stores it viathe file store, and updates
default_thumbnailaccordingly, removingthe previous thumbnail file if the path changes.
DELETEremoves thestored file and clears
default_thumbnail. All three reject external(non-local) thumbnail references, since the server cannot serve or
manage files it does not store itself.
Fixes #493