Commit a9c2f290 by Li Feifei

debug

parent 58443297
Pipeline #15960 passed with stages
in 33 seconds
......@@ -23,7 +23,7 @@ type (
UploadFileInfo struct {
FileName string `json:"FileName"`
FileSize int64 `json:"FileSize"`
PageCount int `jons:"PageCount"`
PageCount int `json:"PageCount"`
SlideCount int `json:"SlideCount"`
SheetCount int `json:"SheetCount"`
}
......
package http
import (
"fmt"
"io"
"os"
"strings"
"time"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/util/gconv"
)
func Get(url string) ([]byte, error) {
......@@ -24,34 +21,9 @@ func handle(response *ghttp.ClientResponse, err error) ([]byte, error) {
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 {
g.Log().Async().Infof("Download File: %s", path)
g.Log().Async().Infof("Download File: %s", file)
resp, err := g.Client().Get(file)
if err != nil {
......@@ -65,20 +37,12 @@ func Download(file string, path string) error {
return err
}
defer out.Close()
// 然后将响应流和文件流对接起来
counter := &WriteCounter{Length: gconv.Uint64(resp.Header.Get("Content-Length"))}
_, err = io.Copy(out, io.TeeReader(resp.Body, counter))
if err != nil && err == io.EOF {
_, err = io.Copy(out, resp.Body)
if err == io.EOF {
return nil
}
if err != nil {
return err
}
fmt.Print("\n")
return nil
return err
}
......@@ -34,7 +34,8 @@ func (n *notify) verify(url string, data g.Map) error {
if err != nil {
return err
}
g.Log().Async().Infof("url: %s, res: %s", url, string(res))
var notifyResponse model.NotifyResponse
if err = json.Unmarshal(res, &notifyResponse); err != nil {
return err
......@@ -68,13 +69,8 @@ func (n *notify) auth(data g.Map) error {
// 发送通知
func (n *notify) notice(path string, data g.Map) error {
var err error
if err = n.auth(data); err != nil {
return err
}
if err = n.verify(n.url+path, data); err != nil {
if err := n.auth(data); err != nil {
return err
}
g.Log().Async().Infof("Notify Success!")
return nil
return n.verify(n.url+path, data)
}
......@@ -74,6 +74,8 @@ func (f *ObtainFile) fileInfo() error {
if err != nil {
return err
}
g.Log().Async().Infof("file info: %s", string(fileBytes))
var fileInfo model.UploadFileInfo
if err = json.Unmarshal(fileBytes, &fileInfo); err != nil {
return err
......@@ -82,7 +84,6 @@ func (f *ObtainFile) fileInfo() error {
if fileInfo.FileSize != 0 {
f.fileSize = fileInfo.FileSize
}
switch {
case fileInfo.SlideCount != 0:
f.pageCount = fileInfo.SlideCount
......@@ -237,6 +238,7 @@ func (f *ObtainFile) Fail() {
}); err != nil {
g.Log().Async().Error(err)
}
g.Log().Async().Infof("Fail Notify Success!")
}
// 上传成功通知
......@@ -261,4 +263,5 @@ func (f *ObtainFile) Success(roomID int) {
}); err != nil {
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