Update:Changelog shows all releases matching minor version and lower than current #3250

This commit is contained in:
advplyr 2024-08-07 17:56:55 -05:00
parent 91dc6eebb0
commit 2f98cb9b6d
3 changed files with 83 additions and 72 deletions

View File

@ -6,10 +6,15 @@
</div>
</template>
<div class="px-8 py-6 w-full rounded-lg bg-bg shadow-lg border border-black-300 relative overflow-y-scroll" style="max-height: 80vh">
<p class="text-xl font-bold pb-4">
Changelog <a :href="currentTagUrl" target="_blank" class="hover:underline">v{{ currentVersionNumber }}</a> ({{ currentVersionPubDate }})
</p>
<div class="custom-text" v-html="compiledMarkedown" />
<template v-for="release in releasesToShow">
<div :key="release.name">
<p class="text-xl font-bold pb-4">
Changelog <a :href="`https://github.com/advplyr/audiobookshelf/releases/tag/${release.name}`" target="_blank" class="hover:underline">{{ release.name }}</a> ({{ $formatDate(release.pubdate, dateFormat) }})
</p>
<div class="custom-text" v-html="getChangelog(release)" />
</div>
<div v-if="release !== releasesToShow[releasesToShow.length - 1]" class="border-b border-black-300 my-8" />
</template>
</div>
</modals-modal>
</template>
@ -37,24 +42,15 @@ export default {
dateFormat() {
return this.$store.state.serverSettings.dateFormat
},
changelog() {
return this.versionData?.currentVersionChangelog || 'No Changelog Available'
},
compiledMarkedown() {
return marked.parse(this.changelog, { gfm: true, breaks: true })
},
currentVersionPubDate() {
if (!this.versionData?.currentVersionPubDate) return 'Unknown release date'
return `${this.$formatDate(this.versionData.currentVersionPubDate, this.dateFormat)}`
},
currentTagUrl() {
return this.versionData?.currentTagUrl
},
currentVersionNumber() {
return this.$config.version
releasesToShow() {
return this.versionData?.releasesToShow || []
}
},
methods: {
getChangelog(release) {
return marked.parse(release.changelog || 'No Changelog Available', { gfm: true, breaks: true })
}
},
methods: {},
mounted() {}
}
</script>

View File

@ -11,6 +11,7 @@ function parseSemver(ver) {
return null
}
return {
name: ver,
total,
version: groups[2],
major: Number(groups[3]),
@ -24,49 +25,60 @@ function parseSemver(ver) {
return null
}
function getReleases() {
return axios
.get(`https://api.github.com/repos/advplyr/audiobookshelf/releases`)
.then((res) => {
return res.data
.map((release) => {
const tagName = release.tag_name
const verObj = parseSemver(tagName)
if (verObj) {
verObj.pubdate = new Date(release.published_at)
verObj.changelog = release.body
return verObj
}
return null
})
.filter((verObj) => verObj)
})
.catch((error) => {
console.error('Failed to get releases', error)
return []
})
}
export const currentVersion = packagejson.version
export async function checkForUpdate() {
if (!packagejson.version) {
return null
}
var currVerObj = parseSemver('v' + packagejson.version)
if (!currVerObj) {
console.error('Invalid version', packagejson.version)
return null
}
var largestVer = null
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)
if (verObj) {
if (!largestVer || largestVer.total < verObj.total) {
largestVer = verObj
}
}
if (verObj.version == currVerObj.version) {
currVerObj.pubdate = new Date(release.published_at)
currVerObj.changelog = release.body
}
})
}
})
if (!largestVer) {
console.error('No valid version tags to compare with')
const releases = await getReleases()
if (!releases.length) {
console.error('No releases found')
return null
}
const currentVersion = releases.find((release) => release.version == packagejson.version)
if (!currentVersion) {
console.error('Current version not found in releases')
return null
}
const latestVersion = releases[0]
const currentVersionMinor = currentVersion.minor
// Show all releases with the same minor version and lower or equal total version
const releasesToShow = releases.filter((release) => {
return release.minor == currentVersionMinor && release.total <= currentVersion.total
})
return {
hasUpdate: largestVer.total > currVerObj.total,
latestVersion: largestVer.version,
githubTagUrl: `https://github.com/advplyr/audiobookshelf/releases/tag/v${largestVer.version}`,
currentVersion: currVerObj.version,
currentTagUrl: `https://github.com/advplyr/audiobookshelf/releases/tag/v${currVerObj.version}`,
currentVersionPubDate: currVerObj.pubdate,
currentVersionChangelog: currVerObj.changelog
hasUpdate: latestVersion.total > currentVersion.total,
latestVersion: latestVersion.version,
githubTagUrl: `https://github.com/advplyr/audiobookshelf/releases/tag/v${latestVersion.version}`,
currentVersion: currentVersion.version,
releasesToShow
}
}

