From e177f9d1382d959315cf5d0d01a6c31ddbc21ccc Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Thu, 4 Nov 2021 00:46:33 +0800 Subject: [PATCH] no message --- controller/blog.go | 4 +++- controller/file.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++ controller/user.go | 33 +++++++++++++++--------------- main.go | 4 ++-- 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/controller/blog.go b/controller/blog.go index 28255dc..78aa762 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -243,7 +243,9 @@ func SearchArticleESHightLight(c *gin.Context) { highlight = highlight.Fields(elastic.NewHighlighterField("content")) highlight = highlight.PreTags("").PostTags("") x := []RetHighlight{} - _, e = db.GetElastic().QueryHighlight("doc", query, &x,highlight, 10, 0) + _, e = db.GetElastic(). + QueryHighlight("doc", query, &x,highlight, 10, 0) + log.Print(x) if nil != e { log.Print(e.Error()) return diff --git a/controller/file.go b/controller/file.go index e9b8fbc..1c8ad69 100644 --- a/controller/file.go +++ b/controller/file.go @@ -80,6 +80,57 @@ func (this *FileController) OnUpload(c *gin.Context) { } +func (this *FileController) OnUploadOrigin(c *gin.Context) { + uid, e := uuid.NewV1() + if nil != e { + log.Print(e.Error()) + return + } + imgtype := c.Query("type") + file, _, err := c.Request.FormFile("image") + if nil != err || nil == file { + log.Print(err.Error()) + return + } + + if imgtype == "gif" { + allgifs, er := gif.DecodeAll(file) + if nil != er { + log.Print("decode error", er.Error()) + return + } + + datout, err := os.Create("image/" + uid.String() + ".gif") + defer datout.Close() + if err != nil { + log.Fatal(err) + return + } + + gif.EncodeAll(datout, allgifs) + c.JSON(200, map[string]interface{}{"url": uid.String() + ".gif"}) + } else { + img, name, err := image.Decode(file) + if nil != err { + log.Print(err.Error()) + return + } + dx := img.Bounds().Dx() + // resize to width 1000 using Lanczos resampling + // and preserve aspect ratio + + m := resize.Resize(uint(dx), 0, img, resize.Lanczos3) + + datout, err := os.Create("image/" + uid.String() + "." + name) + defer datout.Close() + if err != nil { + log.Fatal(err) + } + jpeg.Encode(datout, m, nil) + c.JSON(200, map[string]interface{}{"url": uid.String() + "." + name}) + } +} + func (this *FileController) FileList(c *gin.Context) { var nodes utils.FileDesc path := c.Query("path") diff --git a/controller/user.go b/controller/user.go index 0855572..4c149ab 100644 --- a/controller/user.go +++ b/controller/user.go @@ -289,25 +289,24 @@ func (this *UserController) Login(c *gin.Context) { } } //存储session - session := sessions.Get(c) - log.Println("set session", string(sessionInfo)) - session.Set("", string(sessionInfo)) - session.Clear() + // session := sessions.Get(c) + // log.Println("set session", string(sessionInfo)) + // session.Set("", string(sessionInfo)) + // session.Clear() //session. - var Options *sessions.Options - if req.RememberMe == 1 { - Options = &sessions.Options{ - MaxAge: 2 * 24 * 3600 * 1000, - } - } else { - Options = &sessions.Options{ - MaxAge: 8 * 3600 * 1000, - } - } - session.Options(*Options) - session.Save() - + // var Options *sessions.Options + // if req.RememberMe == 1 { + // Options = &sessions.Options{ + // MaxAge: 2 * 24 * 3600 * 1000, + // } + // } else { + // Options = &sessions.Options{ + // MaxAge: 8 * 3600 * 1000, + // } + // } + // session.Options(*Options) + // session.Save() resp.Msg = "登录成功" resp.Status = 0 diff --git a/main.go b/main.go index 412e945..b4c1503 100644 --- a/main.go +++ b/main.go @@ -168,7 +168,8 @@ func main() { api.POST("/article_update", controller.UpdateArtilce) //更新文章 api.GET("/articleCount", controller.GetArticleCount) //获取所有文章个数 api.DELETE("/article/:id", controller.DeleteArticle) ////删除文章 - api.POST("/image_upload", fileController.OnUpload) // 上传图片 + api.POST("/image_upload", fileController.OnUpload) // 上传图片,如果图片太大自动裁减为原来的一半 + api.POST("/image_upload_origin", fileController.OnUploadOrigin) // 上传图片 api.GET("/image_download/:file", fileController.OnDownLoad) // 下载图片 api.GET("/image_thumbnail/:file", fileController.OnThumbnail) // 下载图片 api.GET("/doc_types", controller.ArticlesTypes) // 获取所有的文章类型 @@ -223,7 +224,6 @@ func main() { api.DELETE("/doc_template/:id",controller.DeleteDocTemplate) // 删除文章模板 api.GET("/doc_template/:id",controller.GetDocTemplateId) //获得单个文章模板信息 } - openapi := r.Group("openapi") { openapi.POST("/diff") // 比较两个文档差异