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
7e67b0b0
Commit
7e67b0b0
authored
May 14, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
5cacf84f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
75 deletions
+23
-75
upload.go
upload/upload.go
+23
-75
No files found.
upload/upload.go
View file @
7e67b0b0
...
...
@@ -10,6 +10,7 @@ import (
"github.com/astaxie/beego/orm"
"github.com/chai2010/webp"
"github.com/xxjwxc/gowp/workpool"
"github.com/rocketlaunchr/go-pool"
"image"
"image/jpeg"
"image/png"
...
...
@@ -35,9 +36,8 @@ import (
var
(
//WEBURL string = "http://offcn-live-svc"
WEBURL
string
=
"https://test-live.offcncloud.com"
client
*
http
.
Client
token
string
once
sync
.
Once
syncPool
pool
.
Pool
)
const
docUrl
string
=
"http://doc.offcncloud.com/"
...
...
@@ -45,40 +45,18 @@ const docUrl string = "http://doc.offcncloud.com/"
func
init
()
{
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
once
.
Do
(
func
()
{
log
.
SetFlags
(
log
.
Lshortfile
|
log
.
LstdFlags
)
syncPool
=
pool
.
New
(
10
)
})
}
//func main() {
//tick := time.NewTicker(30 * time.Minute)
//upload()
//for {
// select {
// case <-tick.C:
// upload()
// }
//}
//}
func
ptoken
()
{
qclient
,
qtoken
,
err
:=
webToken
()
client
=
qclient
token
=
qtoken
println
(
"token ==="
,
token
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
}
}
func
Upload
(
v
*
models
.
XyuSmallTempFiles
)
{
//ptoken()
go
Down
(
v
)
}
func
Down
(
v
*
models
.
XyuSmallTempFiles
)
{
...
...
@@ -88,14 +66,7 @@ func Down(v *models.XyuSmallTempFiles) {
filename
:=
path
.
Base
(
url
)
filePath
:=
"/data/files/"
+
filename
ext
:=
path
.
Ext
(
filename
)
//if strings.Contains(ext, "ppt") || strings.Contains(ext, "pptx") {
// p := &PPT{request:v}
// if err := p.Transform(); err != nil {
// beeLogger.Log.Errorf("PPT Error : %s", err)
// return
// }
// return
//}
objectName
:=
v
.
Url
[
strings
.
Index
(
v
.
Url
,
"com/"
)
+
4
:
]
// 文件以及存在就不需要下载
...
...
@@ -265,6 +236,9 @@ func Down(v *models.XyuSmallTempFiles) {
return
}
Pool
:=
workpool
.
New
(
10
)
syncPool
.
SetFactory
(
func
()
interface
{}
{
return
&
bytes
.
Buffer
{}
})
for
_
,
file
:=
range
reader
.
File
{
Pool
.
DoWait
(
func
()
error
{
log
.
Printf
(
"file = %s
\n
"
,
file
.
Name
)
...
...
@@ -276,36 +250,8 @@ func Down(v *models.XyuSmallTempFiles) {
}
return
err
})
//go func(file *zip.File) {
// defer debug.FreeOSMemory()
// err := pdfThumbnail(objectPath, file, bucket)
//
// if err != nil {
// fmt.Println(objectPath + file.Name + "上传失败")
// // 上传缩略图失败,重试3次
// for i := 0; i < 3; i++ {
// err = pdfThumbnail(objectPath, file, bucket)
// if err == nil {
// ch1 <- true
// return
// }
// }
// UpdateFileError("5", v.Uuid, v.RoomNum, objectName)
// ch1 <- false
// return
// } else {
// ch1 <- true
// return
// }
//
//}(file)
}
//for i := 0; i < int(wordFloat64); i++ {
// t := <-ch1
// if t {
// uploadImageCount++
// }
//}
}
err
=
Pool
.
Wait
()
if
err
!=
nil
{
UpdateFileError
(
"5"
,
v
.
Uuid
,
v
.
RoomNum
,
objectName
)
...
...
@@ -314,12 +260,7 @@ func Down(v *models.XyuSmallTempFiles) {
}
defer
reader
.
Close
()
//fmt.Println(uploadImageCount, wordFloat64)
//if uploadImageCount != wordFloat64 {
// UpdateFileError("5", v.Uuid, v.RoomNum, objectName)
// fmt.Println("上传失败")
// return
//}
go
func
()
{
err
:=
uploadPacked
(
bucket
,
filename
,
contentHash
,
objectPath
,
...
...
@@ -526,9 +467,15 @@ func pdfThumbnail(objectPath string, file *zip.File, bucket *oss.Bucket) error {
return
err
}
defer
fc
.
Close
()
item
:=
syncPool
.
Borrow
()
defer
item
.
Return
()
defer
debug
.
FreeOSMemory
()
buf
:=
item
.
Item
.
(
*
bytes
.
Buffer
)
//defer debug.FreeOSMemory()
var
img
image
.
Image
fileSuffix
:=
path
.
Ext
(
file
.
Name
)
//获取文件后缀
...
...
@@ -541,9 +488,10 @@ func pdfThumbnail(objectPath string, file *zip.File, bucket *oss.Bucket) error {
return
errors
.
New
(
"image ext is not found"
)
}
var
buf
bytes
.
Buffer
if
err
=
webp
.
Encode
(
&
buf
,
img
,
&
webp
.
Options
{
Lossless
:
true
});
err
!=
nil
{
//var buf bytes.Buffer
if
err
=
webp
.
Encode
(
buf
,
img
,
&
webp
.
Options
{
Lossless
:
true
});
err
!=
nil
{
return
err
}
r
:=
bytes
.
NewReader
(
buf
.
Bytes
())
...
...
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