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
7f5bb56c
Commit
7f5bb56c
authored
Dec 03, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug
parent
636114f1
Pipeline
#17149
passed with stages
in 1 minute 4 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
18 deletions
+10
-18
file_upload.go
packed/file/file_upload.go
+10
-18
No files found.
packed/file/file_upload.go
View file @
7f5bb56c
...
...
@@ -8,7 +8,6 @@ import (
"image"
"image/jpeg"
"image/png"
"io/ioutil"
"os"
"path"
"regexp"
...
...
@@ -18,6 +17,7 @@ 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"
...
...
@@ -74,8 +74,6 @@ 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
...
...
@@ -102,23 +100,15 @@ func (f *ObtainFile) taskJob(file *zip.File) ([]interface{}, error) {
if
err
!=
nil
{
return
nil
,
err
}
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
(
imageReader
)
img
,
err
=
png
.
Decode
(
fd
)
case
".jpeg"
:
img
,
err
=
jpeg
.
Decode
(
imageReader
)
img
,
err
=
jpeg
.
Decode
(
fd
)
default
:
return
nil
,
gerror
.
New
(
"image ext is not found"
)
}
...
...
@@ -126,13 +116,16 @@ func (f *ObtainFile) taskJob(file *zip.File) ([]interface{}, error) {
return
nil
,
err
}
replaceName
:=
fmt
.
Sprintf
(
"%05s"
,
reFileNameCompile
.
ReplaceAllString
(
file
.
Name
,
"$1"
))
+
fileSuffix
replaceName
:=
fmt
.
Sprintf
(
"%05s"
,
reFileNameCompile
.
ReplaceAllString
(
file
.
Name
,
"$1"
))
+
".webp"
var
buf
bytes
.
Buffer
if
err
:=
webp
.
Encode
(
&
buf
,
img
,
&
webp
.
Options
{
Lossless
:
true
});
err
!=
nil
{
return
nil
,
err
}
info
:=
img
.
Bounds
()
imageInfo
:=
[]
interface
{}{
replaceName
,
info
.
Max
.
X
,
info
.
Max
.
Y
}
return
imageInfo
,
oss
.
Upload
(
f
.
parser
.
splitUploadPath
()
+
"images/"
+
replaceName
,
fileReader
)
return
imageInfo
,
oss
.
Upload
(
f
.
parser
.
splitUploadPath
()
+
"images/"
+
replaceName
,
bytes
.
NewBuffer
(
buf
.
Bytes
()))
}
func
(
f
*
ObtainFile
)
task
(
file
*
zip
.
File
)
(
err
error
)
{
...
...
@@ -153,7 +146,6 @@ func (f *ObtainFile) uploadPicture() error {
return
err
}
defer
reader
.
Close
()
pool
:=
workpool
.
New
(
10
)
for
_
,
file
:=
range
reader
.
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