AppImage / appimage.github.io

Given an URL to an AppImage, the GitHub action in this project inspects the AppImage and puts it into a community-maintained catalog
https://appimage.github.io/
Other
295 stars 545 forks source link

Use client-side JavaScript to get the latest release from GitHub #61

Open probonopd opened 7 years ago

probonopd commented 7 years ago

AppImageHub is a repository of AppImages available on the net, but we don't want to keep track of each version released. It is a vital part of the AppImage philosophy that there should be no intermediaries between application authors and users, and in the very same second a releases is made available, it should be "there" for download for users. Hence, for AppImages made available on GitHub Releases, we could use the GitHub API on the client side to get the latest AppImage.

Something along the lines of https://stackoverflow.com/questions/24987542/

<script type="text/javascript">
    $(document).ready(function () {
        GetLatestReleaseInfo();
    });

    function GetLatestReleaseInfo() {
        $.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function (release) {
            var asset = release.assets[0];
            var downloadCount = 0;
            for (var i = 0; i < release.assets.length; i++) {
                downloadCount += release.assets[i].download_count;
            }
            var oneHour = 60 * 60 * 1000;
            var oneDay = 24 * oneHour;
            var dateDiff = new Date() - new Date(asset.updated_at);
            var timeAgo;
            if (dateDiff < oneDay)
            {
                timeAgo = (dateDiff / oneHour).toFixed(1) + " hours ago";
            }
            else
            {
                timeAgo = (dateDiff / oneDay).toFixed(1) + " days ago";
            }
            var releaseInfo = release.name + " was updated " + timeAgo + " and downloaded " + downloadCount.toLocaleString() + " times.";
            $(".sharex-download").attr("href", asset.browser_download_url);
            $(".release-info").text(releaseInfo);
            $(".release-info").fadeIn("slow");
        });
    }
</script>

TODO: Iterate through all AppImages that may be in the latest release and return the download link for the one matching the architecture the browser is running.

Help from JavaScript wizards highly appreciated.

probonopd commented 7 years ago
TheAssassin commented 7 years ago

I don't think that this is really useful to anyone. A simple download link to the latest version should work fine (which we got when there's AppImageUpdate support), following the snappy pragma "versions mean nothing, they're just tags".

probonopd commented 7 years ago

Correct. But where do we get the information about what is the "latest version" from? Right, the GitHub API. And directly from there to the client, without a roundtrip over our repository.

TheAssassin commented 7 years ago

What I meant is, the "version" value (e.g. "the latest version is 1.0.1 released 2017-8-9"), doesn't really add anything to the page. Some information, like "the AppImage was last updated at " is more interesting to me. That could be implemented by making a HEAD request to the actual download URL and evaluating the Last-Modified header, which is provided by most web servers (works even for GitHub releases, I just checked that). You don't need to implement any kind of special API for this to work, even VanillaJS can do it.

That said, for either approach, there's some privacy related problems. Whenever visiting an application page on AppImageHub, the browser would "call home" by making a request to whatever server the AppImage is hosted on. For the same reason, I'm not very fond of embedding <img> tags pointing to the screenshot URLs in the AppStream files, and like the "make my own screenshot" approach you implemented so far, whose primary intention is to make sure that the screenshots aren't outdated or differ from reality in any other way, but also improve the privacy.