mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 19:51:47 -03:00
Add files via upload
This commit is contained in:
1397
backend/launcher.js
1397
backend/launcher.js
File diff suppressed because it is too large
Load Diff
73
backend/updateManager.js
Normal file
73
backend/updateManager.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
const axios = require('axios');
|
||||||
|
|
||||||
|
const UPDATE_CHECK_URL = 'http://3.10.208.30:3002/api/version_launcher';
|
||||||
|
const CURRENT_VERSION = '2.0.0';
|
||||||
|
const GITHUB_DOWNLOAD_URL = 'https://github.com/amiayweb/Hytale-F2P/';
|
||||||
|
|
||||||
|
class UpdateManager {
|
||||||
|
constructor() {
|
||||||
|
this.updateAvailable = false;
|
||||||
|
this.remoteVersion = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkForUpdates() {
|
||||||
|
try {
|
||||||
|
console.log('Checking for updates...');
|
||||||
|
console.log(`Local version: ${CURRENT_VERSION}`);
|
||||||
|
|
||||||
|
const response = await axios.get(UPDATE_CHECK_URL, {
|
||||||
|
timeout: 5000,
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Hytale-F2P-Launcher'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data && response.data.launcher_version) {
|
||||||
|
this.remoteVersion = response.data.launcher_version;
|
||||||
|
console.log(`Remote version: ${this.remoteVersion}`);
|
||||||
|
|
||||||
|
if (this.remoteVersion !== CURRENT_VERSION) {
|
||||||
|
this.updateAvailable = true;
|
||||||
|
console.log('Update available!');
|
||||||
|
return {
|
||||||
|
updateAvailable: true,
|
||||||
|
currentVersion: CURRENT_VERSION,
|
||||||
|
newVersion: this.remoteVersion,
|
||||||
|
downloadUrl: GITHUB_DOWNLOAD_URL
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
console.log('Launcher is up to date');
|
||||||
|
return {
|
||||||
|
updateAvailable: false,
|
||||||
|
currentVersion: CURRENT_VERSION,
|
||||||
|
newVersion: this.remoteVersion
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('Invalid API response');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error checking for updates:', error.message);
|
||||||
|
return {
|
||||||
|
updateAvailable: false,
|
||||||
|
error: error.message,
|
||||||
|
currentVersion: CURRENT_VERSION
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getDownloadUrl() {
|
||||||
|
return GITHUB_DOWNLOAD_URL;
|
||||||
|
}
|
||||||
|
|
||||||
|
getUpdateInfo() {
|
||||||
|
return {
|
||||||
|
updateAvailable: this.updateAvailable,
|
||||||
|
currentVersion: CURRENT_VERSION,
|
||||||
|
remoteVersion: this.remoteVersion,
|
||||||
|
downloadUrl: this.getDownloadUrl()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = UpdateManager;
|
||||||
Reference in New Issue
Block a user