Skip to content

Commit b24f9d7

Browse files
authored
Merge pull request #829 from xiaomakuaiz/fix/mobile-app-update-url
fix(mobile): correct app update version endpoint
2 parents 51a093d + e2f563e commit b24f9d7

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

mobile/app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"typedRoutes": true
9797
},
9898
"extra": {
99-
"updatesServer": "https://release.monkeycode-ai.com"
99+
"updatesServer": "https://release.monkeycode-ai.com/public/mobile"
100100
}
101101
}
102102
}

mobile/ota-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ node ota-server/server.js # 默认 :4747,读 ../dist
2626
## 二点五、检查更新的逻辑(原生优先,对用户不暴露"热更新")
2727

2828
客户端「检查更新」是一条统一、按优先级的流程:
29-
1. 先查**有没有更新的原生版本** —— `GET /app-version/<platform>.json``ios.json` / `android.json`,返回 `{ version, url }`)。客户端用 path 而非 query,所以**可直接当静态文件托管在 OSS/CDN**(每个平台一个 JSON)。本地 server 从 `ota-server/native-release.json` 生成这两个响应;放 OSS 时就上传两个静态文件。若 `version` > 已装的 `Constants.nativeAppVersion` → 提示"发现新版本 vX,去更新" → 打开下载/商店链接(**OTA 推不动原生,必须装新包**)。
29+
1. 先查**有没有更新的原生版本** —— `GET /app-version/<platform>.json`生产路径如 `https://release.monkeycode-ai.com/public/mobile/app-version/android.json`,返回 `{ version, url }``version` 必须是可比较的数字版本(如日期 `26070603`),`url` 必须是 `http(s)` 下载/商店地址。客户端用 path 而非 query,所以**可直接当静态文件托管在 OSS/CDN**(每个平台一个 JSON)。本地 server 从 `ota-server/native-release.json` 生成这两个响应;放 OSS 时就上传两个静态文件。若 `version` > 已装的 `Constants.nativeAppVersion` → 提示"发现新版本 vX,去更新" → 打开下载/商店链接(**OTA 推不动原生,必须装新包**)。
3030
2. 原生已是最新 → 再查 **OTA**,有就提示"是否立即更新" → 下载并重启。
3131
3. 都没有 → "已是最新"。
3232

mobile/src/updates/useOtaUpdate.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export function currentOtaId(): string | null {
6363
}
6464

6565
export type AppUpdate = { version: string; url: string } | null;
66+
const APP_VERSION_RE = /^\d+$/;
67+
68+
function isHttpUrl(value: string): boolean {
69+
return /^https?:\/\//i.test(value);
70+
}
6671

6772
/**
6873
* 检查是否有更新的「原生版本」(新安装包)。比 OTA 优先:原生改动 OTA 推不动,
@@ -71,17 +76,21 @@ export type AppUpdate = { version: string; url: string } | null;
7176
*
7277
* 用 path 而非 query:`<updatesServer>/app-version/<platform>.json` —— 这样可以直接
7378
* 作为静态文件托管在 OSS/CDN 上(每个平台一个 JSON,内容为 { version, url })。
79+
* 生产 updatesServer 指向发布静态目录,如 https://release.monkeycode-ai.com/public/mobile。
7480
*/
7581
export async function checkAppUpdate(): Promise<AppUpdate> {
7682
const base = (Constants.expoConfig?.extra as { updatesServer?: string } | undefined)?.updatesServer?.replace(/\/$/, '');
7783
const installed = installedAppVersion();
7884
if (!base || !installed) return null;
7985
try {
80-
const res = await fetch(`${base}/app-version/${Platform.OS}.json`);
86+
const res = await fetch(`${base}/app-version/${Platform.OS}.json?_=${Date.now()}`, { cache: 'no-store' });
8187
if (!res.ok) return null;
82-
const j = (await res.json()) as { version?: string; url?: string };
83-
if (j?.version && String(j.version) > installed) {
84-
return { version: String(j.version), url: String(j.url || '') };
88+
const j = (await res.json()) as { version?: unknown; url?: unknown };
89+
const version = typeof j?.version === 'string' ? j.version.trim() : '';
90+
const url = typeof j?.url === 'string' ? j.url.trim() : '';
91+
if (!APP_VERSION_RE.test(version) || !isHttpUrl(url)) return null;
92+
if (version > installed) {
93+
return { version, url };
8594
}
8695
return null;
8796
} catch {

0 commit comments

Comments
 (0)