MCPcopy Index your code
hub / github.com/TruthHun/BookStack / UpdateCateIcon

Method UpdateCateIcon

controllers/ManagerController.go:993–1030  ·  view source on GitHub ↗

更新分类的图标

()

Source from the content-addressed store, hash-verified

991
992// 更新分类的图标
993func (this *ManagerController) UpdateCateIcon() {
994 var err error
995 id, _ := this.GetInt("id")
996 if id == 0 {
997 this.JsonResult(1, "参数不正确")
998 }
999
1000 data := make(map[string]interface{})
1001 model := new(models.Category)
1002 if cate := model.Find(id); cate.Id > 0 {
1003 cate.Icon = strings.TrimLeft(cate.Icon, "/")
1004 f, h, err1 := this.GetFile("icon")
1005 if err1 != nil {
1006 err = err1
1007 }
1008 defer f.Close()
1009
1010 tmpFile := fmt.Sprintf("uploads/icons/%v%v"+filepath.Ext(h.Filename), id, time.Now().Unix())
1011 os.MkdirAll(filepath.Dir(tmpFile), os.ModePerm)
1012 if err = this.SaveToFile("icon", tmpFile); err == nil {
1013 switch utils.StoreType {
1014 case utils.StoreOss:
1015 store.ModelStoreOss.MoveToOss(tmpFile, tmpFile, true, false)
1016 store.ModelStoreOss.DelFromOss(cate.Icon)
1017 data["icon"] = utils.ShowImg(tmpFile)
1018 case utils.StoreLocal:
1019 store.ModelStoreLocal.DelFiles(cate.Icon)
1020 data["icon"] = "/" + tmpFile
1021 }
1022 err = model.UpdateByField(cate.Id, "icon", "/"+tmpFile)
1023 }
1024 }
1025
1026 if err != nil {
1027 this.JsonResult(1, err.Error())
1028 }
1029 this.JsonResult(0, "更新成功", data)
1030}
1031
1032// 友情链接
1033func (this *ManagerController) FriendLink() {

Callers

nothing calls this directly

Calls 7

ShowImgFunction · 0.92
JsonResultMethod · 0.80
MoveToOssMethod · 0.80
DelFromOssMethod · 0.80
DelFilesMethod · 0.80
UpdateByFieldMethod · 0.80
FindMethod · 0.45

Tested by

no test coverage detected