View File

@ -32,33 +32,33 @@ export const state = () => ({
})
export const getters = {
getServerSetting: state => key => {
getServerSetting: (state) => (key) => {
if (!state.serverSettings) return null
return state.serverSettings[key]
},
getLibraryItemIdStreaming: state => {
getLibraryItemIdStreaming: (state) => {
return state.streamLibraryItem?.id || null
},
getIsStreamingFromDifferentLibrary: (state, getters, rootState) => {
if (!state.streamLibraryItem) return false
return state.streamLibraryItem.libraryId !== rootState.libraries.currentLibraryId
},
getIsMediaStreaming: state => (libraryItemId, episodeId) => {
getIsMediaStreaming: (state) => (libraryItemId, episodeId) => {
if (!state.streamLibraryItem) return null
if (!episodeId) return state.streamLibraryItem.id == libraryItemId
return state.streamLibraryItem.id == libraryItemId && state.streamEpisodeId == episodeId
},
getIsMediaQueued: state => (libraryItemId, episodeId) => {
return state.playerQueueItems.some(i => {
getIsMediaQueued: (state) => (libraryItemId, episodeId) => {
return state.playerQueueItems.some((i) => {
if (!episodeId) return i.libraryItemId === libraryItemId
return i.libraryItemId === libraryItemId && i.episodeId === episodeId
})
},
getBookshelfView: state => {
getBookshelfView: (state) => {
if (!state.serverSettings || isNaN(state.serverSettings.bookshelfView)) return Constants.BookshelfView.STANDARD
return state.serverSettings.bookshelfView
},
getHomeBookshelfView: state => {
getHomeBookshelfView: (state) => {
if (!state.serverSettings || isNaN(state.serverSettings.homeBookshelfView)) return Constants.BookshelfView.STANDARD
return state.serverSettings.homeBookshelfView
}
@ -69,17 +69,20 @@ export const actions = {
const updatePayload = {
...payload
}
return this.$axios.$patch('/api/settings', updatePayload).then((result) => {
if (result.success) {
commit('setServerSettings', result.serverSettings)
return true
} else {
return this.$axios
.$patch('/api/settings', updatePayload)
.then((result) => {
if (result.success) {
commit('setServerSettings', result.serverSettings)
return true
} else {
return false
}
})
.catch((error) => {
console.error('Failed to update server settings', error)
return false
}
}).catch((error) => {
console.error('Failed to update server settings', error)
return false
})
})
},
checkForUpdate({ commit }) {
const VERSION_CHECK_BUFF = 1000 * 60 * 5 // 5 minutes
@ -96,7 +99,7 @@ export const actions = {
}
var shouldCheckForUpdate = Date.now() - Number(lastVerCheck) > VERSION_CHECK_BUFF
if (!shouldCheckForUpdate && savedVersionData && savedVersionData.version !== currentVersion) {
if (!shouldCheckForUpdate && savedVersionData && (savedVersionData.version !== currentVersion || !savedVersionData.releasesToShow)) {
// Version mismatch between saved data so check for update anyway
shouldCheckForUpdate = true
}
@ -180,7 +183,7 @@ export const mutations = {
})
},
addItemToQueue(state, item) {
const exists = state.playerQueueItems.some(i => {
const exists = state.playerQueueItems.some((i) => {
if (!i.episodeId) return i.libraryItemId === item.libraryItemId
return i.libraryItemId === item.libraryItemId && i.episodeId === item.episodeId
})