2021-09-16 00:59:38 +02:00
|
|
|
import packagejson from '../package.json'
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
function parseSemver(ver) {
|
|
|
|
if (!ver) return null
|
|
|
|
var groups = ver.match(/^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/)
|
|
|
|
if (groups && groups.length > 6) {
|
2021-09-24 23:14:33 +02:00
|
|
|
var total = Number(groups[3]) * 10000 + Number(groups[4]) * 100 + Number(groups[5])
|
2021-09-16 00:59:38 +02:00
|
|
|
if (isNaN(total)) {
|
|
|
|
console.warn('Invalid version total', groups[3], groups[4], groups[5])
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
total,
|
|
|
|
version: groups[2],
|
|
|
|
major: Number(groups[3]),
|
|
|
|
minor: Number(groups[4]),
|
|
|
|
patch: Number(groups[5]),
|
|
|
|
preRelease: groups[6] || null
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.warn('Invalid semver string', ver)
|
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|
2022-06-02 00:15:13 +02:00
|
|
|
|
|
|
|
export const currentVersion = packagejson.version
|
|
|
|
|
2021-09-16 00:59:38 +02:00
|
|
|
export async function checkForUpdate() {
|
|
|
|
if (!packagejson.version) {
|
2022-06-02 00:15:13 +02:00
|
|
|
return null
|
2021-09-16 00:59:38 +02:00
|
|
|
}
|
|
|
|
var currVerObj = parseSemver('v' + packagejson.version)
|
|
|
|
if (!currVerObj) {
|
|
|
|
console.error('Invalid version', packagejson.version)
|
2022-06-02 00:15:13 +02:00
|
|
|
return null
|
2021-09-16 00:59:38 +02:00
|
|
|
}
|
|
|
|
var largestVer = null
|
2022-04-29 19:20:51 +02:00
|
|
|
await axios.get(`https://api.github.com/repos/advplyr/audiobookshelf/releases`).then((res) => {
|
|
|
|
var releases = res.data
|
|
|
|
if (releases && releases.length) {
|
|
|
|
releases.forEach((release) => {
|
|
|
|
var tagName = release.tag_name
|
|
|
|
var verObj = parseSemver(tagName)
|
2021-09-16 00:59:38 +02:00
|
|
|
if (verObj) {
|
|
|
|
if (!largestVer || largestVer.total < verObj.total) {
|
|
|
|
largestVer = verObj
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 05:26:30 +02:00
|
|
|
|
|
|
|
if (verObj.version == currVerObj.version) {
|
2024-07-06 17:57:20 +02:00
|
|
|
currVerObj.pubdate = new Date(release.published_at)
|
2022-07-09 05:26:30 +02:00
|
|
|
currVerObj.changelog = release.body
|
|
|
|
}
|
2021-09-16 00:59:38 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (!largestVer) {
|
|
|
|
console.error('No valid version tags to compare with')
|
2022-06-02 00:15:13 +02:00
|
|
|
return null
|
2021-09-16 00:59:38 +02:00
|
|
|
}
|
2022-04-29 19:20:51 +02:00
|
|
|
|
2021-09-16 00:59:38 +02:00
|
|
|
return {
|
|
|
|
hasUpdate: largestVer.total > currVerObj.total,
|
|
|
|
latestVersion: largestVer.version,
|
|
|
|
githubTagUrl: `https://github.com/advplyr/audiobookshelf/releases/tag/v${largestVer.version}`,
|
2022-07-09 05:26:30 +02:00
|
|
|
currentVersion: currVerObj.version,
|
2024-07-06 17:57:20 +02:00
|
|
|
currentTagUrl: `https://github.com/advplyr/audiobookshelf/releases/tag/v${currVerObj.version}`,
|
|
|
|
currentVersionPubDate: currVerObj.pubdate,
|
2022-07-09 05:26:30 +02:00
|
|
|
currentVersionChangelog: currVerObj.changelog
|
2021-09-16 00:59:38 +02:00
|
|
|
}
|
2024-07-06 17:57:20 +02:00
|
|
|
}
|