Commit df4051dc by a2231243

code format

parent 3f4aebf9
Pipeline #15530 failed with stages
in 10 seconds
...@@ -10,8 +10,7 @@ import ( ...@@ -10,8 +10,7 @@ import (
var File = fileApi{} var File = fileApi{}
type fileApi struct { type fileApi struct{}
}
func (f *fileApi) Index(r *ghttp.Request) { func (f *fileApi) Index(r *ghttp.Request) {
_ = r.Response.WriteJson(g.Map{ _ = r.Response.WriteJson(g.Map{
......
...@@ -39,3 +39,24 @@ type NotifyResponse struct { ...@@ -39,3 +39,24 @@ type NotifyResponse struct {
Code int64 `json:"code"` Code int64 `json:"code"`
Msg string `json:"msg"` Msg string `json:"msg"`
} }
// 上传成功响应内容
type SuccessResponse struct {
Name string `c:"name"`
Nickanem string `c:"nickname"`
NameHash string `c:"file_name_hash"`
Uuid string `c:"uuid"`
ContentHash string `c:"hash"`
DataPath string `c:"path"`
DocType string `c:"doc_type"`
MineType string `c:"type"`
FileSize int64 `c:"files_size"`
PageCount int `c:"page_count"`
Link string `c:"link"`
Private string `c:"private"`
Time string `c:"time"`
RoomID int `c:"room_id"`
IsCourseware int `c:"is_courseware, omitempty"`
IsMaterial int `c:"is_material, omitempty"`
IsTitlebook int `c:"is_titlebook, omitempty"`
}
...@@ -10,12 +10,12 @@ import ( ...@@ -10,12 +10,12 @@ import (
var File = &fileService{ var File = &fileService{
done: make(chan error), done: make(chan error),
ok: make(chan bool), ok: make(chan *model.SuccessResponse),
} }
type fileService struct { type fileService struct {
done chan error done chan error
ok chan bool ok chan *model.SuccessResponse
} }
// 上传课件 // 上传课件
...@@ -30,9 +30,10 @@ func (f *fileService) Upload(r *model.FileUploadRequest) { ...@@ -30,9 +30,10 @@ func (f *fileService) Upload(r *model.FileUploadRequest) {
var room model.XyuRoom var room model.XyuRoom
err = dao.XyuRoom.Where(dao.XyuRoom.Columns.RoomNum, r.RoomNum).Scan(&room) err = dao.XyuRoom.Where(dao.XyuRoom.Columns.RoomNum, r.RoomNum).Scan(&room)
if err != nil { if err != nil {
go func() { f.done <- err }()
g.Log().Async().Errorf("房间不存在, room_num: %s\n", r.RoomNum) g.Log().Async().Errorf("房间不存在, room_num: %s\n", r.RoomNum)
go func() { f.done <- err }()
} }
// 上传操作 // 上传操作
go parserURLObject.Worker(err) go parserURLObject.Worker(err)
...@@ -41,10 +42,9 @@ func (f *fileService) Upload(r *model.FileUploadRequest) { ...@@ -41,10 +42,9 @@ func (f *fileService) Upload(r *model.FileUploadRequest) {
select { select {
case <-f.done: case <-f.done:
// 上传失败 // 上传失败
n.Notify("/web/room_files_error", packed.FailGmap(r, parserURLObject)) n.Fail(parserURLObject)
return return
case res := <-f.ok:
case <-f.ok:
// 上传成功 // 上传成功
count, err := dao.XyuRoomFile.Where(dao.XyuRoomFile.Columns.RoomId, room.Id). count, err := dao.XyuRoomFile.Where(dao.XyuRoomFile.Columns.RoomId, room.Id).
Where(dao.XyuRoomFile.Columns.Name, r.Name).Count() Where(dao.XyuRoomFile.Columns.Name, r.Name).Count()
...@@ -56,6 +56,7 @@ func (f *fileService) Upload(r *model.FileUploadRequest) { ...@@ -56,6 +56,7 @@ func (f *fileService) Upload(r *model.FileUploadRequest) {
if count == 1 { if count == 1 {
return return
} }
n.Notify("/web/room_files_add", packed.SuccessGmap(r, parserURLObject, room.Id)) res.RoomID = room.Id
n.Success(res)
} }
} }
# HTTP Server # HTTP Server
[server] [server]
Address = ":80" Address = ":80"
ServerRoot = "public" ServerAgent = "gf-app"
ServerAgent = "gf-app" LogPath = "/tmp/log/gf-app/server"
LogPath = "/tmp/log/gf-app/server" DumpRouterMap = true
DumpRouterMap = true
# Logger. # Logger.
...@@ -14,17 +13,22 @@ ...@@ -14,17 +13,22 @@
StdoutPrint = true StdoutPrint = true
HeaderPrint = true HeaderPrint = true
# 回调通知
[notify] [notify]
url = "http://offcn-live-svc" url = "http://test-live.offcncloud.com"
name = "offcn" name = "offcn"
password = "123123" password = "123123"
[oss] [oss]
url = "https://xiaoyu-live.oss-cn-beijing-internal.aliyuncs.com" url = "https://xiaoyu-live.oss-cn-beijing.aliyuncs.com"
point = "oss-cn-beijing.aliyuncs.com" point = "oss-cn-beijing.aliyuncs.com"
keyid = "LTAI1fMvVUPBXl2E" keyid = "LTAI1fMvVUPBXl2E"
serect = "cTAMLufmPFznfE0peur8oMmy2c5kvk" serect = "cTAMLufmPFznfE0peur8oMmy2c5kvk"
bucket = "xiaoyu-live"
# 下载zip包存储目录
[temp]
path = "D:/"
# Database. # Database.
[database] [database]
...@@ -35,10 +39,3 @@ ...@@ -35,10 +39,3 @@
Path = "/tmp/log/gf-app/sql" Path = "/tmp/log/gf-app/sql"
Level = "all" Level = "all"
Stdout = true Stdout = true
# Template.
[viewer]
Path = "template"
DefaultFile = "index.html"
Delimiters = ["${", "}"]
...@@ -281,4 +281,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C ...@@ -281,4 +281,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gorm.io/driver/mysql v1.0.1/go.mod h1:KtqSthtg55lFp3S5kUXqlGaelnWpKitn4k1xZTnoiPw= gorm.io/driver/mysql v1.0.1/go.mod h1:KtqSthtg55lFp3S5kUXqlGaelnWpKitn4k1xZTnoiPw=
gorm.io/gorm v1.9.19/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= gorm.io/gorm v1.9.19/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.20.2/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= gorm.io/gorm v1.20.2/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
\ No newline at end of file
...@@ -19,6 +19,7 @@ func Get(url string) ([]byte, error) { ...@@ -19,6 +19,7 @@ func Get(url string) ([]byte, error) {
} }
func Download(file string, path string) error { func Download(file string, path string) error {
g.Log().Async().Infof("Download zip url: %s ", file)
resp, err := http.Get(file) resp, err := http.Get(file)
if err != nil { if err != nil {
return err return err
......
package packed package packed
import ( import (
"errors"
"fmt"
"github.com/gogf/gf/frame/g"
"mime" "mime"
"net/url"
"path"
"strings"
) )
type file struct { type file struct {
ext string url string //课件地址
ext string //课件后缀
name string //课件名称
nameHash string //课件名hash
contentHash string //课件内容hash
dataPath string //数据库存储路径
fileInfoURL string //解析课件的URL
tempZipPath string //临时存放zip包地址
uploadPath string //oss存储路径
docType string //课件type类型
mineType string //课件mine类型
}
func NewFile(ossFileLink, name string) (*file, error) {
u, err := url.Parse(ossFileLink)
if err != nil {
g.Log().Async().Error(err)
return nil, err
}
dataPath := u.EscapedPath()
slicePath := strings.Split(strings.TrimLeft(dataPath, "/"), "/")
if len(slicePath) < 4 {
g.Log().Async().Error(errors.New("上传URL格式不正确"))
return nil, errors.New("上传URL格式不正确")
}
f := &file{
ext: path.Ext(name),
url: ossFileLink,
dataPath: dataPath[1:],
nameHash: slicePath[3],
contentHash: slicePath[2],
name: name,
fileInfoURL: fmt.Sprintf("%s?info=0&ssl=1&furl=%s%s",
ParserFileLink,
g.Cfg().GetString("oss.url"),
dataPath),
tempZipPath: fmt.Sprintf("%s%s.zip",
g.Cfg().GetString("temp.path"),
slicePath[2]),
uploadPath: strings.Join(slicePath[0:len(slicePath)-1], "/") + "/",
}
f.docType = f.getDocType()
f.mineType = f.getMine()
return f, nil
} }
// 解析doctype // 解析doctype
...@@ -26,6 +77,5 @@ func (f *file) getDocType() string { ...@@ -26,6 +77,5 @@ func (f *file) getDocType() string {
// 获取文件mine // 获取文件mine
func (f *file) getMine() string { func (f *file) getMine() string {
_ = mime.AddExtensionType(".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation")
return mime.TypeByExtension(f.ext) return mime.TypeByExtension(f.ext)
} }
...@@ -10,10 +10,10 @@ import ( ...@@ -10,10 +10,10 @@ import (
"image/jpeg" "image/jpeg"
"image/png" "image/png"
"io/ioutil" "io/ioutil"
"net/url"
"os" "os"
"path" "path"
"strings" "strings"
"time"
"ppt_server/app/model" "ppt_server/app/model"
"ppt_server/library" "ppt_server/library"
...@@ -22,64 +22,43 @@ import ( ...@@ -22,64 +22,43 @@ import (
"github.com/xxjwxc/gowp/workpool" "github.com/xxjwxc/gowp/workpool"
) )
// 解析URL返回基本信息 // 解析URL返回基本信息
type ObtainFile struct { type ObtainFile struct {
url string //上传URL r *model.FileUploadRequest //客户端请求参数
fileName string //上传文件名 bucket *ossSdk // oss上传bucket
NameHash string //文件名hash ok chan *model.SuccessResponse // 上传传课件状态
ContentHash string //内容hash err chan error // 上传课件失败Error
DocType string //doc_type fileSize int64 // 课件大小
MineType string //文件mine类型 pageCount int // 课件图片数量
fileInfoURL string //解析文件URL地址 parserFile *file // 课件对象
uploadPath string //上传URL路径
DataPath string // 数据库存储Path
Link string //数据库存储link
FileSize int64
PageCount int
bucket *ossSdk
ok chan bool //上传传课件状态
err chan error // 上传课件失败Error
} }
func ParserURL(r *model.FileUploadRequest, errChan chan error, ok chan bool) (*ObtainFile, error) { const (
u, err := url.Parse(r.Url) ParserFileLink = "http://doc.offcncloud.com/"
OssIntranetLink = "xiaoyu-live.oss-cn-beijing-internal.aliyuncs.com"
UploadFileLinkHost = "desktop.offcncloud.com"
)
func ParserURL(r *model.FileUploadRequest, errChan chan error,
ok chan *model.SuccessResponse) (*ObtainFile, error) {
f, err := NewFile(r.Url, r.Name)
if err != nil { if err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
return nil, err return nil, err
} }
dataPath := u.EscapedPath()[1:] bucket, err := NewOss(g.Cfg().GetString("oss.bucket"))
slicePath := strings.Split(dataPath, "/")
if len(slicePath) < 4 {
g.Log().Async().Error(errors.New("上传URL格式不正确"))
return nil, errors.New("上传URL格式不正确")
}
f := &file{
ext: path.Ext(r.Name),
}
buecket, err := NewOss("xiaoyu-live")
if err != nil { if err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
return nil, err return nil, err
} }
file := &ObtainFile{ file := &ObtainFile{
url: r.Url, bucket: bucket,
fileName: r.Name, ok: ok,
NameHash: slicePath[3], err: errChan,
ContentHash: slicePath[2], parserFile: f,
DocType: f.getDocType(), r: r,
MineType: f.getMine(),
bucket: buecket,
fileInfoURL: "http://doc.offcncloud.com/?info=0&ssl=1&furl=" + g.Cfg().GetString("oss.url") + u.EscapedPath(),
uploadPath: strings.Join(slicePath[0:len(slicePath)-1], "/") + "/",
DataPath: dataPath,
err: errChan,
ok: ok,
Link: strings.Replace(r.Url, "xiaoyu-live.oss-cn-beijing-internal.aliyuncs.com", "desktop.offcncloud.com", -1),
} }
return file, nil return file, nil
...@@ -87,26 +66,27 @@ func ParserURL(r *model.FileUploadRequest, errChan chan error, ok chan bool) (*O ...@@ -87,26 +66,27 @@ func ParserURL(r *model.FileUploadRequest, errChan chan error, ok chan bool) (*O
//从web365获取上传文件信息 //从web365获取上传文件信息
func (f *ObtainFile) fileInfo() error { func (f *ObtainFile) fileInfo() error {
fileBytes, err := library.Get(f.parserFile.fileInfoURL)
fileBytes, err := library.Get(f.fileInfoURL)
if err != nil { if err != nil {
return err return err
} }
var fileInfo model.UploadFileInfo var fileInfo model.UploadFileInfo
if err := json.Unmarshal(fileBytes, &fileInfo); err != nil { if err := json.Unmarshal(fileBytes, &fileInfo); err != nil {
return err return err
} }
if fileInfo.FileSize != 0 { if fileInfo.FileSize != 0 {
f.FileSize = fileInfo.FileSize f.fileSize = fileInfo.FileSize
} }
switch { switch {
case fileInfo.SlideCount != 0: case fileInfo.SlideCount != 0:
f.PageCount = fileInfo.SlideCount f.pageCount = fileInfo.SlideCount
case fileInfo.PageCount != 0: case fileInfo.PageCount != 0:
f.PageCount = fileInfo.PageCount f.pageCount = fileInfo.PageCount
case fileInfo.SheetCount != 0: case fileInfo.SheetCount != 0:
f.PageCount = fileInfo.SheetCount f.pageCount = fileInfo.SheetCount
} }
return nil return nil
...@@ -120,13 +100,12 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) { ...@@ -120,13 +100,12 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) {
defer fd.Close() defer fd.Close()
reqBody := []byte{} fileBytes := []byte{}
reqBody, _ = ioutil.ReadAll(fd) fileBytes, _ = ioutil.ReadAll(fd)
// 获取图片信息reader // 获取图片信息reader
imageReader := ioutil.NopCloser(bytes.NewBuffer(reqBody)) imageReader := ioutil.NopCloser(bytes.NewBuffer(fileBytes))
// 上传图片reader // 上传图片reader
fileReader := ioutil.NopCloser(bytes.NewBuffer(reqBody)) fileReader := ioutil.NopCloser(bytes.NewBuffer(fileBytes))
var img image.Image var img image.Image
fileSuffix := path.Ext(file.Name) //获取文件后缀 fileSuffix := path.Ext(file.Name) //获取文件后缀
...@@ -155,7 +134,7 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) { ...@@ -155,7 +134,7 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) {
g.Log().Async().Infof("Upload picture file: %s Success", fileName) g.Log().Async().Infof("Upload picture file: %s Success", fileName)
return imageInfo, f.bucket.Upload(f.uploadPath+"images/"+fileName, fileReader) return imageInfo, f.bucket.Upload(f.parserFile.uploadPath+"images/"+fileName, fileReader)
} }
func (f *ObtainFile) uploadPng(zipFileAddress string) ([][]interface{}, error) { func (f *ObtainFile) uploadPng(zipFileAddress string) ([][]interface{}, error) {
...@@ -182,6 +161,7 @@ func (f *ObtainFile) uploadPng(zipFileAddress string) ([][]interface{}, error) { ...@@ -182,6 +161,7 @@ func (f *ObtainFile) uploadPng(zipFileAddress string) ([][]interface{}, error) {
if err = pool.Wait(); err != nil { if err = pool.Wait(); err != nil {
return nil, err return nil, err
} }
return imageInfos, nil return imageInfos, nil
} }
...@@ -189,20 +169,20 @@ func (f *ObtainFile) uploadPng(zipFileAddress string) ([][]interface{}, error) { ...@@ -189,20 +169,20 @@ func (f *ObtainFile) uploadPng(zipFileAddress string) ([][]interface{}, error) {
func (f *ObtainFile) uploadPacked(imagesInfos [][]interface{}) error { func (f *ObtainFile) uploadPacked(imagesInfos [][]interface{}) error {
packed := model.Packed{ packed := model.Packed{
FileName: f.fileName, FileName: f.parserFile.name,
Hash: f.ContentHash, Hash: f.parserFile.contentHash,
OssImagesPath: f.uploadPath + "images/", OssImagesPath: f.parserFile.uploadPath + "images/",
ImageInfos: imagesInfos, ImageInfos: imagesInfos,
} }
for i := 1; i <= f.PageCount; i++ { for i := 1; i <= f.pageCount; i++ {
packed.ImagesName = append(packed.ImagesName, fmt.Sprintf("%05d", i)+".png") packed.ImagesName = append(packed.ImagesName, fmt.Sprintf("%05d", i)+".png")
} }
data, err := json.Marshal(packed) data, err := json.Marshal(packed)
if err != nil { if err != nil {
return err return err
} }
return f.bucket.Upload(f.uploadPath+"packed.json", bytes.NewReader(data)) return f.bucket.Upload(f.parserFile.uploadPath+"packed.json", bytes.NewReader(data))
} }
// 进行上传操作 // 进行上传操作
...@@ -217,28 +197,31 @@ func (f *ObtainFile) Worker(err error) { ...@@ -217,28 +197,31 @@ func (f *ObtainFile) Worker(err error) {
f.err <- err f.err <- err
return return
} }
g.Log().Async().Infof("file: %s file info complete", f.fileName) g.Log().Async().Infof("file: %s file info complete", f.parserFile.name)
zipURL := fmt.Sprintf("http://doc.offcncloud.com/?info=1&words=%v&ssl=1&furl=%s", downloadZipLink := fmt.Sprintf("%s?info=1&words=%v&ssl=1&furl=%s/%s",
f.PageCount, g.Cfg().GetString("oss.url")+"/"+f.DataPath) ParserFileLink,
f.pageCount,
g.Cfg().GetString("oss.url"),
f.parserFile.dataPath)
// 下载ZIP包 // 下载ZIP包
zipURLAddress := "D:/" + f.ContentHash + ".zip"
if err = library.Download(zipURL, zipURLAddress); err != nil { if err = library.Download(downloadZipLink, f.parserFile.tempZipPath); err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
f.err <- err f.err <- err
return return
} }
g.Log().Async().Infof("file: %s Zip Donwload Complete", f.fileName) g.Log().Async().Infof("file: %s Zip Donwload Complete", f.parserFile.name)
// 解析ZIP包并上传图片到OSS // 解析ZIP包并上传图片到OSS
imagesInfos, err := f.uploadPng(zipURLAddress) imagesInfos, err := f.uploadPng(f.parserFile.tempZipPath)
if err != nil { if err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
f.err <- err f.err <- err
return return
} }
g.Log().Async().Infof("file: %s Upload picture Complete!", f.fileName) g.Log().Async().Infof("file: %s Upload picture Complete!", f.parserFile.name)
// 上传packed.json到oss // 上传packed.json到oss
if err := f.uploadPacked(imagesInfos); err != nil { if err := f.uploadPacked(imagesInfos); err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
...@@ -246,8 +229,32 @@ func (f *ObtainFile) Worker(err error) { ...@@ -246,8 +229,32 @@ func (f *ObtainFile) Worker(err error) {
return return
} }
g.Log().Async().Infof("filename == %s upload success!", f.fileName) g.Log().Async().Infof("filename == %s upload success!", f.parserFile.name)
// 清理zip包 // 清理zip包
_ = os.Remove(zipURLAddress) _ = os.Remove(f.parserFile.tempZipPath)
f.ok <- true
res := &model.SuccessResponse{
Name: f.parserFile.name,
NameHash: f.parserFile.nameHash,
ContentHash: f.parserFile.contentHash,
DataPath: f.parserFile.dataPath,
DocType: f.parserFile.docType,
MineType: f.parserFile.mineType,
FileSize: f.fileSize,
PageCount: f.pageCount,
Link: strings.Replace(f.parserFile.url, OssIntranetLink, UploadFileLinkHost, -1),
Private: "1",
Time: time.Now().Format("2006-01-02 15:04:05"),
Nickanem: f.r.Nickanem,
Uuid: f.r.Uuid,
}
switch f.r.Type {
case 1:
res.IsMaterial = 1
case 2:
res.IsCourseware = 1
case 3:
res.IsTitlebook = 1
}
f.ok <- res
} }
...@@ -9,7 +9,6 @@ import ( ...@@ -9,7 +9,6 @@ import (
"net/url" "net/url"
"regexp" "regexp"
"strings" "strings"
"time"
"ppt_server/app/model" "ppt_server/app/model"
...@@ -18,7 +17,6 @@ import ( ...@@ -18,7 +17,6 @@ import (
) )
type Notfiy struct { type Notfiy struct {
token string
name string name string
password string password string
url string url string
...@@ -40,7 +38,7 @@ func NewNotfiy() *Notfiy { ...@@ -40,7 +38,7 @@ func NewNotfiy() *Notfiy {
} }
} }
func (n *Notfiy) Post(url string, data g.Map) error { func (n *Notfiy) post(url string, data g.Map) error {
res, err := n.request("POST", url, data) res, err := n.request("POST", url, data)
if err != nil { if err != nil {
...@@ -57,7 +55,7 @@ func (n *Notfiy) Post(url string, data g.Map) error { ...@@ -57,7 +55,7 @@ func (n *Notfiy) Post(url string, data g.Map) error {
return nil return nil
} }
func (n *Notfiy) Get(url string, data g.Map) ([]byte, error) { func (n *Notfiy) get(url string, data g.Map) ([]byte, error) {
return n.request("GET", url, data) return n.request("GET", url, data)
} }
...@@ -85,77 +83,51 @@ func (n *Notfiy) request(method, r_url string, data g.Map) ([]byte, error) { ...@@ -85,77 +83,51 @@ func (n *Notfiy) request(method, r_url string, data g.Map) ([]byte, error) {
return ioutil.ReadAll(res.Body) return ioutil.ReadAll(res.Body)
} }
func (n *Notfiy) setToken() error { func (n *Notfiy) auth() (string, error) {
if err := n.Post(n.url+"/web/login", g.Map{ if err := n.post(n.url+"/web/login", g.Map{
"name": n.name, "name": n.name,
"password": n.password, "password": n.password,
}); err != nil { }); err != nil {
return err return "", err
} }
// 获取Token // 获取Token
tokenTypes, err := n.Get(n.url+"/web/admin", nil) tokenTypes, err := n.get(n.url+"/web/admin", nil)
if err != nil { if err != nil {
return err return "", err
} }
re := regexp.MustCompile(`<meta name="csrf-token" content="([^"]+)">`) re := regexp.MustCompile(`<meta name="csrf-token" content="([^"]+)">`)
token := re.FindAllSubmatch(tokenTypes, -1) token := re.FindAllSubmatch(tokenTypes, -1)
n.token = string(token[0][1]) return string(token[0][1]), nil
return nil
} }
// 上传失败通知 // 上传失败通知
func (n *Notfiy) Notify(path string, data g.Map) { func (n *Notfiy) notify(path string, data g.Map) {
var err error csrfToken, err := n.auth()
if err = n.setToken(); err != nil {
if err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
return return
} }
data["_token"] = n.token data["_token"] = csrfToken
if err = n.Post(n.url+path, data); err != nil { if err = n.post(n.url+path, data); err != nil {
g.Log().Async().Errorf("notify fail, err : %s\n", err) g.Log().Async().Errorf("notify fail, err : %s\n", err)
} }
g.Log().Async().Infof("Notify Success!") g.Log().Async().Infof("Notify Success!")
return return
} }
func FailGmap(r *model.FileUploadRequest, object *ObtainFile) g.Map { func (n *Notfiy) Fail(object *ObtainFile) {
return g.Map{ n.notify("/web/room_files_error", g.Map{
"code": 400, "code": 400,
"uuid": r.Uuid, "uuid": object.r.Uuid,
"room_num": r.RoomNum, "room_num": object.r.RoomNum,
"path": object.DataPath, "path": object.parserFile.dataPath,
} })
} }
func SuccessGmap(r *model.FileUploadRequest, object *ObtainFile, room_id int) g.Map { func (n *Notfiy) Success(res *model.SuccessResponse) {
data := g.Map{
"room_id": room_id,
"is_courseware": "1",
"private": "1",
"nickname": r.Nickanem,
"name": r.Name,
"time": time.Now().Format("2006-01-02 15:04:05"),
"uuid": r.Uuid,
"file_name_hash": object.NameHash,
"hash": object.ContentHash,
"doc_type": object.DocType,
"type": object.MineType,
"path": object.DataPath,
"files_size": object.FileSize,
"link": object.Link,
"page_count": object.PageCount,
}
switch r.Type {
case 1:
data["is_material"] = 1
case 2:
data["is_courseware"] = 1
case 3:
data["is_titlebook"] = 1
}
return data n.notify("/web/room_files_add", gconv.Map(res))
} }
package packed package packed
import ( import (
"io"
"github.com/aliyun/aliyun-oss-go-sdk/oss" "github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"io"
) )
type ossSdk struct { type ossSdk struct {
...@@ -11,7 +12,6 @@ type ossSdk struct { ...@@ -11,7 +12,6 @@ type ossSdk struct {
bucket *oss.Bucket bucket *oss.Bucket
} }
func NewOss(bucket string) (*ossSdk, error) { func NewOss(bucket string) (*ossSdk, error) {
client, err := oss.New(g.Cfg().GetString("oss.point"), client, err := oss.New(g.Cfg().GetString("oss.point"),
g.Cfg().GetString("oss.keyid"), g.Cfg().GetString("oss.serect")) g.Cfg().GetString("oss.keyid"), g.Cfg().GetString("oss.serect"))
......
...@@ -11,8 +11,15 @@ import ( ...@@ -11,8 +11,15 @@ import (
func init() { func init() {
s := g.Server() s := g.Server()
s.Use(middleware.MiddlewareCors, middleware.MiddlewareRecover) s.Use(
middleware.MiddlewareCors,
middleware.MiddlewareRecover,
)
s.Group(`file`, func(group *ghttp.RouterGroup) { s.Group(`file`, func(group *ghttp.RouterGroup) {
group.ALL(`/`, api.File, "Index, 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