summarylogtreecommitdiffstats
path: root/get_latest
blob: 45370713c84c6095cc2f3560e49da322a1097230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/node

require('console');

const args = process.argv.slice(2)
const archs = args.length < 1 ? [`x86_64`] : args;

const fs = require('fs');
const path = require('path');
const syncRequest = require('sync-request');
const os = require('os');

require('seajs');

const file = "linuxQQDownload"
const url = `https://cdn-go.cn/qq-web/im.qq.com_new/latest/rainbow/${file}.js`
const res = syncRequest('GET', url);

fs.mkdtemp(path.join(os.tmpdir(), "/"), (err, directory) => {
  if (err) throw err;

  seajs.config({
    base: directory,
  });

  fs.writeFileSync(path.join(directory, `${file}.js`), res.body);

  seajs.use(`${file}`, function (config) {
    console.log(`version=${config.version}`);
    console.log(`updateDate=${config.updateDate}`);

    for (const key in archs) {
      const arch = archs[key];

      let config_index;
      switch (arch) {
        case `x86_64`:
          config_index = `x64DownloadUrl`;
          break;
        case `aarch64`:
          config_index = `armDownloadUrl`;
          break;
        case `loong64`:
          config_index = `loongarchDownloadUrl`;
          break;
        default:
          throw new Error(`This arch is currently not supported`);
      }

      console.log(`url_${arch}=${config[config_index].appimage}`);
    }
  });

  fs.rm(directory, { recursive: true }, (err) => {
    if (err) throw err;
  });
});