Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
264d5495e6 | ||
|
|
8954902994 | ||
|
|
09a8547ded | ||
|
|
b800069c82 | ||
|
|
82110e36b7 | ||
|
|
5604edc00b | ||
|
|
79059e7818 | ||
|
|
7294e9050d | ||
|
|
7d87ca7a86 | ||
|
|
4b943e887d | ||
|
|
6b2841274d | ||
|
|
d5ccfbb231 | ||
|
|
359eac8985 | ||
|
|
96750730d3 | ||
|
|
725503152e |
@@ -11,7 +11,7 @@
|
||||
|
||||
<groupId>com.imyeyu.timiserverapi</groupId>
|
||||
<artifactId>TimiServerAPI</artifactId>
|
||||
<version>1.0.72</version>
|
||||
<version>1.0.77</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>TimiServerAPI</name>
|
||||
<description>imyeyu.com API</description>
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.EqualsAndHashCode;
|
||||
///
|
||||
/// 应用发布通道
|
||||
///
|
||||
/// 通道只持有一个指针,回滚就是改指向,发布记录本身不可变
|
||||
/// 通道分别持有热更包和原生包指针
|
||||
///
|
||||
/// @author Codex
|
||||
/// @since 2026-11-06
|
||||
@@ -24,7 +24,13 @@ public class AppChannel extends UUIDEntity {
|
||||
/// 通道名称
|
||||
protected String name;
|
||||
|
||||
/// 当前指向的发布 ID,为空表示该通道无发布
|
||||
/// 当前热更包发布 ID
|
||||
protected String bundleReleaseId;
|
||||
|
||||
/// 当前原生包发布 ID
|
||||
protected String nativeReleaseId;
|
||||
|
||||
/// 过渡期旧指针
|
||||
protected String releaseId;
|
||||
|
||||
/// 最后操作人用户 ID
|
||||
|
||||
@@ -44,4 +44,11 @@ public interface AppChannelMapper extends BaseMapper<AppChannel, String> {
|
||||
@Param("updatedBy") String updatedBy,
|
||||
@Param("updatedAt") Long updatedAt
|
||||
);
|
||||
/// 按类型切换指针并同步旧指针
|
||||
@Update("UPDATE app_channel SET bundle_release_id = CASE WHEN #{nativeRelease} = false THEN #{releaseId} ELSE bundle_release_id END, native_release_id = CASE WHEN #{nativeRelease} = true THEN #{releaseId} ELSE native_release_id END, release_id = #{releaseId}, updated_by = #{updatedBy}, updated_at = #{updatedAt} WHERE id = #{id}")
|
||||
int updatePointers(@Param("id") String id, @Param("releaseId") String releaseId, @Param("nativeRelease") boolean nativeRelease, @Param("updatedBy") String updatedBy, @Param("updatedAt") Long updatedAt);
|
||||
|
||||
/// 清除所有通道中指向撤回记录的指针
|
||||
@Update("UPDATE app_channel SET bundle_release_id = CASE WHEN bundle_release_id = #{releaseId} THEN NULL ELSE bundle_release_id END, native_release_id = CASE WHEN native_release_id = #{releaseId} THEN NULL ELSE native_release_id END, release_id = CASE WHEN release_id = #{releaseId} THEN NULL ELSE release_id END, updated_by = #{updatedBy}, updated_at = #{updatedAt} WHERE product_id = #{productId} AND deleted_at IS NULL AND (bundle_release_id = #{releaseId} OR native_release_id = #{releaseId} OR release_id = #{releaseId})")
|
||||
int clearRelease(@Param("productId") String productId, @Param("releaseId") String releaseId, @Param("updatedBy") String updatedBy, @Param("updatedAt") Long updatedAt);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.imyeyu.java.TimiJava;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -42,6 +43,18 @@ public class AppVersionService {
|
||||
/// 内置包版本标识
|
||||
public static final String BUILTIN_VERSION = "builtin";
|
||||
|
||||
/// 首个能处理外壳安装包的 Web 包版本
|
||||
///
|
||||
/// 更早的包不认识 shell 标记,只会把 url 当热更 zip 交给插件解压,拿到 APK 必然失败。
|
||||
/// 通道指向原生包时,低于这个版本的设备改为下发热更包,先把它升到能自升级为止
|
||||
public static final String SHELL_AWARE_VERSION = "1.3.2";
|
||||
|
||||
/// 首个按独立字段接收外壳更新的 Web 包版本
|
||||
///
|
||||
/// 从这版起响应把安装包放到 shellUrl,主字段 url 永远给热更包;
|
||||
/// 更早的包只认「主字段 + shell 标记」,所以两套语义要并存到 1.5.0 铺开为止
|
||||
public static final String SHELL_JSON_AWARE_VERSION = "1.5.0";
|
||||
|
||||
/// 更新日志最多返回的版本条数
|
||||
public static final int MAX_NOTES = 20;
|
||||
|
||||
@@ -66,21 +79,26 @@ public class AppVersionService {
|
||||
if (product == null) {
|
||||
return AppUpdateCheckResponse.none(currentVersion);
|
||||
}
|
||||
AppRelease release = resolveChannelRelease(product, req);
|
||||
if (release == null) {
|
||||
return AppUpdateCheckResponse.none(currentVersion);
|
||||
}
|
||||
int currentCode = parseInt(req.getVersionCode(), 0);
|
||||
if (release.getKind() == AppRelease.Kind.NATIVE) {
|
||||
AppRelease target = resolveNative(release, currentCode);
|
||||
return target == null
|
||||
? AppUpdateCheckResponse.none(currentVersion)
|
||||
: buildResponse(target, Boolean.TRUE.equals(target.getMandatory()), true);
|
||||
AppRelease bundlePointer = resolvePointer(product, req, AppRelease.Kind.BUNDLE);
|
||||
AppRelease nativePointer = resolvePointer(product, req, AppRelease.Kind.NATIVE);
|
||||
AppRelease bundle = bundlePointer == null ? null : resolveBundle(bundlePointer, product, currentCode, currentVersion, req.getDeviceId());
|
||||
AppRelease nativeTarget = nativePointer == null ? null : resolveNative(nativePointer, currentCode);
|
||||
boolean shellAware = 0 <= compareVersion(currentVersion, SHELL_AWARE_VERSION);
|
||||
boolean jsonAware = 0 <= compareVersion(currentVersion, SHELL_JSON_AWARE_VERSION);
|
||||
// 认识 shell 标记但还不认识独立字段的包,主字段继续给安装包
|
||||
if (nativeTarget != null && shellAware && !jsonAware) {
|
||||
return buildResponse(nativeTarget, Boolean.TRUE.equals(nativeTarget.getMandatory()), true);
|
||||
}
|
||||
AppRelease target = resolveBundle(release, product, currentCode, currentVersion, req.getDeviceId());
|
||||
return target == null
|
||||
? AppUpdateCheckResponse.none(currentVersion)
|
||||
: buildResponse(target, false, false);
|
||||
AppUpdateCheckResponse response = bundle == null ? AppUpdateCheckResponse.none(currentVersion) : buildResponse(bundle, false, false);
|
||||
if (nativeTarget != null && jsonAware) {
|
||||
AppUpdateCheckResponse shell = buildResponse(nativeTarget, false, true);
|
||||
response.setShellUrl(shell.getUrl());
|
||||
response.setShellVersion(shell.getVersion());
|
||||
response.setShellChecksum(shell.getChecksum());
|
||||
response.setShellMandatory(Boolean.TRUE.equals(nativeTarget.getMandatory()));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/// 查询更新日志
|
||||
@@ -100,9 +118,12 @@ public class AppVersionService {
|
||||
if (product == null) {
|
||||
return new AppUpdateNotesResponse(null, Collections.emptyList());
|
||||
}
|
||||
AppRelease target = resolveChannelRelease(product, req);
|
||||
// 原生包更新走安装包,与热更日志无关
|
||||
if (target == null || target.getKind() == AppRelease.Kind.NATIVE) {
|
||||
AppRelease target = resolvePointer(product, req, AppRelease.Kind.BUNDLE);
|
||||
// 指针为空(刚建通道还没发过热更)时退回最近一次发布,日志不该跟着空
|
||||
if (target == null) {
|
||||
target = latestPublishedBundle(product);
|
||||
}
|
||||
if (target == null) {
|
||||
return new AppUpdateNotesResponse(null, Collections.emptyList());
|
||||
}
|
||||
// 当前版本不低于通道版本:已是最新,或回滚后反而超前
|
||||
@@ -156,17 +177,22 @@ public class AppVersionService {
|
||||
/// @param product 产品
|
||||
/// @param req 插件上报信息
|
||||
/// @return 发布记录,通道为空或指向的记录不可用时为 null
|
||||
private AppRelease resolveChannelRelease(AppProduct product, AppUpdateCheckRequest req) {
|
||||
private AppRelease resolvePointer(AppProduct product, AppUpdateCheckRequest req, AppRelease.Kind kind) {
|
||||
String channelCode = TimiJava.isEmpty(req.getChannel()) ? DEFAULT_CHANNEL : req.getChannel();
|
||||
AppChannel channel = channelMapper.selectByProductAndCode(product.getId(), channelCode);
|
||||
if (channel == null || TimiJava.isEmpty(channel.getReleaseId())) {
|
||||
if (channel == null) {
|
||||
return null;
|
||||
}
|
||||
AppRelease release = releaseMapper.select(channel.getReleaseId());
|
||||
if (release == null || release.getStatus() != AppRelease.Status.PUBLISHED) {
|
||||
String id = kind == AppRelease.Kind.BUNDLE ? channel.getBundleReleaseId() : channel.getNativeReleaseId();
|
||||
// 兼容旧代码在回滚期间仅更新旧指针的情况
|
||||
if (TimiJava.isEmpty(id)) {
|
||||
id = channel.getReleaseId();
|
||||
}
|
||||
if (TimiJava.isEmpty(id)) {
|
||||
return null;
|
||||
}
|
||||
return release;
|
||||
AppRelease release = releaseMapper.select(id);
|
||||
return release != null && release.getKind() == kind && release.getStatus() == AppRelease.Status.PUBLISHED ? release : null;
|
||||
}
|
||||
|
||||
/// 原生包是否需要更新
|
||||
@@ -217,6 +243,23 @@ public class AppVersionService {
|
||||
return release;
|
||||
}
|
||||
|
||||
/// 取最近一次发布的热更包
|
||||
///
|
||||
/// 通道指向原生包时,更新日志没有「通道版本」可用,改用这里兜底。
|
||||
/// 日志是「这个产品最近发了什么」,与设备能不能装无关,所以不套灰度与兼容区间
|
||||
///
|
||||
/// @param product 产品
|
||||
/// @return 版本最高的已发布热更包,没有则返回 null
|
||||
private AppRelease latestPublishedBundle(AppProduct product) {
|
||||
AppRelease latest = null;
|
||||
for (AppRelease item : releaseMapper.selectPublished(product.getId(), AppRelease.Kind.BUNDLE)) {
|
||||
if (latest == null || 0 < compareVersion(item.getVersionName(), latest.getVersionName())) {
|
||||
latest = item;
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
/// 判断设备是否命中灰度
|
||||
///
|
||||
/// @param grayPermille 灰度比例,万分比
|
||||
@@ -248,7 +291,7 @@ public class AppVersionService {
|
||||
.path("/attach/download/")
|
||||
.path(release.getAttachmentId())
|
||||
.toUriString();
|
||||
return new AppUpdateCheckResponse(release.getVersionName(), url, release.getSha256(), mandatory, shell, release.getNote());
|
||||
return new AppUpdateCheckResponse(release.getVersionName(), url, release.getSha256(), mandatory, shell, release.getNote(), null, null, null, null);
|
||||
}
|
||||
|
||||
/// 比较版本号
|
||||
@@ -316,6 +359,7 @@ public class AppVersionService {
|
||||
/// @param grayPermille 灰度比例,为空时保持原值
|
||||
/// @param operatorId 操作人用户 ID
|
||||
/// @param note 变更说明
|
||||
@Transactional
|
||||
public void publish(String releaseId, String channelCode, Integer grayPermille, String operatorId, String note) {
|
||||
AppRelease release = releaseMapper.select(releaseId);
|
||||
if (release == null) {
|
||||
@@ -336,7 +380,7 @@ public class AppVersionService {
|
||||
release.setNote(TimiJava.isEmpty(note) ? release.getNote() : note);
|
||||
release.setUpdatedAt(now);
|
||||
releaseMapper.updateSelective(release);
|
||||
channelMapper.updateReleaseId(channel.getId(), releaseId, operatorId, now);
|
||||
channelMapper.updatePointers(channel.getId(), releaseId, release.getKind() == AppRelease.Kind.NATIVE, operatorId, now);
|
||||
log("APP_RELEASE_PUBLISH", releaseId);
|
||||
}
|
||||
|
||||
@@ -348,6 +392,7 @@ public class AppVersionService {
|
||||
/// @param channelCode 通道代码
|
||||
/// @param targetReleaseId 目标发布 ID
|
||||
/// @param operatorId 操作人用户 ID
|
||||
@Transactional
|
||||
public void rollback(String productId, String channelCode, String targetReleaseId, String operatorId) {
|
||||
AppChannel channel = channelMapper.selectByProductAndCode(productId, channelCode);
|
||||
if (channel == null) {
|
||||
@@ -362,7 +407,7 @@ public class AppVersionService {
|
||||
target.setStatus(AppRelease.Status.PUBLISHED);
|
||||
target.setUpdatedAt(now);
|
||||
releaseMapper.updateSelective(target);
|
||||
channelMapper.updateReleaseId(channel.getId(), targetReleaseId, operatorId, now);
|
||||
channelMapper.updatePointers(channel.getId(), targetReleaseId, target.getKind() == AppRelease.Kind.NATIVE, operatorId, now);
|
||||
log("APP_RELEASE_ROLLBACK", targetReleaseId);
|
||||
}
|
||||
|
||||
@@ -370,6 +415,7 @@ public class AppVersionService {
|
||||
///
|
||||
/// @param releaseId 发布 ID
|
||||
/// @param operatorId 操作人用户 ID
|
||||
@Transactional
|
||||
public void revoke(String releaseId, String operatorId) {
|
||||
AppRelease release = releaseMapper.select(releaseId);
|
||||
if (release == null) {
|
||||
@@ -379,10 +425,7 @@ public class AppVersionService {
|
||||
release.setStatus(AppRelease.Status.REVOKED);
|
||||
release.setUpdatedAt(now);
|
||||
releaseMapper.updateSelective(release);
|
||||
AppChannel channel = channelMapper.selectByProductAndCode(release.getProductId(), DEFAULT_CHANNEL);
|
||||
if (channel != null && releaseId.equals(channel.getReleaseId())) {
|
||||
channelMapper.updateReleaseId(channel.getId(), null, operatorId, now);
|
||||
}
|
||||
channelMapper.clearRelease(release.getProductId(), releaseId, operatorId, now);
|
||||
log("APP_RELEASE_REVOKE", releaseId);
|
||||
}
|
||||
|
||||
@@ -461,7 +504,7 @@ public class AppVersionService {
|
||||
if (release.getStatus() == AppRelease.Status.PUBLISHED) {
|
||||
throw new IllegalArgumentException("已发布的版本不能删除,请先撤回");
|
||||
}
|
||||
releaseMapper.destroy(releaseId);
|
||||
releaseMapper.delete(releaseId);
|
||||
log("APP_RELEASE_DELETE", releaseId);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,11 +39,23 @@ public class AppUpdateCheckResponse {
|
||||
/// 字段名不能叫 message:Capgo 插件把 message 当作错误信息,收到会直接判为检查失败
|
||||
protected String note;
|
||||
|
||||
/// 外壳下载地址
|
||||
protected String shellUrl;
|
||||
|
||||
/// 外壳版本
|
||||
protected String shellVersion;
|
||||
|
||||
/// 外壳 SHA-256
|
||||
protected String shellChecksum;
|
||||
|
||||
/// true 为强制更新
|
||||
protected Boolean shellMandatory;
|
||||
|
||||
/// 构建无更新响应,version 与当前一致时插件不会下载
|
||||
///
|
||||
/// @param currentVersion 当前运行的 Web 包版本
|
||||
/// @return 无更新响应
|
||||
public static AppUpdateCheckResponse none(String currentVersion) {
|
||||
return new AppUpdateCheckResponse(currentVersion, "", null, false, null, null);
|
||||
return new AppUpdateCheckResponse(currentVersion, "", null, false, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +260,9 @@ public class AttachmentController {
|
||||
}
|
||||
|
||||
private void setDownloadHeader(Attachment attachment) throws UnsupportedEncodingException {
|
||||
if (attachment != null && TimiSpring.getRequest().getRequestURI().endsWith("/download") && attachment.getName() != null) {
|
||||
// 路径带 /download 就强制下载:/download/{id} 的结尾是 id,用 endsWith 匹配不到
|
||||
boolean download = TimiSpring.getRequest().getRequestURI().contains("/download");
|
||||
if (attachment != null && download && attachment.getName() != null) {
|
||||
TimiSpring.getResponse().setHeader("Content-Disposition", Network.getFileDownloadHeader(attachment.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
ALTER TABLE `app_channel`
|
||||
ADD COLUMN `bundle_release_id` VARCHAR(36) NULL COMMENT '当前热更包发布 ID' AFTER `name`,
|
||||
ADD COLUMN `native_release_id` VARCHAR(36) NULL COMMENT '当前原生包发布 ID' AFTER `bundle_release_id`;
|
||||
|
||||
UPDATE `app_channel` c JOIN `app_release` r ON r.`id` = c.`release_id`
|
||||
SET c.`native_release_id` = IF(r.`kind` = 'NATIVE', c.`release_id`, NULL),
|
||||
c.`bundle_release_id` = IF(r.`kind` = 'BUNDLE', c.`release_id`,
|
||||
(SELECT b.`id` FROM `app_release` b WHERE b.`product_id` = c.`product_id` AND b.`kind` = 'BUNDLE'
|
||||
AND b.`status` = 'PUBLISHED' AND b.`deleted_at` IS NULL ORDER BY b.`published_at` DESC LIMIT 1));
|
||||
Reference in New Issue
Block a user