Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ppt_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Li Feifei
ppt_server
Commits
a9c2f290
Commit
a9c2f290
authored
Aug 17, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug
parent
58443297
Pipeline
#15960
passed with stages
in 33 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
50 deletions
+13
-50
file.go
app/model/file.go
+1
-1
http_client.go
library/http/http_client.go
+4
-40
file_notify.go
packed/file/file_notify.go
+4
-8
file_upload.go
packed/file/file_upload.go
+4
-1
No files found.
app/model/file.go
View file @
a9c2f290
...
...
@@ -23,7 +23,7 @@ type (
UploadFileInfo
struct
{
FileName
string
`json:"FileName"`
FileSize
int64
`json:"FileSize"`
PageCount
int
`j
ons
:"PageCount"`
PageCount
int
`j
son
:"PageCount"`
SlideCount
int
`json:"SlideCount"`
SheetCount
int
`json:"SheetCount"`
}
...
...
library/http/http_client.go
View file @
a9c2f290
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
(
"
\r
Downloading... %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
}
packed/file/file_notify.go
View file @
a9c2f290
...
...
@@ -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
)
}
packed/file/file_upload.go
View file @
a9c2f290
...
...
@@ -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!"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment