summarylogtreecommitdiffstats
path: root/get_latest
blob: 2d8e6850047b49bf88f56f5e52a159418c98e53f (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
#!/bin/node

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

const arch = process.argv.slice(2)[0];
if (arch == undefined) {
  process.exit(1);
}

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) {
    let urls = config[arch + 'DownloadUrl'];
    if (urls == undefined || urls.appimage == undefined) {
      process.exit(1);
    }
    console.log(urls.appimage);
  });

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