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)}`; } }