Commit e4ed42da by a2231243

code format

parent 81a1926b
Pipeline #15532 failed with stages
in 11 seconds
......@@ -8,7 +8,7 @@ import (
)
// Recover异常恢复
func MiddlewareRecover(r *ghttp.Request) {
func Recover(r *ghttp.Request) {
r.Middleware.Next()
if err := r.GetError(); err != nil {
r.Response.ClearBuffer()
......@@ -18,19 +18,17 @@ func MiddlewareRecover(r *ghttp.Request) {
"code": http.StatusBadRequest,
"msg": e.FirstString(),
})
default:
_ = r.Response.WriteJson(g.Map{
"code": http.StatusInternalServerError,
"msg": err.Error(),
})
}
}
}
// CORS跨域
func MiddlewareCors(r *ghttp.Request) {
func Cors(r *ghttp.Request) {
r.Response.CORSDefault()
r.Middleware.Next()
}
package packed
import (
"errors"
"fmt"
"github.com/gogf/gf/frame/g"
"mime"
"net/url"
"path"
"strings"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
)
type file struct {
......@@ -34,8 +35,8 @@ func NewFile(ossFileLink, name string) (*file, error) {
slicePath := strings.Split(strings.TrimLeft(dataPath, "/"), "/")
if len(slicePath) < 4 {
g.Log().Async().Error(errors.New("上传URL格式不正确"))
return nil, errors.New("上传URL格式不正确")
g.Log().Async().Error(gerror.New("上传URL格式不正确"))
return nil, gerror.New("上传URL格式不正确")
}
f := &file{
ext: path.Ext(name),
......
......@@ -4,7 +4,6 @@ import (
"archive/zip"
"bytes"
"encoding/json"
"errors"
"fmt"
"image"
"image/jpeg"
......@@ -18,15 +17,16 @@ import (
"ppt_server/app/model"
"ppt_server/library"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/xxjwxc/gowp/workpool"
)
// 解析URL返回基本信息
type ObtainFile struct {
r *model.FileUploadRequest //客户端请求参数
r *model.FileUploadRequest // 客户端请求参数
bucket *ossSdk // oss上传bucket
ok chan *model.SuccessResponse // 上传传课件状态
ok chan *model.SuccessResponse // 上传课件响应成功
err chan error // 上传课件失败Error
fileSize int64 // 课件大小
pageCount int // 课件图片数量
......@@ -72,6 +72,7 @@ func (f *ObtainFile) fileInfo() error {
}
var fileInfo model.UploadFileInfo
if err := json.Unmarshal(fileBytes, &fileInfo); err != nil {
return err
}
......@@ -115,10 +116,10 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) {
case ".jpeg":
img, _ = jpeg.Decode(imageReader)
default:
return nil, errors.New("image ext is not found")
return nil, gerror.New("image ext is not found")
}
if img == nil {
return nil, errors.New("Image invalid")
return nil, gerror.New("Image invalid")
}
var filenameOnly string
......@@ -206,12 +207,14 @@ func (f *ObtainFile) Worker(err error) {
f.parserFile.dataPath)
// 下载ZIP包
if err = library.Download(downloadZipLink, f.parserFile.tempZipPath); err != nil {
g.Log().Async().Error(err)
f.err <- err
return
}
// 清理ZIP包
defer os.Remove(f.parserFile.tempZipPath)
g.Log().Async().Infof("file: %s Zip Donwload Complete", f.parserFile.name)
// 解析ZIP包并上传图片到OSS
......@@ -230,8 +233,6 @@ func (f *ObtainFile) Worker(err error) {
}
g.Log().Async().Infof("filename == %s upload success!", f.parserFile.name)
// 清理zip包
_ = os.Remove(f.parserFile.tempZipPath)
res := &model.SuccessResponse{
Name: f.parserFile.name,
......
......@@ -2,7 +2,6 @@ package packed
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/http/cookiejar"
......@@ -12,6 +11,7 @@ import (
"ppt_server/app/model"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
)
......@@ -50,7 +50,7 @@ func (n *Notfiy) post(url string, data g.Map) error {
}
if login.Code != 200 {
return errors.New(login.Msg)
return gerror.New(login.Msg)
}
return nil
}
......@@ -128,6 +128,5 @@ func (n *Notfiy) Fail(object *ObtainFile) {
}
func (n *Notfiy) Success(res *model.SuccessResponse) {
n.notify("/web/room_files_add", gconv.Map(res))
}
......@@ -12,12 +12,14 @@ func init() {
s := g.Server()
s.Use(
middleware.MiddlewareCors,
middleware.MiddlewareRecover,
middleware.Cors,
middleware.Recover,
)
s.Group(`file`, func(group *ghttp.RouterGroup) {
group.GET(`/upload`, api.File.Index)
group.POST(`/upload`, api.File.Upload)
group.ALL(`/`, api.File, "Index, Upload")
//group.GET(`/upload`, api.File.Index)
//group.POST(`/upload`, api.File.Upload)
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment