Get release from github, todo use common
This commit is contained in:
parent
83e334c3f8
commit
252d496dc2
|
@ -0,0 +1,53 @@
|
||||||
|
/**
|
||||||
|
* BetterDiscord axios wrapper
|
||||||
|
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
|
||||||
|
* All rights reserved.
|
||||||
|
* https://betterdiscord.net
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
export default class AxiosWrapper {
|
||||||
|
|
||||||
|
static get axios() { return axios; }
|
||||||
|
|
||||||
|
static get(url) { return axios.get(url) }
|
||||||
|
|
||||||
|
static get github() {
|
||||||
|
return this._github ? this._github : (
|
||||||
|
this._github = {
|
||||||
|
main: this.create('https://github.com'),
|
||||||
|
api: this.create('https://api.github.com')
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static get zl() {
|
||||||
|
return this._zl ? this._zl : (this._zl = {
|
||||||
|
api: this.create('https://zl', 1000, this.zlHeaders),
|
||||||
|
cdn: this.create('https://zl', 1000, this.zlHeaders)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static create(baseUrl, timeout = 1000, headers = null) {
|
||||||
|
return axios.create({ baseURL: baseUrl, timeout, headers: headers ? headers : this.defaultHeaders });
|
||||||
|
}
|
||||||
|
|
||||||
|
static get defaultHeaders() {
|
||||||
|
return {
|
||||||
|
'User-Agent': 'BetterDiscordApp User'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static get zlHeaders() {
|
||||||
|
return {
|
||||||
|
'User-Agent': 'BetterDiscordApp User',
|
||||||
|
'X-ZL-Apikey': '1a20cce89a2dbd163fc9570f3246c20891e62b2818ada55f82fa3d1d96fa7ef4',
|
||||||
|
'X-ZL-User': 'anonymous'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
import Module from './modulebase';
|
import Module from './modulebase';
|
||||||
import semver from 'semver';
|
import semver from 'semver';
|
||||||
|
import Axi from './axi';
|
||||||
|
|
||||||
const TEST_UPDATE = [
|
const TEST_UPDATE = [
|
||||||
{
|
{
|
||||||
|
@ -84,6 +85,32 @@ export default class Updater extends Module {
|
||||||
this.updaterThread = setInterval(this.checkForUpdates, interval * 60 * 1000);
|
this.updaterThread = setInterval(this.checkForUpdates, interval * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validate(releaseInfo) {
|
||||||
|
return releaseInfo &&
|
||||||
|
typeof releaseInfo === 'object' &&
|
||||||
|
releaseInfo.files &&
|
||||||
|
Array.isArray(releaseInfo.files) &&
|
||||||
|
releaseInfo.files.length >= 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
async latestRelease() {
|
||||||
|
try {
|
||||||
|
const release = await Axi.github.api.get('repos/JsSucks/BetterDiscordApp/releases/latest'); // TODO replace with config
|
||||||
|
const releaseInfoAsset = release.data.assets.find(asset => asset.name === 'releaseinfo.json');
|
||||||
|
const releaseInfo = await Axi.get(releaseInfoAsset['browser_download_url']);
|
||||||
|
|
||||||
|
if (this.validate(releaseInfo.data)) return releaseInfo.data;
|
||||||
|
return this.latestReleaseFallback();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
return this.latestReleaseFallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async latestReleaseFallback() {
|
||||||
|
console.log('fallback');
|
||||||
|
}
|
||||||
|
|
||||||
async checkForUpdates() {
|
async checkForUpdates() {
|
||||||
console.log('[BetterDiscord:Updater] Checking for updates');
|
console.log('[BetterDiscord:Updater] Checking for updates');
|
||||||
this.bd.sendToDiscord('updater-checkForUpdates', '');
|
this.bd.sendToDiscord('updater-checkForUpdates', '');
|
||||||
|
@ -92,6 +119,9 @@ export default class Updater extends Module {
|
||||||
const { coreVersion, clientVersion, editorVersion } = this.bd.config;
|
const { coreVersion, clientVersion, editorVersion } = this.bd.config;
|
||||||
const releaseInfo = new ReleaseInfo({ core: coreVersion, client: clientVersion, editor: editorVersion });
|
const releaseInfo = new ReleaseInfo({ core: coreVersion, client: clientVersion, editor: editorVersion });
|
||||||
|
|
||||||
|
const latestRelease = await this.latestRelease();
|
||||||
|
console.log(latestRelease);
|
||||||
|
|
||||||
releaseInfo.test();
|
releaseInfo.test();
|
||||||
this.debug(releaseInfo);
|
this.debug(releaseInfo);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue