fix: keep release downloads on configured origin
Signed Release / release (push) Successful in 7m18s
Signed Release / release (push) Successful in 7m18s
This commit is contained in:
@@ -50,7 +50,6 @@ public class SystemUpdateService {
|
||||
private static final int MAX_RELEASE_HISTORY = 20;
|
||||
private static final int MAX_RELEASE_ASSETS = 32;
|
||||
private static final int MAX_ASSET_NAME_CHARS = 255;
|
||||
private static final int MAX_ASSET_URL_CHARS = 4_096;
|
||||
|
||||
private final UpdateProperties properties;
|
||||
private final ObjectMapper objectMapper;
|
||||
@@ -266,6 +265,16 @@ public class SystemUpdateService {
|
||||
+ encode(repository[1]) + "/releases" + suffix);
|
||||
}
|
||||
|
||||
private URI releaseAssetUri(String tag, String name) {
|
||||
String[] repository = properties.getRepository().split("/", 2);
|
||||
if (repository.length != 2 || repository[0].isBlank() || repository[1].isBlank()) {
|
||||
throw new ApiException(500, "更新仓库配置无效");
|
||||
}
|
||||
String base = properties.getGiteaBaseUrl().replaceAll("/+$", "");
|
||||
return URI.create(base + "/" + encode(repository[0]) + "/" + encode(repository[1])
|
||||
+ "/releases/download/" + encode(tag) + "/" + encode(name));
|
||||
}
|
||||
|
||||
private JsonNode fetchReleaseJson(URI uri) {
|
||||
HttpRequest.Builder builder = HttpRequest.newBuilder(uri)
|
||||
.timeout(Duration.ofSeconds(Math.max(1, properties.getRequestTimeoutSeconds())))
|
||||
@@ -327,15 +336,12 @@ public class SystemUpdateService {
|
||||
List<ReleaseAsset> assets = new ArrayList<>();
|
||||
for (JsonNode node : root.path("assets")) {
|
||||
String name = text(node, "name");
|
||||
String downloadUrl = text(node, "browser_download_url");
|
||||
if (name.isBlank() || name.length() > MAX_ASSET_NAME_CHARS
|
||||
|| downloadUrl.isBlank() || downloadUrl.length() > MAX_ASSET_URL_CHARS) {
|
||||
if (name.isBlank() || name.length() > MAX_ASSET_NAME_CHARS) {
|
||||
throw new ApiException(502, "Release 文件信息无效");
|
||||
}
|
||||
validateAssetUrl(downloadUrl);
|
||||
assets.add(new ReleaseAsset(
|
||||
name,
|
||||
downloadUrl,
|
||||
releaseAssetUri(tag, name).toString(),
|
||||
node.path("size").asLong(0)
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user