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
548da8d6
Commit
548da8d6
authored
Dec 02, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug
parent
f90a3497
Pipeline
#17128
passed with stages
in 1 minute 5 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
15 deletions
+14
-15
go.mod
go.mod
+1
-0
go.sum
go.sum
+3
-2
file_upload.go
packed/file/file_upload.go
+10
-13
No files found.
go.mod
View file @
548da8d6
...
...
@@ -4,6 +4,7 @@ go 1.16
require (
github.com/aliyun/aliyun-oss-go-sdk v2.1.9+incompatible // indirect
github.com/chai2010/webp v1.1.0
github.com/gogf/gf v1.16.4 // indirect
github.com/xxjwxc/gowp v0.0.0-20210520113007-57eb4693b12d // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
...
...
go.sum
View file @
548da8d6
...
...
@@ -18,6 +18,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chai2010/webp v1.1.0 h1:4Ei0/BRroMF9FaXDG2e4OxwFcuW2vcXd+A6tyqTJUQQ=
github.com/chai2010/webp v1.1.0/go.mod h1:LP12PG5IFmLGHUU26tBiCBKnghxx3toZFwDjOYvd3Ow=
github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28 h1:LdXxtjzvZYhhUaonAaAKArG3pyC67kGL3YY+6hGG8G4=
github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
...
...
@@ -282,4 +284,4 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gorm.io/driver/mysql v1.0.1/go.mod h1:KtqSthtg55lFp3S5kUXqlGaelnWpKitn4k1xZTnoiPw=
gorm.io/gorm v1.9.19/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
gorm.io/gorm v1.20.2/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
\ No newline at end of file
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
packed/file/file_upload.go
View file @
548da8d6
...
...
@@ -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"
...
...
@@ -45,7 +45,6 @@ const (
var
reFileNameCompile
,
_
=
regexp
.
Compile
(
`p([\d]+)[.].*`
)
var
reTokenPattern
=
`<meta name="csrf-token" content="([^"]+)">`
func
Upload
(
r
model
.
FileUploadRequest
,
errChan
chan
error
,
ok
chan
bool
)
(
file
*
ObtainFile
,
err
error
)
{
...
...
@@ -106,32 +105,30 @@ 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
(
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"
)
}
if
err
!=
nil
{
return
nil
,
err
}
replaceName
:=
fmt
.
Sprintf
(
"%05s"
,
reFileNameCompile
.
ReplaceAllString
(
file
.
Name
,
"$1"
))
+
fileSuffix
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"
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
.
NewReader
(
buf
.
Bytes
())
)
}
func
(
f
*
ObtainFile
)
task
(
file
*
zip
.
File
)
error
{
...
...
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