Added update checker

This commit is contained in:
RemixDev 2022-01-13 01:33:29 +01:00
parent 018b008915
commit b9e2fd298e
9 changed files with 152 additions and 71 deletions

16
scripts/gen-version.js Normal file
View File

@ -0,0 +1,16 @@
const { execSync } = require('child_process')
function generateVersion(){
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth()+1;
const day = now.getDate();
const commitsNumber = String(execSync('git rev-list --count HEAD')).trim()
const commitHash = String(execSync('git rev-parse --short=10 HEAD')).trim()
return `${year}.${month}.${day}-r${commitsNumber}.${commitHash}`
}
console.log(generateVersion())
module.exports = generateVersion

View File

@ -1,17 +1,5 @@
const { execSync } = require('child_process')
const fs = require('fs')
function generateVersion(){
const now = new Date();
const year = now.getFullYear();
const month = now.getMonth()+1;
const day = now.getDate();
const commitsNumber = String(execSync('git rev-list --count HEAD')).trim()
const commitHash = String(execSync('git rev-parse --short=10 HEAD')).trim()
return `${year}.${month}.${day}-r${commitsNumber}.${commitHash}`
}
const generateVersion = require('./gen-version.js')
let package = JSON.parse(fs.readFileSync('package.json'))
package.version = generateVersion()

2
server/dist/app.js vendored

File diff suppressed because one or more lines are too long

View File

