This commit is contained in:
Liang Ding 2023-04-06 21:56:52 +08:00
parent 76e24225ae
commit 5a7e436ba5
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
12 changed files with 63 additions and 12 deletions

View file

@ -56,6 +56,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/system/getConf", model.CheckAuth, getConf)
ginServer.Handle("POST", "/api/system/checkUpdate", model.CheckAuth, checkUpdate)
ginServer.Handle("POST", "/api/system/exportLog", model.CheckAuth, exportLog)
ginServer.Handle("POST", "/api/system/getChangelog", model.CheckAuth, getChangelog)
ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, setLocalStorage)
ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)

View file

@ -17,6 +17,7 @@
package api
import (
"github.com/88250/lute"
"net/http"
"os"
"path/filepath"
@ -32,6 +33,43 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
func getChangelog(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
data := map[string]interface{}{"show": false, "html": ""}
ret.Data = data
changelogsDir := filepath.Join(util.WorkingDir, "changelogs")
if !gulu.File.IsDir(changelogsDir) {
return
}
if !model.Conf.ShowChangelog {
return
}
changelogPath := filepath.Join(changelogsDir, "v"+util.Ver+".md")
if !gulu.File.IsExist(changelogPath) {
logging.LogWarnf("changelog not found: %s", changelogPath)
return
}
contentData, err := os.ReadFile(changelogPath)
if nil != err {
logging.LogErrorf("read changelog failed: %s", err)
return
}
luteEngine := lute.New()
htmlContent := luteEngine.Markdown("", contentData)
data["show"] = true
data["html"] = htmlContent
ret.Data = data
}
func getEmojiConf(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

View file

@ -75,6 +75,7 @@ type AppConf struct {
Api *conf.API `json:"api"` // API
Repo *conf.Repo `json:"repo"` // 数据仓库
OpenHelp bool `json:"openHelp"` // 启动后是否需要打开用户指南
ShowChangelog bool `json:"showChangelog"` // 是否显示版本更新日志
}
func InitConf() {
@ -219,6 +220,7 @@ func InitConf() {
} else {
if 0 < semver.Compare("v"+util.Ver, "v"+Conf.System.KernelVersion) {
logging.LogInfof("upgraded from version [%s] to [%s]", Conf.System.KernelVersion, util.Ver)
Conf.ShowChangelog = true
} else if 0 > semver.Compare("v"+util.Ver, "v"+Conf.System.KernelVersion) {
logging.LogInfof("downgraded from version [%s] to [%s]", Conf.System.KernelVersion, util.Ver)
}