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
e4ed42da
Commit
e4ed42da
authored
Jul 20, 2021
by
a2231243
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code format
parent
81a1926b
Pipeline
#15532
failed with stages
in 11 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
23 deletions
+24
-23
middleware.go
middleware/middleware.go
+2
-4
file_parser.go
packed/file_parser.go
+5
-4
file_upload.go
packed/file_upload.go
+9
-8
notify.go
packed/notify.go
+2
-3
router.go
router/router.go
+6
-4
No files found.
middleware/middleware.go
View file @
e4ed42da
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
)
)
// Recover异常恢复
// Recover异常恢复
func
Middleware
Recover
(
r
*
ghttp
.
Request
)
{
func
Recover
(
r
*
ghttp
.
Request
)
{
r
.
Middleware
.
Next
()
r
.
Middleware
.
Next
()
if
err
:=
r
.
GetError
();
err
!=
nil
{
if
err
:=
r
.
GetError
();
err
!=
nil
{
r
.
Response
.
ClearBuffer
()
r
.
Response
.
ClearBuffer
()
...
@@ -18,19 +18,17 @@ func MiddlewareRecover(r *ghttp.Request) {
...
@@ -18,19 +18,17 @@ func MiddlewareRecover(r *ghttp.Request) {
"code"
:
http
.
StatusBadRequest
,
"code"
:
http
.
StatusBadRequest
,
"msg"
:
e
.
FirstString
(),
"msg"
:
e
.
FirstString
(),
})
})
default
:
default
:
_
=
r
.
Response
.
WriteJson
(
g
.
Map
{
_
=
r
.
Response
.
WriteJson
(
g
.
Map
{
"code"
:
http
.
StatusInternalServerError
,
"code"
:
http
.
StatusInternalServerError
,
"msg"
:
err
.
Error
(),
"msg"
:
err
.
Error
(),
})
})
}
}
}
}
}
}
// CORS跨域
// CORS跨域
func
Middleware
Cors
(
r
*
ghttp
.
Request
)
{
func
Cors
(
r
*
ghttp
.
Request
)
{
r
.
Response
.
CORSDefault
()
r
.
Response
.
CORSDefault
()
r
.
Middleware
.
Next
()
r
.
Middleware
.
Next
()
}
}
packed/file_parser.go
View file @
e4ed42da
package
packed
package
packed
import
(
import
(
"errors"
"fmt"
"fmt"
"github.com/gogf/gf/frame/g"
"mime"
"mime"
"net/url"
"net/url"
"path"
"path"
"strings"
"strings"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
)
)
type
file
struct
{
type
file
struct
{
...
@@ -34,8 +35,8 @@ func NewFile(ossFileLink, name string) (*file, error) {
...
@@ -34,8 +35,8 @@ func NewFile(ossFileLink, name string) (*file, error) {
slicePath
:=
strings
.
Split
(
strings
.
TrimLeft
(
dataPath
,
"/"
),
"/"
)
slicePath
:=
strings
.
Split
(
strings
.
TrimLeft
(
dataPath
,
"/"
),
"/"
)
if
len
(
slicePath
)
<
4
{
if
len
(
slicePath
)
<
4
{
g
.
Log
()
.
Async
()
.
Error
(
errors
.
New
(
"上传URL格式不正确"
))
g
.
Log
()
.
Async
()
.
Error
(
gerror
.
New
(
"上传URL格式不正确"
))
return
nil
,
errors
.
New
(
"上传URL格式不正确"
)
return
nil
,
gerror
.
New
(
"上传URL格式不正确"
)
}
}
f
:=
&
file
{
f
:=
&
file
{
ext
:
path
.
Ext
(
name
),
ext
:
path
.
Ext
(
name
),
...
...
packed/file_upload.go
View file @
e4ed42da
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"archive/zip"
"archive/zip"
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"errors"
"fmt"
"fmt"
"image"
"image"
"image/jpeg"
"image/jpeg"
...
@@ -18,15 +17,16 @@ import (
...
@@ -18,15 +17,16 @@ import (
"ppt_server/app/model"
"ppt_server/app/model"
"ppt_server/library"
"ppt_server/library"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/g"
"github.com/xxjwxc/gowp/workpool"
"github.com/xxjwxc/gowp/workpool"
)
)
// 解析URL返回基本信息
// 解析URL返回基本信息
type
ObtainFile
struct
{
type
ObtainFile
struct
{
r
*
model
.
FileUploadRequest
//客户端请求参数
r
*
model
.
FileUploadRequest
//
客户端请求参数
bucket
*
ossSdk
// oss上传bucket
bucket
*
ossSdk
// oss上传bucket
ok
chan
*
model
.
SuccessResponse
// 上传
传课件状态
ok
chan
*
model
.
SuccessResponse
// 上传
课件响应成功
err
chan
error
// 上传课件失败Error
err
chan
error
// 上传课件失败Error
fileSize
int64
// 课件大小
fileSize
int64
// 课件大小
pageCount
int
// 课件图片数量
pageCount
int
// 课件图片数量
...
@@ -72,6 +72,7 @@ func (f *ObtainFile) fileInfo() error {
...
@@ -72,6 +72,7 @@ func (f *ObtainFile) fileInfo() error {
}
}
var
fileInfo
model
.
UploadFileInfo
var
fileInfo
model
.
UploadFileInfo
if
err
:=
json
.
Unmarshal
(
fileBytes
,
&
fileInfo
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
fileBytes
,
&
fileInfo
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -115,10 +116,10 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) {
...
@@ -115,10 +116,10 @@ func (f *ObtainFile) job(file *zip.File) ([]interface{}, error) {
case
".jpeg"
:
case
".jpeg"
:
img
,
_
=
jpeg
.
Decode
(
imageReader
)
img
,
_
=
jpeg
.
Decode
(
imageReader
)
default
:
default
:
return
nil
,
errors
.
New
(
"image ext is not found"
)
return
nil
,
gerror
.
New
(
"image ext is not found"
)
}
}
if
img
==
nil
{
if
img
==
nil
{
return
nil
,
errors
.
New
(
"Image invalid"
)
return
nil
,
gerror
.
New
(
"Image invalid"
)
}
}
var
filenameOnly
string
var
filenameOnly
string
...
@@ -206,12 +207,14 @@ func (f *ObtainFile) Worker(err error) {
...
@@ -206,12 +207,14 @@ func (f *ObtainFile) Worker(err error) {
f
.
parserFile
.
dataPath
)
f
.
parserFile
.
dataPath
)
// 下载ZIP包
// 下载ZIP包
if
err
=
library
.
Download
(
downloadZipLink
,
f
.
parserFile
.
tempZipPath
);
err
!=
nil
{
if
err
=
library
.
Download
(
downloadZipLink
,
f
.
parserFile
.
tempZipPath
);
err
!=
nil
{
g
.
Log
()
.
Async
()
.
Error
(
err
)
g
.
Log
()
.
Async
()
.
Error
(
err
)
f
.
err
<-
err
f
.
err
<-
err
return
return
}
}
// 清理ZIP包
defer
os
.
Remove
(
f
.
parserFile
.
tempZipPath
)
g
.
Log
()
.
Async
()
.
Infof
(
"file: %s Zip Donwload Complete"
,
f
.
parserFile
.
name
)
g
.
Log
()
.
Async
()
.
Infof
(
"file: %s Zip Donwload Complete"
,
f
.
parserFile
.
name
)
// 解析ZIP包并上传图片到OSS
// 解析ZIP包并上传图片到OSS
...
@@ -230,8 +233,6 @@ func (f *ObtainFile) Worker(err error) {
...
@@ -230,8 +233,6 @@ func (f *ObtainFile) Worker(err error) {
}
}
g
.
Log
()
.
Async
()
.
Infof
(
"filename == %s upload success!"
,
f
.
parserFile
.
name
)
g
.
Log
()
.
Async
()
.
Infof
(
"filename == %s upload success!"
,
f
.
parserFile
.
name
)
// 清理zip包
_
=
os
.
Remove
(
f
.
parserFile
.
tempZipPath
)
res
:=
&
model
.
SuccessResponse
{
res
:=
&
model
.
SuccessResponse
{
Name
:
f
.
parserFile
.
name
,
Name
:
f
.
parserFile
.
name
,
...
...
packed/notify.go
View file @
e4ed42da
...
@@ -2,7 +2,6 @@ package packed
...
@@ -2,7 +2,6 @@ package packed
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
"io/ioutil"
"io/ioutil"
"net/http"
"net/http"
"net/http/cookiejar"
"net/http/cookiejar"
...
@@ -12,6 +11,7 @@ import (
...
@@ -12,6 +11,7 @@ import (
"ppt_server/app/model"
"ppt_server/app/model"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/util/gconv"
"github.com/gogf/gf/util/gconv"
)
)
...
@@ -50,7 +50,7 @@ func (n *Notfiy) post(url string, data g.Map) error {
...
@@ -50,7 +50,7 @@ func (n *Notfiy) post(url string, data g.Map) error {
}
}
if
login
.
Code
!=
200
{
if
login
.
Code
!=
200
{
return
errors
.
New
(
login
.
Msg
)
return
gerror
.
New
(
login
.
Msg
)
}
}
return
nil
return
nil
}
}
...
@@ -128,6 +128,5 @@ func (n *Notfiy) Fail(object *ObtainFile) {
...
@@ -128,6 +128,5 @@ func (n *Notfiy) Fail(object *ObtainFile) {
}
}
func
(
n
*
Notfiy
)
Success
(
res
*
model
.
SuccessResponse
)
{
func
(
n
*
Notfiy
)
Success
(
res
*
model
.
SuccessResponse
)
{
n
.
notify
(
"/web/room_files_add"
,
gconv
.
Map
(
res
))
n
.
notify
(
"/web/room_files_add"
,
gconv
.
Map
(
res
))
}
}
router/router.go
View file @
e4ed42da
...
@@ -12,12 +12,14 @@ func init() {
...
@@ -12,12 +12,14 @@ func init() {
s
:=
g
.
Server
()
s
:=
g
.
Server
()
s
.
Use
(
s
.
Use
(
middleware
.
Middleware
Cors
,
middleware
.
Cors
,
middleware
.
Middleware
Recover
,
middleware
.
Recover
,
)
)
s
.
Group
(
`file`
,
func
(
group
*
ghttp
.
RouterGroup
)
{
s
.
Group
(
`file`
,
func
(
group
*
ghttp
.
RouterGroup
)
{
group
.
GET
(
`/upload`
,
api
.
File
.
Index
)
group
.
ALL
(
`/`
,
api
.
File
,
"Index, Upload"
)
group
.
POST
(
`/upload`
,
api
.
File
.
Upload
)
//group.GET(`/upload`, api.File.Index)
//group.POST(`/upload`, api.File.Upload)
})
})
}
}
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