@ -9,6 +9,8 @@ import { wss } from './app'
import { Settings } from './types'
import { NotLoggedIn } from './helpers/errors'
import { GUI_PACKAGE } from './helpers/paths'
const Downloader = deemix.downloader.Downloader
const { Single, Collection, Convertable } = deemix.types.downloadObjects
export const defaultSettings: Settings = deemix.settings.DEFAULTS
@ -20,7 +22,10 @@ export const getAccessToken = deemix.utils.deezer.getAccessToken
export const getArlFromAccessToken = deemix.utils.deezer.getArlFromAccessToken
export const deemixVersion = require('../node_modules/deemix/package.json').version
const currentVersionTemp = JSON.parse(String(fs.readFileSync(GUI_PACKAGE))).version
export const currentVersion = currentVersionTemp === '0.0.0' ? 'continuous' : currentVersionTemp
let deezerAvailable: boolean | null = null
let latestVersion: string | null = null
export async function isDeezerAvailable(): Promise<boolean> {
if (deezerAvailable === null) {
@ -44,6 +49,54 @@ export async function isDeezerAvailable(): Promise<boolean> {
return deezerAvailable
}
export async function getLatestVersion(force = false): Promise<string | null> {
if ((latestVersion === null || force) && !settings.disableUpdateCheck) {
let response
try {
response = await got.get('https://deemix.app/gui/latest', {
https: {
rejectUnauthorized: false
}
})
} catch (e) {
console.trace(e)
latestVersion = 'NotFound'
return latestVersion
}
latestVersion = response.body.trim()
}
return latestVersion
}
function parseVersion(version: string | null): any {
if (version === null || version === 'continuous' || version === 'NotFound') return null
try {
const matchResult = version.match(/(\d+)\.(\d+)\.(\d+)-r(\d)+\.(.+)/) || []
return {
year: parseInt(matchResult[1]),
month: parseInt(matchResult[2]),
day: parseInt(matchResult[3]),
revision: parseInt(matchResult[4]),
commit: matchResult[5] || ''
}
} catch (e) {
console.trace(e)
return null
}
}
export function isUpdateAvailable(): boolean {
const currentVersionObj: any = parseVersion(currentVersion)
const latestVersionObj: any = parseVersion(latestVersion)
if (currentVersionObj === null || latestVersionObj === null) return false
if (latestVersionObj.year > currentVersionObj.year) return true
if (latestVersionObj.month > currentVersionObj.month) return true
if (latestVersionObj.day > currentVersionObj.day) return true
if (latestVersionObj.revision > currentVersionObj.revision) return true
if (latestVersionObj.commit !== currentVersionObj.commit) return true
return false
}
export const plugins: any = {
// eslint-disable-next-line new-cap
spotify: new deemix.plugins.spotify()

View File

@ -0,0 +1,16 @@
import { ApiHandler } from '../../../types'
import { getLatestVersion, isUpdateAvailable } from '../../../main'
const path: ApiHandler['path'] = '/checkForUpdates'
const handler: ApiHandler['handler'] = async (_, res) => {
const latestCommit = await getLatestVersion()
res.send({
latestCommit,
updateAvailable: isUpdateAvailable()
})
}
const apiHandler: ApiHandler = { path, handler }
export default apiHandler

View File

@ -16,6 +16,7 @@ import getUserSpotifyPlaylists from './getUserSpotifyPlaylists'
import getUserFavorites from './getUserFavorites'
import getQueue from './getQueue'
import spotifyStatus from './spotifyStatus'
import checkForUpdates from './checkForUpdates'
export default [
albumSearch,
@ -35,5 +36,6 @@ export default [
getUserSpotifyPlaylists,
getUserFavorites,
getQueue,
spotifyStatus
spotifyStatus,
checkForUpdates
]

View File

@ -1,9 +1,8 @@
import fs from 'fs'
import express from 'express'
// @ts-expect-error
import { Deezer } from 'deezer-js'
import { GUI_PACKAGE } from '../helpers/paths'
import { sessionDZ, getQueue, deemixVersion, isDeezerAvailable, plugins } from '../main'
import { consoleInfo } from '../helpers/errors'
import { sessionDZ, getQueue, deemixVersion, currentVersion, isDeezerAvailable, plugins, getSettings } from '../main'
const router = express.Router()
let update: any = null
@ -13,12 +12,10 @@ router.get('/connect', async (req, res) => {
const dz = sessionDZ[req.session.id]
if (!update) {
const currentVersion = JSON.parse(String(fs.readFileSync(GUI_PACKAGE))).version
console.log(currentVersion)
consoleInfo(`Currently running deemix-gui version ${currentVersion}`)
consoleInfo(`deemix-lib version ${deemixVersion}`)
update = {
currentCommit: currentVersion === '0.0.0' ? 'continuous' : currentVersion,
latestCommit: null,
updateAvailable: false,
currentCommit: currentVersion,
deemixVersion
}
}
@ -28,9 +25,12 @@ router.get('/connect', async (req, res) => {
autologin: !dz.logged_in,
currentUser: dz.current_user,
deezerAvailable: await isDeezerAvailable(),
spotifyEnabled: plugins.spotify.enabled
spotifyEnabled: plugins.spotify.enabled,
settingsData: getSettings()
}
if (result.settingsData.settings.autoCheckForUpdates) result.checkForUpdates = true
const queue = getQueue()
if (Object.keys(queue.queue).length > 0) {

2
webui

@ -1 +1 @@
Subproject commit aef5c775ba33765f25c03e3e75c100f1fc23d63c
Subproject commit 2e153770b776960c1db8aa15ad9a16f8c3802624

View File

@ -8,9 +8,9 @@
integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==
"@babel/helper-validator-identifier@^7.12.11":
version "7.15.7"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.15.7.tgz#220df993bfe904a4a6b02ab4f3385a5ebf6e2389"
integrity sha512-K4JvCtQqad9OY2+yTU8w+E82ywk/fe+ELNlt1G8z3bVGlZfn/hOcQQsUhGhW/N+tb3fxK800wLtKOE/aM0m72w==
version "7.16.7"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.16.7.tgz#e8c602438c4a8195751243da9031d1607d247cad"
integrity sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw==
"@babel/parser@7.13.13":
version "7.13.13"
@ -144,14 +144,14 @@
integrity sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==
"@types/node@*":
version "17.0.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.2.tgz#a4c07d47ff737e8ee7e586fe636ff0e1ddff070a"
integrity sha512-JepeIUPFDARgIs0zD/SKPgFsJEAF0X5/qO80llx59gOxFTboS9Amv3S+QfB7lqBId5sFXJ99BN0J6zFRvL9dDA==
version "17.0.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.8.tgz#50d680c8a8a78fe30abe6906453b21ad8ab0ad7b"
integrity sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==
"@types/node@^14.6.2":
version "14.18.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.2.tgz#00fe4d1686d5f6cf3a2f2e9a0eef42594d06abfc"
integrity sha512-fqtSN5xn/bBzDxMT77C1rJg6CsH/R49E7qsGuvdPJa20HtV5zSTuLJPNfnlyVH3wauKnkHdLggTVkOW/xP9oQg==
version "14.18.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.5.tgz#0dd636fe7b2c6055cbed0d4ca3b7fb540f130a96"
integrity sha512-LMy+vDDcQR48EZdEx5wRX1q/sEl6NdGuHXPnfeL8ixkwCOSZ2qnIyIZmcCbdX0MeRqHhAcHmX+haCbrS8Run+A==
"@types/plist@^3.0.1":
version "3.0.2"
@ -460,9 +460,9 @@ cacheable-request@^6.0.0:
responselike "^1.0.2"
camelcase@^6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.2.1.tgz#250fd350cfd555d0d2160b1d51510eaf8326e86e"
integrity sha512-tVI4q5jjFV5CavAU8DXfza/TJcZutVKo/5Foskmsqcm0MsL91moHvwiGNnqaa2o6PF/7yT5ikDRcVcl8Rj6LCA==
version "6.3.0"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==
chalk@^2.4.2:
version "2.4.2"
@ -971,10 +971,10 @@ fast-deep-equal@^3.1.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
fast-glob@^3.1.1:
version "3.2.7"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.7.tgz#fd6cb7a2d7e9aa7a7846111e85a196d6b2f766a1"
integrity sha512-rYGMRwip6lUMvYD3BTScMwT1HtAs2d71SMv66Vrxs0IekGZEjhM0pcMfjQPnknBt2zeCwQMEupiN02ZP4DiT1Q==
fast-glob@^3.2.9:
version "3.2.10"
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.10.tgz#2734f83baa7f43b7fd41e13bc34438f4ffe284ee"
integrity sha512-s9nFhFnvR63wls6/kM88kQqDhMu0AfdjqouE2l5GVQPbqLgyFjjU5ry/r2yKsJxpb9Py1EYNqieFrmMaX4v++A==
dependencies:
"@nodelib/fs.stat" "^2.0.2"
"@nodelib/fs.walk" "^1.2.3"
@ -1175,15 +1175,15 @@ globalthis@^1.0.1:
define-properties "^1.1.3"
globby@^11.0.3:
version "11.0.4"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==
version "11.1.0"
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
dependencies:
array-union "^2.1.0"
dir-glob "^3.0.1"
fast-glob "^3.1.1"
ignore "^5.1.4"
merge2 "^1.3.0"
fast-glob "^3.2.9"
ignore "^5.2.0"
merge2 "^1.4.1"
slash "^3.0.0"
got@^9.6.0:
@ -1204,9 +1204,9 @@ got@^9.6.0:
url-parse-lax "^3.0.0"
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==
version "4.2.9"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz#041b05df45755e587a24942279b9d113146e1c96"
integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==
"graceful-readlink@>= 1.0.0":
version "1.0.1"
@ -1241,9 +1241,9 @@ has@^1.0.3:
function-bind "^1.1.1"
hosted-git-info@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-4.0.2.tgz#5e425507eede4fea846b7262f0838456c4209961"
integrity sha512-c9OGXbZ3guC/xOlCg1Ci/VgWlwsqDv1yMQL1CWqXDL0hDjXuNcq0zuR4xqPSuasI3kqFDhqSyTjREz5gzq0fXg==
version "4.1.0"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-4.1.0.tgz#827b82867e9ff1c8d0c4d9d53880397d2c86d224"
integrity sha512-kyCuEOWjJqZuDbRHzL8V93NzQhwIB71oFWSyzVo+KPZI+pnQPPxucdkrOZvkLRnrf5URsQM+IJ09Dw29cRALIA==
dependencies:
lru-cache "^6.0.0"
@ -1280,7 +1280,7 @@ ieee754@^1.1.13:
resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352"
integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==
ignore@^5.1.4:
ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==
@ -1340,10 +1340,10 @@ is-ci@^3.0.0:
dependencies:
ci-info "^3.2.0"
is-core-module@^2.2.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.8.0.tgz#0321336c3d0925e497fd97f5d95cb114a5ccd548"
integrity sha512-vd15qHsaqrRL7dtH6QNuy0ndJmRDrS9HAM1CAiSifNUFv4x1a0CCVsj18hJ1mShxIG6T2i1sO78MkP56r0nYRw==
is-core-module@^2.8.0:
version "2.8.1"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.8.1.tgz#f59fdfca701d5879d0a6b100a40aa1560ce27211"
integrity sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==
dependencies:
has "^1.0.3"
@ -1547,7 +1547,7 @@ matcher@^3.0.0:
dependencies:
escape-string-regexp "^4.0.0"
merge2@^1.3.0:
merge2@^1.3.0, merge2@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
@ -1748,7 +1748,7 @@ path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
path-parse@^1.0.6:
path-parse@^1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
@ -1764,9 +1764,9 @@ pend@~1.2.0:
integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA=
picomatch@^2.2.3:
version "2.3.0"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.0.tgz#f1f061de8f6a4bf022892e2d128234fb98302972"
integrity sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
pify@^3.0.0:
version "3.0.0"
@ -1954,12 +1954,13 @@ require-directory@^2.1.1:
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
resolve@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
version "1.21.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.21.0.tgz#b51adc97f3472e6a5cf4444d34bc9d6b9037591f"
integrity sha512-3wCbTpk5WJlyE4mSOtDLhqQmGFi0/TD9VPwmiolnk8U0wRgMEktqCXd3vy5buTO3tljvalNvKrjHEfrd2WpEKA==
dependencies:
is-core-module "^2.2.0"
path-parse "^1.0.6"
is-core-module "^2.8.0"
path-parse "^1.0.7"
supports-preserve-symlinks-flag "^1.0.0"
responselike@^1.0.2:
version "1.0.2"
@ -2240,6 +2241,11 @@ supports-color@^7.1.0:
dependencies:
has-flag "^4.0.0"
supports-preserve-symlinks-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09"
integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==
tar-fs@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784"
@ -2566,9 +2572,9 @@ yargs@^16.2.0:
yargs-parser "^20.2.2"
yargs@^17.0.1:
version "17.3.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.0.tgz#295c4ffd0eef148ef3e48f7a2e0f58d0e4f26b1c"
integrity sha512-GQl1pWyDoGptFPJx9b9L6kmR33TGusZvXIZUT+BOz9f7X2L94oeAskFYLEg/FkhV06zZPBYLvLZRWeYId29lew==
version "17.3.1"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.3.1.tgz#da56b28f32e2fd45aefb402ed9c26f42be4c07b9"
integrity sha512-WUANQeVgjLbNsEmGk20f+nlHgOqzRFpiGWVaBrYGYIGANIIu3lWjoyi0fNlFmJkvfhCZ6BXINe7/W2O2bV4iaA==
dependencies:
cliui "^7.0.2"
escalade "^3.1.1"