no message
parent
c90b44b2c5
commit
59989de706
|
@ -26,46 +26,46 @@ type FileController struct {
|
|||
}
|
||||
|
||||
func (this *FileController) OnUpload(c *gin.Context) {
|
||||
uid,e := uuid.NewV1()
|
||||
if nil != e{
|
||||
uid, e := uuid.NewV1()
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
imgtype := c.Query("type")
|
||||
log.Print(imgtype)
|
||||
file, _, err := c.Request.FormFile("image")
|
||||
if nil != err || nil == file{
|
||||
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())
|
||||
|
||||
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" )
|
||||
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{
|
||||
gif.EncodeAll(datout, allgifs)
|
||||
c.JSON(200, map[string]interface{}{"url": uid.String() + ".gif"})
|
||||
} else {
|
||||
img, name, err := image.Decode(file)
|
||||
if nil != err{
|
||||
if nil != err {
|
||||
log.Print(err.Error())
|
||||
return
|
||||
}
|
||||
dx := img.Bounds().Dx()
|
||||
// resize to width 1000 using Lanczos resampling
|
||||
// and preserve aspect ratio
|
||||
if(dx > 800){
|
||||
dx = dx / 2;
|
||||
if dx > 800 {
|
||||
dx = dx / 2
|
||||
}
|
||||
m := resize.Resize(uint(dx), 0, img, resize.Lanczos3)
|
||||
|
||||
|
@ -75,25 +75,25 @@ func (this *FileController) OnUpload(c *gin.Context) {
|
|||
log.Fatal(err)
|
||||
}
|
||||
jpeg.Encode(datout, m, nil)
|
||||
c.JSON(200, map[string] interface{}{"url":uid.String() + "." + name } )
|
||||
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")
|
||||
utils.GetPathFileName("files\\" + path,&nodes)
|
||||
utils.GetPathFileName("files\\"+path, &nodes)
|
||||
log.Print(nodes)
|
||||
bs,e := json.Marshal(nodes)
|
||||
if nil != e{
|
||||
bs, e := json.Marshal(nodes)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
}
|
||||
log.Print(string(bs))
|
||||
c.JSON(200,map[string]interface{}{
|
||||
"msg":"ok",
|
||||
"status":200,
|
||||
"files":nodes,
|
||||
c.JSON(200, map[string]interface{}{
|
||||
"msg": "ok",
|
||||
"status": 200,
|
||||
"files": nodes,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -102,23 +102,23 @@ func (this *FileController) FileType(c *gin.Context) {
|
|||
}
|
||||
|
||||
func (this *FileController) DownloadFile(c *gin.Context) {
|
||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
||||
resp := RespBase{Msg: "FAIL", Status: 211}
|
||||
filename := c.Query("filename")
|
||||
file,e := os.Open( "files//" +filename)
|
||||
if nil != e{
|
||||
file, e := os.Open("files//" + filename)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
c.JSON(200,resp)
|
||||
c.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
bytes,e :=ioutil.ReadAll(file)
|
||||
if nil != e{
|
||||
bytes, e := ioutil.ReadAll(file)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
c.JSON(200,resp)
|
||||
c.JSON(200, resp)
|
||||
return
|
||||
}
|
||||
c.Header("X-Content-Type-Options", "nosniff")
|
||||
c.Header("Content-Disposition",
|
||||
"/files/" + filename)
|
||||
"/files/"+filename)
|
||||
c.Writer.Write(bytes)
|
||||
|
||||
}
|
||||
|
@ -127,42 +127,42 @@ func (this *FileController) OnFileUploadFile(c *gin.Context) {
|
|||
path := c.Query("path")
|
||||
filename := c.Query("filename")
|
||||
file, _, err := c.Request.FormFile("file")
|
||||
if nil != err || nil == file{
|
||||
if nil != err || nil == file {
|
||||
log.Print(err.Error())
|
||||
return
|
||||
}
|
||||
bytes,err := ioutil.ReadAll(file)
|
||||
if nil != err{
|
||||
bytes, err := ioutil.ReadAll(file)
|
||||
if nil != err {
|
||||
log.Print(err.Error())
|
||||
return
|
||||
}
|
||||
header := make([]byte,512)
|
||||
copy(header,bytes)
|
||||
header := make([]byte, 512)
|
||||
copy(header, bytes)
|
||||
types := http.DetectContentType(header)
|
||||
log.Print(types)
|
||||
// jpg
|
||||
defer file.Close()
|
||||
out, err := os.Create("files/" + path + "/" + filename)
|
||||
out, err := os.Create("files/" + path + "/" + filename)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
defer out.Close()
|
||||
out.Write(bytes)
|
||||
log.Print(len(bytes))
|
||||
c.JSON(200, map[string] interface{}{"msg": "ok" })
|
||||
c.JSON(200, map[string]interface{}{"msg": "ok"})
|
||||
}
|
||||
|
||||
func (this *FileController) OnThumbnail(c *gin.Context) {
|
||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
||||
resp := RespBase{Msg: "FAIL", Status: 211}
|
||||
|
||||
fileName := c.Param("file")
|
||||
if "" == fileName{
|
||||
c.JSON(200,resp)
|
||||
if "" == fileName {
|
||||
c.JSON(200, resp)
|
||||
|
||||
return
|
||||
}
|
||||
// input files
|
||||
files := []string{"/home/ubuntu/api/bin/image/" +fileName}
|
||||
files := []string{"/home/ubuntu/api/bin/image/" + fileName}
|
||||
|
||||
// load images and make 100x100 thumbnails of them
|
||||
var thumbnails []image.Image
|
||||
|
@ -184,63 +184,62 @@ func (this *FileController) OnThumbnail(c *gin.Context) {
|
|||
}
|
||||
|
||||
// save the combined image to file
|
||||
err := imaging.Save(dst, "/home/ubuntu/api/bin/image/thumbnail_" + fileName)
|
||||
err := imaging.Save(dst, "/home/ubuntu/api/bin/image/thumbnail_"+fileName)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
return
|
||||
}
|
||||
// open file
|
||||
file,e := os.Open("/home/ubuntu/api/bin/image/thumbnail_" + fileName)
|
||||
if nil != e{
|
||||
file, e := os.Open("/home/ubuntu/api/bin/image/thumbnail_" + fileName)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
c.JSON(200,resp)
|
||||
c.JSON(200, resp)
|
||||
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
bytes,e :=ioutil.ReadAll(file)
|
||||
if nil != e{
|
||||
bytes, e := ioutil.ReadAll(file)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
c.JSON(200,resp)
|
||||
c.JSON(200, resp)
|
||||
|
||||
return
|
||||
}
|
||||
c.Header("X-Content-Type-Options", "nosniff")
|
||||
c.Header("Content-Type","image/png")
|
||||
c.Header("Content-Type", "image/png")
|
||||
c.Header("Content-Disposition",
|
||||
"/image/" +fileName)
|
||||
"/image/"+fileName)
|
||||
c.Writer.Write(bytes)
|
||||
}
|
||||
|
||||
|
||||
func (this *FileController) OnDownLoad(c *gin.Context) {
|
||||
resp := RespBase{Msg:"FAIL",Status: 211}
|
||||
func (this *FileController) OnDownLoad(c *gin.Context) {
|
||||
resp := RespBase{Msg: "FAIL", Status: 211}
|
||||
|
||||
fileName := c.Param("file")
|
||||
if "" == fileName{
|
||||
c.JSON(200,resp)
|
||||
if "" == fileName {
|
||||
c.JSON(200, resp)
|
||||
|
||||
return
|
||||
}
|
||||
file,e := os.Open(utils.GetCurrentDirectory() + "/image/" +fileName)
|
||||
file, e := os.Open(utils.GetCurrentDirectory() + "/image/" + fileName)
|
||||
|
||||
if nil != e{
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
c.JSON(200,resp)
|
||||
c.JSON(200, resp)
|
||||
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
bytes,e :=ioutil.ReadAll(file)
|
||||
if nil != e{
|
||||
bytes, e := ioutil.ReadAll(file)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
c.JSON(200,resp)
|
||||
c.JSON(200, resp)
|
||||
|
||||
return
|
||||
}
|
||||
c.Header("X-Content-Type-Options", "nosniff")
|
||||
c.Header("Content-Type","image/png")
|
||||
c.Header("Content-Type", "image/png")
|
||||
c.Header("Content-Disposition",
|
||||
"/image/" +fileName)
|
||||
"/image/"+fileName)
|
||||
c.Writer.Write(bytes)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"background/db"
|
||||
"background/model"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PlanController struct {
|
||||
}
|
||||
|
||||
func (this *PlanController) GetPlan(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
func (this *PlanController) GetPlanDates(c *gin.Context) {
|
||||
type Req struct {
|
||||
Date string `json:"date"`
|
||||
}
|
||||
var req Req
|
||||
|
||||
resp := RespBase{
|
||||
Msg: "ERROR",
|
||||
Status: 23,
|
||||
}
|
||||
defer c.JSON(200, &resp)
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
plan := []model.Plan{}
|
||||
e = db.GetOrm().Model(&plan).Where("date = ?", req.Date).Find(&plan).Error
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
}
|
||||
resp.Status = 0
|
||||
resp.Msg = "OK"
|
||||
resp.Data = plan
|
||||
return
|
||||
}
|
||||
|
||||
func (this *PlanController) AddPlan(c *gin.Context) {
|
||||
var req model.Plan
|
||||
resp := RespBase{Msg: "r", Status: 0, Data: nil}
|
||||
defer c.JSON(200, &resp)
|
||||
e := c.BindJSON(&req)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
e = db.GetOrm().Create(&req).Error
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
}
|
||||
|
||||
func (this *PlanController) DelPlan(c *gin.Context) {
|
||||
resp := RespBase{Msg: "r", Status: 0, Data: nil}
|
||||
defer c.JSON(200, &resp)
|
||||
var e error
|
||||
iid := 0
|
||||
id := c.Query("id")
|
||||
if "" != id {
|
||||
iid, e = strconv.Atoi(id)
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
return
|
||||
}
|
||||
plan := model.Plan{}
|
||||
plan.ID = uint32(iid)
|
||||
e = db.GetOrm().Delete(&plan).Error
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
return
|
||||
}
|
||||
resp.Msg = "OK"
|
||||
resp.Status = 0
|
||||
}
|
20
main.go
20
main.go
|
@ -27,6 +27,7 @@ var (
|
|||
userController = controller.UserController{}
|
||||
mailContoller = controller.MailController{}
|
||||
fileController = controller.FileController{}
|
||||
planController = controller.PlanController{}
|
||||
)
|
||||
|
||||
func CORSMiddleware(c *gin.Context) {
|
||||
|
@ -149,7 +150,7 @@ func main() {
|
|||
api.POST("/hardware", controller.AddHardware) // 新增硬件
|
||||
api.GET("/hardware", controller.ReadHardWare) // 读取硬件
|
||||
api.DELETE("/hardware", controller.DeleteHardWare) // 读取硬件
|
||||
api.POST("/doc_search",)
|
||||
api.POST("/doc_search")
|
||||
api.PUT("/file", fileController.OnFileUploadFile) // 上传文件
|
||||
api.GET("/file", fileController.DownloadFile) // 下载 文件
|
||||
api.GET("/filelist", fileController.FileList) // 文件列表
|
||||
|
@ -168,12 +169,17 @@ func main() {
|
|||
|
||||
api.GET("doc_versions", nil) // 获取文章的某个版本
|
||||
|
||||
api.PUT("/book", controller.CreateBook) //
|
||||
api.POST("/book", controller.UpdateBook) //
|
||||
api.POST("/getbook", controller.GetBook) // 单书籍数据
|
||||
api.POST("/getbooks", controller.GetPageBook) // 批量书籍
|
||||
api.POST("/delbook", controller.Delbook) // 删除书籍
|
||||
api.GET("/bookcount", controller.BookCount) // 删除书籍
|
||||
api.PUT("/book", controller.CreateBook) //
|
||||
api.POST("/book", controller.UpdateBook) //
|
||||
api.POST("/getbook", controller.GetBook) // 单书籍数据
|
||||
api.POST("/getbooks", controller.GetPageBook) // 批量书籍
|
||||
api.POST("/delbook", controller.Delbook) // 删除书籍
|
||||
api.GET("/bookcount", controller.BookCount) // 删除书籍
|
||||
|
||||
api.POST("/get_plans", planController.GetPlanDates)
|
||||
api.PUT("/plan", planController.AddPlan)
|
||||
api.DELETE("/plan", planController.DelPlan)
|
||||
|
||||
}
|
||||
|
||||
openapi := r.Group("openapi")
|
||||
|
|
|
@ -9,21 +9,18 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type Plan struct {
|
||||
ID uint32 `gorm:"column:id;primary_key" json:"id"`
|
||||
ID uint32 `gorm:"column:id;primary_key" json:"id"`
|
||||
StartTime utils.OrmTime `gorm:"column:start_time" json:"start_time"`
|
||||
EndTime utils.OrmTime `gorm:"column:end_time" json:"end_time"`
|
||||
Date utils.OrmTime `gorm:"column:date" json:"date"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
Date string `gorm:"column:date" json:"date"`
|
||||
Content string `gorm:"column:content" json:"content"`
|
||||
}
|
||||
|
||||
func (m *Plan) TableName() string {
|
||||
return "plan"
|
||||
}
|
||||
|
||||
|
||||
type Users struct {
|
||||
ID int64 `sql:"id" json:"id"`
|
||||
UserName string `sql:"user_name" json:"user_name"`
|
||||
|
@ -63,18 +60,18 @@ func GetUsers(limit int32, offsetPage int32, name string) ([]Users, int32) {
|
|||
return users, cnts[0].Count
|
||||
}
|
||||
|
||||
func ModyfyPassword(UserName string ,Password string) error {
|
||||
func ModyfyPassword(UserName string, Password string) error {
|
||||
h := md5.New()
|
||||
h.Write([]byte(Password))
|
||||
query := fmt.Sprintf("update users set user_pwd = '%s' where user_name = '%s' ",
|
||||
utils.ByteSliceToString(h.Sum(nil)),UserName)
|
||||
n,err := db.GetMysqlClient().Update(query)
|
||||
utils.ByteSliceToString(h.Sum(nil)), UserName)
|
||||
n, err := db.GetMysqlClient().Update(query)
|
||||
if nil != err {
|
||||
logs.Error(err.Error())
|
||||
return err
|
||||
}
|
||||
if n == 0{
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue