Skip to content

Commit

Permalink
v2.6.4 修复 Modrinth 查找范围, 修复鬼斩构建站直链错误
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed Jul 11, 2024
1 parent f60e112 commit 0acf793
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.aplini</groupId>
<artifactId>AutoUpdatePlugins</artifactId>
<version>2.6.2</version>
<version>2.6.4</version>
<packaging>jar</packaging>

<name>AutoUpdatePlugins</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,18 +587,20 @@ else if(url.contains("://modrinth.com/")){ // Modrinth 页面
if(matcher.find()) {
String data = httpGet("https://api.modrinth.com/v2/project"+ matcher.group(0) +"/version");
if(data == null){return null;}
// 0 为最新的一个版本
Map<?, ?> map = (Map<?, ?>) ((ArrayList<?>) new Gson().fromJson(data, ArrayList.class)).get(0);
ArrayList<?> files = (ArrayList<?>) map.get("files");

// 遍历发布文件列表
for(Object _li : files){
Map<?, ?> li = (Map<?, ?>) _li;
String fileName = (String) li.get("filename");
if(matchFileName.isEmpty() || Pattern.compile(matchFileName).matcher(fileName).matches()){
String dUrl = (String) li.get("url");
log(logLevel.DEBUG, _nowParser + m.piece(m.debugGetVersion, dUrl));
return dUrl;
ArrayList<?> versions = new Gson().fromJson(data, ArrayList.class);
// 遍历版本列表
for(Object _version : versions){
Map<?, ?> version = (Map<?, ?>) _version;
ArrayList<?> files = (ArrayList<?>) version.get("files");
// 遍历发布文件列表
for(Object _file : files){
Map<?, ?> file = (Map<?, ?>) _file;
String fileName = (String) file.get("filename");
if(matchFileName.isEmpty() || Pattern.compile(matchFileName).matcher(fileName).matches()){
String dUrl = (String) file.get("url");
log(logLevel.DEBUG, _nowParser + m.piece(m.debugGetVersion, dUrl));
return dUrl;
}
}
}
log(logLevel.WARN, "[Modrinth] "+ m.piece(m.debugNoFileMatching, url));
Expand All @@ -622,13 +624,17 @@ else if(url.contains("://builds.guizhanss.com/")){ // 鬼斩构建站
// 获取路径 "/ApliNi/plugin/master"
Matcher matcher = Pattern.compile("/([^/]+)/([^/]+)/([^/]+)$").matcher(url);
if(matcher.find()){
// 获取所有发布中的第一个版本
String data = httpGet("https://builds.guizhanss.com/api/builds" + matcher.group(0));
if(data == null){return null;}
ArrayList<?> arr = (ArrayList<?>) new Gson().fromJson(data, HashMap.class).get("data");
Map<?, ?> map = (Map<?, ?>) arr.get(arr.size() - 1); // 获取最后一项

String dUrl = "https://builds.guizhanss.com/r2"+ matcher.group(0) +"/"+ map.get("target");
// 此部分注释的代码被新的 API 替代
// // 获取所有发布中的第一个版本
// String data = httpGet("https://builds.guizhanss.com/api/builds" + matcher.group(0));
// if(data == null){return null;}
// ArrayList<?> arr = (ArrayList<?>) new Gson().fromJson(data, HashMap.class).get("data");
// Map<?, ?> map = (Map<?, ?>) arr.get(arr.size() - 1); // 获取最后一项
//
// String dUrl = "https://builds.guizhanss.com/r2"+ matcher.group(0) +"/"+ map.get("target");

// 现在可以获取直连
String dUrl = "https://builds.guizhanss.com/api/download"+ matcher.group(0) +"/latest";
log(logLevel.DEBUG, _nowParser + m.piece(m.debugGetVersion, dUrl));
return dUrl;
}
Expand Down

0 comments on commit 0acf793

Please sign in to comment.