From 190bc5bce9d2152350dd97b64377903c3ce6c587 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Fri, 5 Dec 2025 20:11:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(expo-updates):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=9B=B4=E6=96=B0ID=E7=94=9F=E6=88=90=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E5=9F=BA=E4=BA=8Ebundle=20hash=E7=A1=AE=E4=BF=9DID?= =?UTF-8?q?=E5=94=AF=E4=B8=80=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/expo-updates/expo-updates.service.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/expo-updates/expo-updates.service.ts b/src/expo-updates/expo-updates.service.ts index 4d04314..6e72ffc 100644 --- a/src/expo-updates/expo-updates.service.ts +++ b/src/expo-updates/expo-updates.service.ts @@ -73,8 +73,12 @@ export class ExpoUpdatesService { } } + // ID 基于 bundle hash 生成,确保内容不变时 ID 固定 + const updateId = this.configService.get('EXPO_UPDATE_ID') + || this.hashToUUID(bundleHash); + return { - id: this.configService.get('EXPO_UPDATE_ID') || this.generateId(), + id: updateId, createdAt: this.configService.get('EXPO_CREATED_AT') || new Date().toISOString(), runtimeVersion: configRuntimeVersion || runtimeVersion, launchAsset: { @@ -93,9 +97,12 @@ export class ExpoUpdatesService { return { type: 'noUpdateAvailable' }; } - private generateId(): string { - const timestamp = Date.now().toString(36); - const random = Math.random().toString(36).substring(2, 10); - return `${timestamp}-${random}`; + /** + * 将 hash 转换为 UUID 格式 + */ + private hashToUUID(hash: string): string { + // 使用 hash 的前32个字符生成 UUID 格式 + const hex = Buffer.from(hash, 'base64url').toString('hex').padEnd(32, '0').slice(0, 32); + return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`; } }