From 71a8d5202cc65a6e714956e78852a7b87ce51b35 Mon Sep 17 00:00:00 2001 From: aunsane Date: Sun, 23 Apr 2017 15:37:35 +0300 Subject: CloudFile: Yandex: generate short donload link --- plugins/CloudFile/src/Services/yandex_api.h | 11 +++++++++++ plugins/CloudFile/src/Services/yandex_service.cpp | 12 +++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'plugins/CloudFile/src/Services') diff --git a/plugins/CloudFile/src/Services/yandex_api.h b/plugins/CloudFile/src/Services/yandex_api.h index 7548f6bd14..f70964bc78 100644 --- a/plugins/CloudFile/src/Services/yandex_api.h +++ b/plugins/CloudFile/src/Services/yandex_api.h @@ -79,6 +79,17 @@ namespace YandexAPI AddUrlParameter("path=%s", ptrA(mir_urlEncode(path))); } }; + + class GetResourcesRequest : public HttpRequest + { + public: + GetResourcesRequest(const char *token, const char *path) : + HttpRequest(REQUEST_GET, YADISK_API) + { + AddOAuthHeader(token); + AddUrlParameter("path=%s", ptrA(mir_urlEncode(path))); + } + }; }; #endif //_YANDEXSERVICE_API_H_ diff --git a/plugins/CloudFile/src/Services/yandex_service.cpp b/plugins/CloudFile/src/Services/yandex_service.cpp index 03f34a432e..d7b2e8b9e6 100644 --- a/plugins/CloudFile/src/Services/yandex_service.cpp +++ b/plugins/CloudFile/src/Services/yandex_service.cpp @@ -149,11 +149,17 @@ void CYandexService::CreateFolder(const char *path) void CYandexService::CreateSharedLink(const char *path, char *url) { ptrA token(db_get_sa(NULL, GetModule(), "TokenSecret")); - YandexAPI::PublishRequest request(token, path); - NLHR_PTR response(request.Send(hConnection)); + YandexAPI::PublishRequest publishRequest(token, path); + NLHR_PTR response(publishRequest.Send(hConnection)); + + GetJsonResponse(response); + + YandexAPI::GetResourcesRequest resourcesRequest(token, path); + response = resourcesRequest.Send(hConnection); JSONNode root = GetJsonResponse(response); - JSONNode link = root.at("href"); + JSONNode link = root.at("public_url"); + mir_strcpy(url, link.as_string().c_str()); } -- cgit v1.2.3