Commit a9c2f290 by Li Feifei

debug

parent 58443297
Pipeline #15960 passed with stages
in 33 seconds
...@@ -23,7 +23,7 @@ type ( ...@@ -23,7 +23,7 @@ type (
UploadFileInfo struct { UploadFileInfo struct {
FileName string `json:"FileName"` FileName string `json:"FileName"`
FileSize int64 `json:"FileSize"` FileSize int64 `json:"FileSize"`
PageCount int `jons:"PageCount"` PageCount int `json:"PageCount"`
SlideCount int `json:"SlideCount"` SlideCount int `json:"SlideCount"`
SheetCount int `json:"SheetCount"` SheetCount int `json:"SheetCount"`
} }
......
package http package http
import ( import (
"fmt"
"io" "io"
"os" "os"
"strings"
"time" "time"
"github.com/gogf/gf/frame/g" "github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/util/gconv"
) )
func Get(url string) ([]byte, error) { func Get(url string) ([]byte, error) {
...@@ -24,34 +21,9 @@ func handle(response *ghttp.ClientResponse, err error) ([]byte, error) { ...@@ -24,34 +21,9 @@ func handle(response *ghttp.ClientResponse, err error) ([]byte, error) {
return response.ReadAll(), nil return response.ReadAll(), nil
} }
type WriteCounter struct {
Total uint64
Length uint64
}
func (wc *WriteCounter) Write(p []byte) (int, error) {
n := len(p)
wc.Total += uint64(n)
wc.PrintProgress()
return n, nil
}
func (wc WriteCounter) PrintProgress() {
// Clear the line by using a character return to go back to the start and remove
// the remaining characters by filling it with spaces
fmt.Printf("\r%s", strings.Repeat(" ", 35))
// Return again and print current status of download
// We use the humanize package to print the bytes in a meaningful way (e.g. 10 MB)
fmt.Printf("\rDownloading... %s complete", fmt.Sprintf("%.2f", gconv.Float64(wc.Total)/gconv.Float64(wc.Length) * 100) + "%")
}
// 下载文件 // 下载文件
func Download(file string, path string) error { func Download(file string, path string) error {
g.Log().Async().Infof("Download File: %s", path) g.Log().Async().Infof("Download File: %s", file)
resp, err := g.Client().Get(file) resp, err := g.Client().Get(file)
if err != nil { if err != nil {
...@@ -65,20 +37,12 @@ func Download(file string, path string) error { ...@@ -65,20 +37,12 @@ func Download(file string, path string) error {
return err return err
} }
defer out.Close() defer out.Close()
// 然后将响应流和文件流对接起来 // 然后将响应流和文件流对接起来
counter := &WriteCounter{Length: gconv.Uint64(resp.Header.Get("Content-Length"))} _, err = io.Copy(out, resp.Body)
_, err = io.Copy(out, io.TeeReader(resp.Body, counter)) if err == io.EOF {
if err != nil && err == io.EOF {
return nil return nil
} }
if err != nil {
return err return err
}
fmt.Print("\n")
return nil
} }
...@@ -34,6 +34,7 @@ func (n *notify) verify(url string, data g.Map) error { ...@@ -34,6 +34,7 @@ func (n *notify) verify(url string, data g.Map) error {
if err != nil { if err != nil {
return err return err
} }
g.Log().Async().Infof("url: %s, res: %s", url, string(res))
var notifyResponse model.NotifyResponse var notifyResponse model.NotifyResponse
if err = json.Unmarshal(res, &notifyResponse); err != nil { if err = json.Unmarshal(res, &notifyResponse); err != nil {
...@@ -68,13 +69,8 @@ func (n *notify) auth(data g.Map) error { ...@@ -68,13 +69,8 @@ func (n *notify) auth(data g.Map) error {
// 发送通知 // 发送通知
func (n *notify) notice(path string, data g.Map) error { func (n *notify) notice(path string, data g.Map) error {
var err error if err := n.auth(data); err != nil {
if err = n.auth(data); err != nil {
return err return err
} }
if err = n.verify(n.url+path, data); err != nil { return n.verify(n.url+path, data)
return err
}
g.Log().Async().Infof("Notify Success!")
return nil
} }
...@@ -74,6 +74,8 @@ func (f *ObtainFile) fileInfo() error { ...@@ -74,6 +74,8 @@ func (f *ObtainFile) fileInfo() error {
if err != nil { if err != nil {
return err return err
} }
g.Log().Async().Infof("file info: %s", string(fileBytes))
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
...@@ -82,7 +84,6 @@ func (f *ObtainFile) fileInfo() error { ...@@ -82,7 +84,6 @@ func (f *ObtainFile) fileInfo() error {
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
...@@ -237,6 +238,7 @@ func (f *ObtainFile) Fail() { ...@@ -237,6 +238,7 @@ func (f *ObtainFile) Fail() {
}); err != nil { }); err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
} }
g.Log().Async().Infof("Fail Notify Success!")
} }
// 上传成功通知 // 上传成功通知
...@@ -261,4 +263,5 @@ func (f *ObtainFile) Success(roomID int) { ...@@ -261,4 +263,5 @@ func (f *ObtainFile) Success(roomID int) {
}); err != nil { }); err != nil {
g.Log().Async().Error(err) g.Log().Async().Error(err)
} }
g.Log().Async().Infof("Success Notify Success!")
} }
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