Пример #1
0
class AssetIconsResource(BaseResource):

    get_schema = AssetIconsSchema()
    upload_schema = AssetIconUploadSchema()

    @use_kwargs(get_schema, location='view_args')
    def get(self, asset: Asset) -> Response:
        # Process the if-match and if-none-match headers so that comparison with etag can be done
        match_header = flask_request.headers.get('If-Match', None)
        if not match_header:
            match_header = flask_request.headers.get('If-None-Match', None)
        if match_header:
            match_header = match_header[1:-1]  # remove enclosing quotes

        return self.rest_api.get_asset_icon(asset, match_header)

    @use_kwargs(upload_schema, location='json_and_view_args')
    def put(self, asset: Asset, file: Path) -> Response:
        return self.rest_api.upload_asset_icon(asset=asset, filepath=file)

    @use_kwargs(upload_schema, location='view_args_and_file')
    def post(self, asset: Asset, file: FileStorage) -> Response:
        with TemporaryDirectory() as temp_directory:
            filename = file.filename if file.filename else f'{asset.identifier}.png'
            filepath = Path(temp_directory) / filename
            file.save(str(filepath))
            response = self.rest_api.upload_asset_icon(asset=asset,
                                                       filepath=filepath)

        return response
Пример #2
0
class AssetIconsResource(BaseResource):

    get_schema = AssetIconsSchema()

    @use_kwargs(get_schema, location='view_args')  # type: ignore
    def get(self, asset: Asset, size: Literal['thumb', 'small', 'large']) -> Response:
        # Process the if-match and if-none-match headers so that comparison with etag can be done
        match_header = flask_request.headers.get('If-Match', None)
        if not match_header:
            match_header = flask_request.headers.get('If-None-Match', None)
        if match_header:
            match_header = match_header[1:-1]  # remove enclosing quotes

        return self.rest_api.get_asset_icon(asset, size, match_header)