easydiffusion/ui/plugins/ui/release-notes.plugin.js
2023-06-14 11:57:06 +02:00

54 lines
1.8 KiB
JavaScript

;(function() {
// Register selftests when loaded by jasmine.
if (typeof PLUGINS?.SELFTEST === "object") {
PLUGINS.SELFTEST["release-notes"] = function() {
it("should be able to fetch CHANGES.md", async function() {
let releaseNotes = await fetch(
`https://raw.githubusercontent.com/easydiffusion/easydiffusion/main/CHANGES.md`
)
expect(releaseNotes.status).toBe(200)
})
}
}
createTab({
id: "news",
icon: "fa-bolt",
label: "What's new",
css: `
#tab-content-news .tab-content-inner {
max-width: 100%;
text-align: left;
padding: 10pt;
}
`,
onOpen: async ({ firstOpen }) => {
if (firstOpen) {
const loadMarkedScriptPromise = loadScript("/media/js/marked.min.js")
let appConfig = await fetch("/get/app_config")
if (!appConfig.ok) {
console.error("[release-notes] Failed to get app_config.")
return
}
appConfig = await appConfig.json()
const updateBranch = appConfig.update_branch || "main"
let releaseNotes = await fetch(
`https://raw.githubusercontent.com/easydiffusion/easydiffusion/${updateBranch}/CHANGES.md`
)
if (!releaseNotes.ok) {
console.error("[release-notes] Failed to get CHANGES.md.")
return
}
releaseNotes = await releaseNotes.text()
await loadMarkedScriptPromise
return marked.parse(releaseNotes)
}
},
})
})()