Fixed "github-master" type URLs

This commit is contained in:
seasnail8169 2021-04-03 01:41:03 +01:00
parent 2123042c9a
commit eb1f0c29d5
1 changed files with 19 additions and 15 deletions

View File

@ -1,32 +1,36 @@
package io.gitlab.jfronny.resclone.fetchers;
import io.gitlab.jfronny.resclone.data.RescloneException;
import io.gitlab.jfronny.resclone.util.UrlUtils;
public class GithubMasterFetcher extends PackFetcher {
@Override
public String getSourceTypeName() {
return "github-master";
}
@Override
public String getDownloadUrl(String baseUrl) throws RescloneException {
public String getDownloadUrl(String baseUrl) throws Exception {
String[] parts = baseUrl.split("/");
String url = "";
if (parts.length == 2) {
url = getStr(parts[0], parts[1], "main");
if (!urlValid(url))
url = getStr(parts[0], parts[1], "master");
}
else if (parts.length == 3) {
url = getStr(parts[0], parts[1], parts[2]);
}
else {
throw new RescloneException("Format for github-master is USER/REPO[/BRANCH]");
String url;
switch (parts.length) {
case 2:
url = getStr(parts[0], parts[1], "main");
if (!UrlUtils.urlValid(url)) url = getStr(parts[0], parts[1], "master");
break;
case 3:
url = getStr(parts[0], parts[1], parts[2]);
break;
default:
throw new Exception("Format for github-master is USER/REPO[/BRANCH]");
}
return url;
}
private String getStr(String user, String repo, String branch) {
return "https://github.com/" + user + "/" + repo + "/archive/" + branch + ".zip";
return "https://github.com/" + user + "/" + repo + "/archive/refs/heads/" + branch + ".zip";
}
}
}