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
29ab7969
Commit
29ab7969
authored
Dec 01, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:webp: 解析转换图片为webp
parent
f90a3497
Pipeline
#17114
failed with stages
in 4 seconds
Changes
4
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
27 deletions
+24
-27
go.mod
go.mod
+10
-3
go.sum
go.sum
+0
-0
file_parser.go
packed/file/file_parser.go
+2
-2
file_upload.go
packed/file/file_upload.go
+12
-22
No files found.
go.mod
View file @
29ab7969
...
@@ -3,8 +3,15 @@ module ppt_server
...
@@ -3,8 +3,15 @@ module ppt_server
go 1.16
go 1.16
require (
require (
github.com/aliyun/aliyun-oss-go-sdk v2.1.9+incompatible // indirect
github.com/aliyun/aliyun-oss-go-sdk v2.1.9+incompatible
github.com/gogf/gf v1.16.4 // indirect
github.com/baiyubin/aliyun-sts-go-sdk v0.0.0-20180326062324-cfa1a18b161f // indirect
github.com/xxjwxc/gowp v0.0.0-20210520113007-57eb4693b12d // indirect
github.com/chai2010/webp v1.1.0
github.com/gogf/gf v1.16.6
github.com/gogf/mysql v1.6.1-0.20210603073548-16164ae25579 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/satori/go.uuid v1.2.0 // indirect
github.com/xxjwxc/gowp v0.0.0-20210520113007-57eb4693b12d
gitlab.eoffcn.com/cloud/goforest v0.3.4 // indirect
go.opentelemetry.io/otel/metric v0.19.0 // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
)
)
go.sum
View file @
29ab7969
This diff is collapsed.
Click to expand it.
packed/file/file_parser.go
View file @
29ab7969
...
@@ -3,11 +3,11 @@ package file
...
@@ -3,11 +3,11 @@ package file
import
(
import
(
"fmt"
"fmt"
"mime"
"mime"
"net/http"
"path"
"path"
"strings"
"strings"
"github.com/gogf/gf/encoding/gurl"
"github.com/gogf/gf/encoding/gurl"
"github.com/gogf/gf/errors/gcode"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/text/gstr"
"github.com/gogf/gf/text/gstr"
...
@@ -32,7 +32,7 @@ func parseURL(ossFileLink string) (*parser, error) {
...
@@ -32,7 +32,7 @@ func parseURL(ossFileLink string) (*parser, error) {
slicePath
:=
gstr
.
SplitAndTrim
(
parseURLPath
[
"path"
],
"/"
,
"/"
)
slicePath
:=
gstr
.
SplitAndTrim
(
parseURLPath
[
"path"
],
"/"
,
"/"
)
if
len
(
slicePath
)
<
4
{
if
len
(
slicePath
)
<
4
{
return
nil
,
gerror
.
NewCode
(
http
.
StatusBa
dRequest
,
"上传URL格式不正确"
)
return
nil
,
gerror
.
NewCode
(
gcode
.
CodeInvali
dRequest
,
"上传URL格式不正确"
)
}
}
f
:=
&
parser
{
f
:=
&
parser
{
ext
:
path
.
Ext
(
ossFileLink
),
ext
:
path
.
Ext
(
ossFileLink
),
...
...
packed/file/file_upload.go
View file @
29ab7969
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"image"
"image"
"image/jpeg"
"image/jpeg"
"image/png"
"image/png"
"io/ioutil"
"os"
"os"
"path"
"path"
"regexp"
"regexp"
...
@@ -18,6 +17,7 @@ import (
...
@@ -18,6 +17,7 @@ import (
"ppt_server/library/http"
"ppt_server/library/http"
"ppt_server/library/oss"
"ppt_server/library/oss"
"github.com/chai2010/webp"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/os/gtime"
...
@@ -45,7 +45,6 @@ const (
...
@@ -45,7 +45,6 @@ const (
var
reFileNameCompile
,
_
=
regexp
.
Compile
(
`p([\d]+)[.].*`
)
var
reFileNameCompile
,
_
=
regexp
.
Compile
(
`p([\d]+)[.].*`
)
var
reTokenPattern
=
`<meta name="csrf-token" content="([^"]+)">`
var
reTokenPattern
=
`<meta name="csrf-token" content="([^"]+)">`
func
Upload
(
r
model
.
FileUploadRequest
,
errChan
chan
error
,
func
Upload
(
r
model
.
FileUploadRequest
,
errChan
chan
error
,
ok
chan
bool
)
(
file
*
ObtainFile
,
err
error
)
{
ok
chan
bool
)
(
file
*
ObtainFile
,
err
error
)
{
...
@@ -103,49 +102,40 @@ func (f *ObtainFile) taskJob(file *zip.File) ([]interface{}, error) {
...
@@ -103,49 +102,40 @@ func (f *ObtainFile) taskJob(file *zip.File) ([]interface{}, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defer
fd
.
Close
()
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
var
img
image
.
Image
fileSuffix
:=
path
.
Ext
(
file
.
Name
)
//获取文件后缀
fileSuffix
:=
path
.
Ext
(
file
.
Name
)
//获取文件后缀
switch
fileSuffix
{
switch
fileSuffix
{
case
".png"
:
case
".png"
:
img
,
err
=
png
.
Decode
(
imageReader
)
img
,
err
=
png
.
Decode
(
fd
)
case
".jpeg"
:
case
".jpeg"
:
img
,
err
=
jpeg
.
Decode
(
imageReader
)
img
,
err
=
jpeg
.
Decode
(
fd
)
default
:
default
:
return
nil
,
gerror
.
New
(
"image ext is not found"
)
return
nil
,
gerror
.
New
(
"image ext is not found"
)
}
}
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
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
()
info
:=
img
.
Bounds
()
imageInfo
:=
[]
interface
{}{
replaceName
,
info
.
Max
.
X
,
info
.
Max
.
Y
}
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
{
func
(
f
*
ObtainFile
)
task
(
file
*
zip
.
File
)
(
err
error
)
{
var
(
err
error
imageInfo
[]
interface
{}
)
for
i
:=
0
;
i
<
3
;
i
++
{
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
)
f
.
packed
.
ImageInfos
=
append
(
f
.
packed
.
ImageInfos
,
imageInfo
)
break
break
}
}
}
}
return
err
return
}
}
func
(
f
*
ObtainFile
)
uploadPicture
()
error
{
func
(
f
*
ObtainFile
)
uploadPicture
()
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