52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package common
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/ArtalkJS/Artalk/internal/config"
|
|
"github.com/ArtalkJS/Artalk/internal/core"
|
|
"github.com/ArtalkJS/Artalk/internal/utils"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type ApiVersionData struct {
|
|
App string `json:"app"`
|
|
Version string `json:"version"`
|
|
CommitHash string `json:"commit_hash"`
|
|
}
|
|
|
|
func GetApiVersionDataMap() ApiVersionData {
|
|
return ApiVersionData{
|
|
App: "artalk",
|
|
Version: strings.TrimPrefix(config.Version, "v"),
|
|
CommitHash: config.CommitHash,
|
|
}
|
|
}
|
|
|
|
func GetApiPublicConfDataMap(app *core.App, c *fiber.Ctx) Map {
|
|
isAdmin := CheckIsAdminReq(app, c)
|
|
imgUpload := app.Conf().ImgUpload.Enabled
|
|
if isAdmin {
|
|
imgUpload = true // 管理员始终允许上传图片
|
|
}
|
|
|
|
frontendConfSrc := app.Conf().Frontend
|
|
if frontendConfSrc == nil {
|
|
frontendConfSrc = make(map[string]interface{})
|
|
}
|
|
|
|
frontendConf := make(map[string]interface{})
|
|
utils.CopyStruct(&frontendConfSrc, &frontendConf)
|
|
|
|
frontendConf["imgUpload"] = &imgUpload
|
|
if app.Conf().Locale != "" {
|
|
frontendConf["locale"] = app.Conf().Locale
|
|
}
|
|
|
|
return Map{
|
|
"img_upload": imgUpload,
|
|
"frontend_conf": frontendConf,
|
|
"version": GetApiVersionDataMap(),
|
|
}
|
|
}
|