diff --git a/controller/blog.go b/controller/blog.go index addb329..c78fc86 100644 --- a/controller/blog.go +++ b/controller/blog.go @@ -50,18 +50,18 @@ func GetArticles(c *gin.Context) { if req.Type == 110 { is_public := 0 if public == "true" { - is_public = 0 - } else { is_public = 1 + } else { + is_public = 0 } sql = "select * from doc where doc.title like '%%%s%%' and is_public = %d limit %d offset %d " sql = fmt.Sprintf(sql, req.Name, is_public, limit, offset*limit) } else { is_public := 0 if public == "true" { - is_public = 0 - } else { is_public = 1 + } else { + is_public = 0 } sql = fmt.Sprintf("select * from doc where doc.title like '%%%s%%' and doc.type = %d and is_public = %d limit %d offset %d ", req.Name, req.Type, is_public, limit, offset*limit) diff --git a/controller/file.go b/controller/file.go index a8d5732..814fff0 100644 --- a/controller/file.go +++ b/controller/file.go @@ -12,8 +12,10 @@ import ( "log" "net/http" "os" - "github.com/nfnt/resize" - "image/jpeg" + // "github.com/nfnt/resize" + // "image/jpeg" + "image/gif" + // "strings" ) type FileController struct { @@ -31,28 +33,55 @@ func (this *FileController) OnUpload(c *gin.Context) { log.Print(err.Error()) return } - img, name, err := image.Decode(file) - bound := img.Bounds() - dx := bound.Dx() - dy := bound.Dy() - log.Printf("%d %d %s",dx,dy,name) - if err != nil { - log.Print(err) - } - // resize to width 1000 using Lanczos resampling - // and preserve aspect ratio - if(dx > 800){ - dx = dx / 2; - } - m := resize.Resize(uint(dx), 0, img, resize.Lanczos3) + // config, name, err := image.DecodeConfig(file) + // dx := config.Width + // log.Print(config.Width,name) + // if err != nil { + // if strings.Contains(err.Error(),"gif") { + + // }else{ + // log.Print(err.Error()) + // // return + // } + // } + // if name == "gif"{ + allgifs,er := gif.DecodeAll(file) + if nil != er{ + log.Print("decode error",er.Error()) + return + } - 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 } ) + datout, err := os.Create("image/" + uid.String() + ".jpg" ) + defer datout.Close() + if err != nil { + log.Fatal(err) + return + } + + gif.EncodeAll(datout,allgifs) + c.JSON(200, map[string] interface{}{"url":uid.String() + ".jpg" } ) + // }else{ + // img, _, err := image.Decode(file) + // if nil != err{ + // log.Print(err.Error()) + // return + // } + + // // resize to width 1000 using Lanczos resampling + // // and preserve aspect ratio + // if(dx > 800){ + // dx = dx / 2; + // } + // 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 } ) + // } }