dpgaspar commented on a change in pull request #8947: [thumbnails] thumbnails
for dashboards and charts
URL:
https://github.com/apache/incubator-superset/pull/8947#discussion_r406284074
##########
File path: superset/dashboards/api.py
##########
@@ -389,3 +401,80 @@ def export(self, **kwargs):
"Content-Disposition"
]
return resp
+
+ @expose("/<pk>/thumbnail/<digest>/", methods=["GET"])
+ @protect()
+ @safe
+ @rison(thumbnail_query_schema)
+ def thumbnail(self, pk, digest, **kwargs): # pylint: disable=invalid-name
+ """Get Dashboard thumbnail
+ ---
+ get:
+ description: >-
+ Compute async or get already computed dashboard thumbnail from
cache
+ parameters:
+ - in: path
+ schema:
+ type: integer
+ name: pk
+ - in: path
+ name: digest
+ description: A hex digest that makes this dashboard unique
+ schema:
+ type: string
+ - in: query
+ name: q
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ force:
+ type: boolean
+ default: false
+ responses:
+ 200:
+ description: Dashboard thumbnail image
+ content:
+ image/*:
+ schema:
+ type: string
+ format: binary
+ 202:
+ description: Thumbnail does not exist on cache, fired async to
compute
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ message:
+ type: string
+ 401:
+ $ref: '#/components/responses/401'
+ 404:
+ $ref: '#/components/responses/404'
+ 422:
+ $ref: '#/components/responses/422'
+ 500:
+ $ref: '#/components/responses/500'
+ """
+ dashboard = self.datamodel.get(pk, self._base_filters)
+ if not dashboard:
+ return self.response_404()
+ # If force, request a screenshot from the workers
+ if kwargs["rison"].get("force", False):
+ cache_dashboard_thumbnail.delay(dashboard.id, force=True)
+ return self.response(202, message="OK Async")
+ # fetch the dashboard screenshot using the current user and cache if
set
+ screenshot =
DashboardScreenshot(pk).get_from_cache(cache=thumbnail_cache)
+ # If the screenshot does not exist, request one from the workers
+ if not screenshot:
+ cache_dashboard_thumbnail.delay(dashboard.id, force=True)
+ return self.response(202, message="OK Async")
+ # If digests
+ if dashboard.digest != digest:
+ logger.info("Requested thumbnail digest differs from actual
digest")
+ return self.response(304, message="Digest differs")
Review comment:
It's now 302 has we talked
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]