-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow updating AppImages from www.appimagehub.com and www.pling…
- Loading branch information
Showing
4 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// system | ||
#include <fnmatch.h> | ||
#include <regex> | ||
|
||
//libraries | ||
#include <cpr/cpr.h> | ||
|
||
//local | ||
#include "pling_v1_zsync.h" | ||
|
||
const char* appimage::update::methods::PlingV1Zsync::plingContentEndpointUrl = "https://api.pling.com/ocs/v1/content/data/"; | ||
|
||
appimage::update::methods::PlingV1Zsync::PlingV1Zsync(std::vector<std::string> updateStringParts) : | ||
productId(updateStringParts[1]), fileMatchingPattern(updateStringParts[2]) { | ||
|
||
} | ||
|
||
std::vector<std::string> appimage::update::methods::PlingV1Zsync::getAvailableDownloads() { | ||
std::vector<std::string> downloads; | ||
|
||
cpr::Url productDetailsUrl = plingContentEndpointUrl + productId; | ||
auto response = cpr::Get(productDetailsUrl); | ||
if (response.status_code >= 200 && response.status_code < 300) { | ||
std::regex urlRegex(R"((?:\<downloadlink\d+\>)(.*?)(?:<\/downloadlink\d+\>))"); | ||
|
||
std::string text = response.text; | ||
std::smatch match; | ||
|
||
// match download link | ||
while (std::regex_search(text, match, urlRegex)) { | ||
// extract second matched group which contains the actual url | ||
std::string url = match[1].str(); | ||
|
||
// apply file matching patter to the file name | ||
auto fileName = url.substr(url.rfind('/') + 1); | ||
if (fnmatch(fileMatchingPattern.data(), fileName.data(), 0) == 0) | ||
downloads.push_back(url); | ||
|
||
text = match.suffix(); | ||
} | ||
} | ||
|
||
return downloads; | ||
} | ||
|
||
std::string appimage::update::methods::PlingV1Zsync::findLatestRelease(const std::vector<std::string>& downloads) { | ||
std::string latestReleaseUrl; | ||
std::string latestReleaseFileName; | ||
|
||
for (const auto& url: downloads) { | ||
auto file_name = url.substr(url.rfind('/') + 1); | ||
|
||
// keep only the latest release | ||
if (file_name > latestReleaseFileName) { | ||
latestReleaseUrl = std::string(url); | ||
latestReleaseFileName = std::string(file_name); | ||
} | ||
} | ||
|
||
return latestReleaseUrl; | ||
} | ||
|
||
std::string appimage::update::methods::PlingV1Zsync::resolveZsyncUrl(const std::string& downloadUrl) { | ||
// pling.com creates zsync files for every uploaded file, we just need to append .zsync | ||
return downloadUrl + ".zsync"; | ||
} | ||
|
||
bool appimage::update::methods::PlingV1Zsync::isUpdateStringAccepted(std::vector<std::string> updateStringParts) { | ||
return updateStringParts.size() == 3 && updateStringParts[0] == "pling-v1-zsync"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
// system | ||
#include <string> | ||
#include <vector> | ||
|
||
//libraries | ||
|
||
//local | ||
|
||
|
||
|
||
namespace appimage { | ||
namespace update { | ||
namespace methods { | ||
/** | ||
* Pling is a family of services which include an AppImage store among many other things. AppImage files are | ||
* served from the www.appimagehub.com and www.pling.com urls. They are also available through an xml API | ||
* `https://api.pling.com/ocs/v1/` | ||
* | ||
* format: pling-v1-zsync|<content id>|<file name matching pattern> | ||
*/ | ||
class PlingV1Zsync { | ||
public: | ||
explicit PlingV1Zsync(std::vector<std::string> updateStringParts); | ||
|
||
static bool isUpdateStringAccepted(std::vector<std::string> updateStringParts); | ||
|
||
std::vector<std::string> getAvailableDownloads(); | ||
|
||
std::string findLatestRelease(const std::vector<std::string>& downloads); | ||
|
||
std::string resolveZsyncUrl(const std::string& downloadUrl); | ||
|
||
private: | ||
static const char* plingContentEndpointUrl; | ||
std::string productId; | ||
std::string fileMatchingPattern; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters