diff --git a/src/apps/haikudepot/WebAppInterface.cpp b/src/apps/haikudepot/WebAppInterface.cpp index 79092c150d..608a6bbc2d 100644 --- a/src/apps/haikudepot/WebAppInterface.cpp +++ b/src/apps/haikudepot/WebAppInterface.cpp @@ -372,6 +372,46 @@ WebAppInterface::RetrieveUserRatings(const BString& packageName, } +status_t +WebAppInterface::RetrieveScreenshot(const BString& code, + int32 width, int32 height, BDataIO* stream) +{ + BString urlString = "https://depot.haiku-os.org/pkgscreenshot/"; + urlString << code << ".png" + << "?tw=" << width << "&th=" << height; + + BUrl url(urlString); + + ProtocolListener listener; + listener.SetDownloadIO(stream); + + BHttpHeaders headers; + headers.AddHeader("User-Agent", "X-HDS-Client"); + + BHttpRequest request(url, true, "HTTP", &listener); + request.SetMethod(B_HTTP_GET); + request.SetHeaders(headers); + + thread_id thread = request.Run(); + wait_for_thread(thread, NULL); + + const BHttpResult& result = dynamic_cast( + request.Result()); + + int32 statusCode = result.StatusCode(); + + if (statusCode == 200) + return B_OK; + + fprintf(stderr, "failed to get screenshot from '%s': %" B_PRIi32 "\n", + urlString.String(), statusCode); + return B_ERROR; +} + + +// #pragma mark - private + + status_t WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString, BMessage& reply) const diff --git a/src/apps/haikudepot/WebAppInterface.h b/src/apps/haikudepot/WebAppInterface.h index f978580957..074c627231 100644 --- a/src/apps/haikudepot/WebAppInterface.h +++ b/src/apps/haikudepot/WebAppInterface.h @@ -48,6 +48,10 @@ public: int resultOffset, int maxResults, BMessage& message); + status_t RetrieveScreenshot( + const BString& code, + int32 width, int32 height, + BDataIO* stream); private: status_t _SendJsonRequest(const char* domain, BString jsonString, BMessage& reply) const;