import { Platform, Linking } from 'react-native' import { apiRequest } from '../core/http' import { getConfig } from '../core/config' export interface AppUpdateInfo { needsUpdate: boolean versionName?: string versionCode?: number downloadUrl?: string changeLog?: string forceUpdate?: boolean appStoreUrl?: string marketUrl?: string } export interface RnUpdateInfo { needsUpdate: boolean latestVersion: string downloadUrl: string md5: string minCommonVersion: string note: string } export const UpdateSDK = { async checkAppUpdate(currentVersionCode: number): Promise { const config = getConfig() return apiRequest('/api/v1/updates/app/check', { params: { appId: config.appId, platform: Platform.OS === 'android' ? 'ANDROID' : 'IOS', currentVersionCode: String(currentVersionCode), }, }) }, async openAppStore(appStoreUrl?: string, marketUrl?: string): Promise { const url = Platform.OS === 'ios' ? appStoreUrl : marketUrl if (url) await Linking.openURL(url) }, async checkRnUpdate(moduleId: string, currentVersion: string): Promise { const config = getConfig() return apiRequest('/api/v1/rn/update/check', { params: { appId: config.appId, moduleId, platform: Platform.OS === 'android' ? 'ANDROID' : 'IOS', currentVersion, }, }) }, }