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
636114f1
Commit
636114f1
authored
Dec 02, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug
parent
548da8d6
Pipeline
#17129
passed with stages
in 34 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
17 deletions
+18
-17
file_upload.go
packed/file/file_upload.go
+18
-17
No files found.
packed/file/file_upload.go
View file @
636114f1
...
...
@@ -8,6 +8,7 @@ import (
"image"
"image/jpeg"
"image/png"
"io/ioutil"
"os"
"path"
"regexp"
...
...
@@ -17,7 +18,6 @@ import (
"ppt_server/library/http"
"ppt_server/library/oss"
"github.com/chai2010/webp"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
...
...
@@ -105,13 +105,20 @@ func (f *ObtainFile) taskJob(file *zip.File) ([]interface{}, error) {
defer
fd
.
Close
()
pictureBytes
,
_
:=
ioutil
.
ReadAll
(
fd
)
// 获取图片信息reader
imageReader
:=
ioutil
.
NopCloser
(
bytes
.
NewBuffer
(
pictureBytes
))
defer
imageReader
.
Close
()
// 上传图片reader
fileReader
:=
ioutil
.
NopCloser
(
bytes
.
NewBuffer
(
pictureBytes
))
defer
fileReader
.
Close
()
var
img
image
.
Image
fileSuffix
:=
path
.
Ext
(
file
.
Name
)
//获取文件后缀
switch
fileSuffix
{
case
".png"
:
img
,
err
=
png
.
Decode
(
fd
)
img
,
err
=
png
.
Decode
(
imageReader
)
case
".jpeg"
:
img
,
err
=
jpeg
.
Decode
(
fd
)
img
,
err
=
jpeg
.
Decode
(
imageReader
)
default
:
return
nil
,
gerror
.
New
(
"image ext is not found"
)
}
...
...
@@ -119,30 +126,24 @@ func (f *ObtainFile) taskJob(file *zip.File) ([]interface{}, error) {
return
nil
,
err
}
var
buf
bytes
.
Buffer
if
err
=
webp
.
Encode
(
&
buf
,
img
,
&
webp
.
Options
{
Lossless
:
true
});
err
!=
nil
{
return
nil
,
err
}
replaceName
:=
fmt
.
Sprintf
(
"%05s"
,
reFileNameCompile
.
ReplaceAllString
(
file
.
Name
,
"$1"
))
+
".webp"
replaceName
:=
fmt
.
Sprintf
(
"%05s"
,
reFileNameCompile
.
ReplaceAllString
(
file
.
Name
,
"$1"
))
+
fileSuffix
info
:=
img
.
Bounds
()
imageInfo
:=
[]
interface
{}{
replaceName
,
info
.
Max
.
X
,
info
.
Max
.
Y
}
return
imageInfo
,
oss
.
Upload
(
f
.
parser
.
splitUploadPath
()
+
"images/"
+
replaceName
,
bytes
.
NewReader
(
buf
.
Bytes
()))
return
imageInfo
,
oss
.
Upload
(
f
.
parser
.
splitUploadPath
()
+
"images/"
+
replaceName
,
fileReader
)
}
func
(
f
*
ObtainFile
)
task
(
file
*
zip
.
File
)
error
{
var
(
err
error
imageInfo
[]
interface
{}
)
func
(
f
*
ObtainFile
)
task
(
file
*
zip
.
File
)
(
err
error
)
{
for
i
:=
0
;
i
<
3
;
i
++
{
if
imageInfo
,
err
=
f
.
taskJob
(
file
);
err
==
nil
{
if
imageInfo
,
err
:
=
f
.
taskJob
(
file
);
err
==
nil
{
f
.
packed
.
ImageInfos
=
append
(
f
.
packed
.
ImageInfos
,
imageInfo
)
break
}
}
return
err
return
}
func
(
f
*
ObtainFile
)
uploadPicture
()
error
{
...
...
@@ -153,7 +154,7 @@ func (f *ObtainFile) uploadPicture() error {
}
defer
reader
.
Close
()
pool
:=
workpool
.
New
(
10
0
)
pool
:=
workpool
.
New
(
10
)
for
_
,
file
:=
range
reader
.
File
{
tempFile
:=
file
...
...
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