xref: /MusicFree/src/utils/checkUpdate.ts (revision cf2d630eca034addcb92030a5268105bce30ef82)
1*cf2d630eS猫头猫import axios from 'axios';
2*cf2d630eS猫头猫import {compare} from 'compare-versions';
3*cf2d630eS猫头猫import DeviceInfo from 'react-native-device-info';
4*cf2d630eS猫头猫
5*cf2d630eS猫头猫const updateList = [
6*cf2d630eS猫头猫    'https://gitee.com/maotoumao/testtt/raw/master/release/version.json',
7*cf2d630eS猫头猫];
8*cf2d630eS猫头猫
9*cf2d630eS猫头猫interface IUpdateInfo {
10*cf2d630eS猫头猫    needUpdate: boolean;
11*cf2d630eS猫头猫    data: {
12*cf2d630eS猫头猫        version: string;
13*cf2d630eS猫头猫        changeLog: string[];
14*cf2d630eS猫头猫        download: string[];
15*cf2d630eS猫头猫    };
16*cf2d630eS猫头猫}
17*cf2d630eS猫头猫
18*cf2d630eS猫头猫export default async function checkUpdate(): Promise<IUpdateInfo | undefined> {
19*cf2d630eS猫头猫    const currentVersion = DeviceInfo.getVersion();
20*cf2d630eS猫头猫    for (let i = 0; i < updateList.length; ++i) {
21*cf2d630eS猫头猫        try {
22*cf2d630eS猫头猫            const rawInfo = (await axios.get(updateList[i])).data;
23*cf2d630eS猫头猫            if (compare(rawInfo.version, currentVersion, '>')) {
24*cf2d630eS猫头猫                return {
25*cf2d630eS猫头猫                    needUpdate: true,
26*cf2d630eS猫头猫                    data: rawInfo,
27*cf2d630eS猫头猫                };
28*cf2d630eS猫头猫            }
29*cf2d630eS猫头猫        } catch {}
30*cf2d630eS猫头猫    }
31*cf2d630eS猫头猫}
32