feat: 系统使用文档转存

This commit is contained in:
TsMask
2023-11-24 14:22:41 +08:00
parent 0e26e1d754
commit 635167c0f7
3 changed files with 94 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package common
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/framework/middleware/collectlogs"
"ems.agt/src/modules/common/controller"
"github.com/gin-gonic/gin"
@@ -25,6 +26,12 @@ func Setup(router *gin.Engine) {
// 系统可暴露的配置信息
indexGroup.GET("/sys-conf", controller.NewCommont.SysConfig)
// 系统使用文档转存
indexGroup.POST("/help-doc",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("系统使用文档", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewCommont.HelpDoc,
)
// 验证码操作处理
indexGroup.GET("/captchaImage",

View File

@@ -1,11 +1,18 @@
package controller
import (
"fmt"
"path/filepath"
"strings"
"ems.agt/src/framework/config"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/vo/result"
commonService "ems.agt/src/modules/common/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 CommontController 结构体
@@ -69,3 +76,43 @@ func (s *CommontController) SysConfig(c *gin.Context) {
c.JSON(200, result.OkData(data))
}
// 转存帮助文档
//
// POST /help-doc
func (s *CommontController) HelpDoc(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
UploadPath string `json:"uploadPath" binding:"required"`
Language string `json:"language" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 取语言前缀
lang := strings.SplitN(body.Language, "_", 2)[0]
// 默认静态资源
static := config.Get("staticFile.default").(map[string]any)
dir, err := filepath.Abs(static["dir"].(string))
if err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
return
}
newFile := fmt.Sprintf("%s/helpDoc/%s_doc.pdf", dir, lang)
fmt.Println(newFile)
// dst := ""
err = file.CopyUploadFile(body.UploadPath, newFile)
if err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
return
}
urlPath := strings.Replace(newFile, dir, static["prefix"].(string), 1)
c.JSON(200, result.OkData(filepath.ToSlash(urlPath)))
}