refactor(expo-updates): 优化更新ID生成逻辑,基于bundle hash确保ID唯一性
This commit is contained in:
@@ -73,8 +73,12 @@ export class ExpoUpdatesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ID 基于 bundle hash 生成,确保内容不变时 ID 固定
|
||||||
|
const updateId = this.configService.get<string>('EXPO_UPDATE_ID')
|
||||||
|
|| this.hashToUUID(bundleHash);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: this.configService.get<string>('EXPO_UPDATE_ID') || this.generateId(),
|
id: updateId,
|
||||||
createdAt: this.configService.get<string>('EXPO_CREATED_AT') || new Date().toISOString(),
|
createdAt: this.configService.get<string>('EXPO_CREATED_AT') || new Date().toISOString(),
|
||||||
runtimeVersion: configRuntimeVersion || runtimeVersion,
|
runtimeVersion: configRuntimeVersion || runtimeVersion,
|
||||||
launchAsset: {
|
launchAsset: {
|
||||||
@@ -93,9 +97,12 @@ export class ExpoUpdatesService {
|
|||||||
return { type: 'noUpdateAvailable' };
|
return { type: 'noUpdateAvailable' };
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateId(): string {
|
/**
|
||||||
const timestamp = Date.now().toString(36);
|
* 将 hash 转换为 UUID 格式
|
||||||
const random = Math.random().toString(36).substring(2, 10);
|
*/
|
||||||
return `${timestamp}-${random}`;
|
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)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user