有一个GitHub的链接,用于在最新版本的存储库中下载文件? [英] Is there a link to GitHub for downloading a file in the latest release of a repository?

查看:165
本文介绍了有一个GitHub的链接,用于在最新版本的存储库中下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用需要这个工作。



另外对于您设置最新版本的URL下载按钮很重要: https://github.com / ShareX / ShareX / release / latest



所以如果浏览器不支持ajax(或javascript)或太慢得不到URL,那么下载按钮仍然可以工作。



当Ajax请求完成后,此按钮的URL将自动更改为直接下载URL。



编辑:



我还下载了显示多个版本的下载页面,您可以在这里找到: htt ps://getsharex.com/downloads/



您可以执行查看页面源来检查怎么运行的。但您也可以从这里查看: https:/ /github.com/ShareX/sharex.github.io/blob/master/downloads/index.html


Using GitHub's Release feature, it is possible to provide a link to download a specific version of the published software. However, every time a release is made, the gh-page also needs to be updated.

Is there a way to get a link to a specific file of whatever the latest version of a software is?

e.g., this would be a static link:

https://github.com/USER/PROJECT/releases/download/v0.0.0/package.zip

What I'd like is something like:

https://github.com/USER/PROJECT/releases/download/latest/package.zip

NOTE: The difference between this question and GitHub latest release is that this question specifically asks for getting access to the file, not the GitHub latest release page

解决方案

You can do ajax request to get latest release download URL using GitHub Releases API like this:

<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>

It also shows when it was released and what the download count is:

jQuery needed for this to work.

Also it is important for you to set latest release URL to download button like this: https://github.com/ShareX/ShareX/releases/latest

So if browser does not support ajax (or javascript) or is too slow to get the URL, the download button will still work.

When Ajax request complete then URL of this button will change automatically to direct download URL.

Edit:

I also made downloads page that shows multiple releases which you can find here: https://getsharex.com/downloads/

You can do View page source to check how it works. But also you can see it from here: https://github.com/ShareX/sharex.github.io/blob/master/downloads/index.html

这篇关于有一个GitHub的链接,用于在最新版本的存储库中下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