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
ccc072cf
Commit
ccc072cf
authored
Aug 17, 2021
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
format code
parent
a9c2f290
Pipeline
#15962
passed with stages
in 34 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
43 deletions
+47
-43
file.go
app/api/file.go
+1
-1
boot.go
boot/boot.go
+15
-11
file_notify.go
packed/file/file_notify.go
+15
-16
file_parser.go
packed/file/file_parser.go
+1
-1
file_upload.go
packed/file/file_upload.go
+15
-14
No files found.
app/api/file.go
View file @
ccc072cf
...
@@ -38,7 +38,7 @@ func (f *fileApi) Upload(r *ghttp.Request) {
...
@@ -38,7 +38,7 @@ func (f *fileApi) Upload(r *ghttp.Request) {
response
.
Fail
(
r
,
err
)
response
.
Fail
(
r
,
err
)
}
}
// 检测课件格式
// 检测课件格式
parserFile
,
err
:=
file
.
Upload
(
&
req
,
service
.
File
.
Done
,
service
.
File
.
Ok
)
parserFile
,
err
:=
file
.
Upload
(
req
,
service
.
File
.
Done
,
service
.
File
.
Ok
)
if
err
!=
nil
{
if
err
!=
nil
{
response
.
Fail
(
r
,
err
)
response
.
Fail
(
r
,
err
)
}
}
...
...
boot/boot.go
View file @
ccc072cf
package
boot
package
boot
import
(
import
(
"fmt"
"os"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/net/ghttp"
"os"
)
)
func
init
()
{
func
init
()
{
gdb
.
SetConfig
(
gdb
.
Config
{
link
:=
fmt
.
Sprintf
(
"mysql:%s:%s@tcp(%s:3306)/xyu"
,
"default"
:
gdb
.
ConfigGroup
{
os
.
Getenv
(
"read_user"
),
gdb
.
ConfigNode
{
os
.
Getenv
(
"read_pass"
),
Host
:
os
.
Getenv
(
"read_sql"
),
os
.
Getenv
(
"read_sql"
))
Port
:
"3306"
,
_
=
g
.
Config
()
.
Set
(
"database.link"
,
link
)
User
:
os
.
Getenv
(
"read_user"
),
Pass
:
os
.
Getenv
(
"read_pass"
),
Type
:
"mysql"
,
Charset
:
"utf8mb4"
,
},
},
})
g
.
Server
()
.
SetNameToUriType
(
ghttp
.
URI_TYPE_CAMEL
)
g
.
Server
()
.
SetNameToUriType
(
ghttp
.
URI_TYPE_CAMEL
)
g
.
Log
()
.
SetAsync
(
true
)
g
.
Log
()
.
SetAsync
(
true
)
...
...
packed/file/file_notify.go
View file @
ccc072cf
...
@@ -2,10 +2,11 @@ package file
...
@@ -2,10 +2,11 @@ package file
import
(
import
(
"encoding/json"
"encoding/json"
"net/http"
"os"
"os"
"ppt_server/app/model"
"ppt_server/app/model"
"ppt_server/library/http"
pHttp
"ppt_server/library/http"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/frame/g"
...
@@ -16,38 +17,36 @@ type notify struct {
...
@@ -16,38 +17,36 @@ type notify struct {
name
string
name
string
password
string
password
string
url
string
url
string
client
*
h
ttp
.
SessionHttpClient
client
*
pH
ttp
.
SessionHttpClient
}
}
func
newNotify
()
*
notify
{
var
n
=
notify
{
return
&
notify
{
url
:
g
.
Cfg
()
.
GetString
(
"notify.url"
),
url
:
g
.
Cfg
()
.
GetString
(
"notify.url"
),
name
:
os
.
Getenv
(
"live_name"
),
name
:
os
.
Getenv
(
"live_name"
),
password
:
os
.
Getenv
(
"live_pwd"
),
password
:
os
.
Getenv
(
"live_pwd"
),
client
:
pHttp
.
NewSessionHttpClient
(),
client
:
http
.
NewSessionHttpClient
(),
}
}
}
//回调验权
//回调验权
func
(
n
*
notify
)
verify
(
url
string
,
data
g
.
Map
)
error
{
func
(
n
notify
)
verify
(
url
string
,
data
g
.
Map
)
error
{
res
,
err
:=
n
.
client
.
Post
(
url
,
data
)
res
,
err
:=
n
.
client
.
Post
(
url
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
g
.
Log
()
.
Async
()
.
Infof
(
"url: %s, res: %s"
,
url
,
string
(
res
))
g
.
Log
()
.
Async
()
.
Infof
(
"url: %s, res: %s"
,
url
,
string
(
res
))
var
notifyResponse
model
.
NotifyResponse
var
notifyResponse
model
.
NotifyResponse
if
err
=
json
.
Unmarshal
(
res
,
&
notifyResponse
);
err
!=
nil
{
if
err
=
json
.
Unmarshal
(
res
,
&
notifyResponse
);
err
!=
nil
{
return
err
return
err
}
}
if
notifyResponse
.
Code
!=
200
{
if
notifyResponse
.
Code
!=
http
.
StatusOK
{
return
gerror
.
New
(
notifyResponse
.
Msg
)
return
gerror
.
New
(
notifyResponse
.
Msg
)
}
}
return
nil
return
nil
}
}
// 登录
// 登录
func
(
n
*
notify
)
auth
(
data
g
.
Map
)
error
{
func
(
n
notify
)
auth
(
data
g
.
Map
)
error
{
if
err
:=
n
.
verify
(
n
.
url
+
"/web/login"
,
g
.
Map
{
if
err
:=
n
.
verify
(
n
.
url
+
"/web/login"
,
g
.
Map
{
"name"
:
n
.
name
,
"name"
:
n
.
name
,
...
@@ -61,16 +60,16 @@ func (n *notify) auth(data g.Map) error {
...
@@ -61,16 +60,16 @@ func (n *notify) auth(data g.Map) error {
return
err
return
err
}
}
buf
,
_
:=
gregex
.
Match
(
`<meta name="csrf-token" content="([^"]+)">`
,
bufferBytes
)
buf
,
_
:=
gregex
.
Match
(
reTokenPattern
,
bufferBytes
)
data
[
"_token"
]
=
string
(
buf
[
1
])
data
[
"_token"
]
=
string
(
buf
[
1
])
return
nil
return
nil
}
}
// 发送通知
// 发送通知
func
(
n
*
notify
)
notice
(
path
string
,
data
g
.
Map
)
error
{
func
(
n
notify
)
notice
(
path
string
,
data
g
.
Map
)
error
{
if
err
:=
n
.
auth
(
data
);
err
!=
nil
{
if
err
:=
n
.
auth
(
data
);
err
!=
nil
{
return
err
return
err
}
}
return
n
.
verify
(
n
.
url
+
path
,
data
)
return
n
.
verify
(
n
.
url
+
path
,
data
)
}
}
packed/file/file_parser.go
View file @
ccc072cf
...
@@ -78,7 +78,7 @@ func (f *parser) contentHash() string {
...
@@ -78,7 +78,7 @@ func (f *parser) contentHash() string {
// 数据库存储path
// 数据库存储path
func
(
f
*
parser
)
dataPath
()
string
{
func
(
f
*
parser
)
dataPath
()
string
{
return
f
.
splitUploadPath
()
+
gurl
.
Encode
(
f
.
slicePath
[
len
(
f
.
slicePath
)
-
1
:
][
0
])
return
f
.
splitUploadPath
()
+
gurl
.
Encode
(
f
.
slicePath
[
len
(
f
.
slicePath
)
-
1
:
][
0
])
}
}
// 解析doctype
// 解析doctype
...
...
packed/file/file_upload.go
View file @
ccc072cf
...
@@ -26,14 +26,14 @@ import (
...
@@ -26,14 +26,14 @@ import (
// 解析URL返回基本信息
// 解析URL返回基本信息
type
ObtainFile
struct
{
type
ObtainFile
struct
{
R
*
model
.
FileUploadRequest
// 客户端请求参数
R
model
.
FileUploadRequest
// 客户端请求参数
ok
chan
bool
// 上传课件响应成功
ok
chan
bool
// 上传课件响应成功
err
chan
error
// 上传课件失败Error
err
chan
error
// 上传课件失败Error
fileSize
int64
// 课件大小
fileSize
int64
// 课件大小
pageCount
int
// 课件图片数量
pageCount
int
// 课件图片数量
parser
*
parser
// 课件对象
parser
*
parser
// 课件对象
n
*
notify
// 事件通知
n
notify
// 事件通知
packed
*
model
.
Packed
// packed.json
packed
*
model
.
Packed
// packed.json
}
}
const
(
const
(
...
@@ -43,9 +43,10 @@ const (
...
@@ -43,9 +43,10 @@ const (
)
)
var
reFileNameCompile
,
_
=
regexp
.
Compile
(
`p([\d]+)[.].*`
)
var
reFileNameCompile
,
_
=
regexp
.
Compile
(
`p([\d]+)[.].*`
)
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
)
{
f
,
err
:=
parseURL
(
r
.
Url
)
f
,
err
:=
parseURL
(
r
.
Url
)
...
@@ -63,7 +64,7 @@ func Upload(r *model.FileUploadRequest, errChan chan error,
...
@@ -63,7 +64,7 @@ func Upload(r *model.FileUploadRequest, errChan chan error,
Hash
:
f
.
contentHash
(),
Hash
:
f
.
contentHash
(),
OssImagesPath
:
f
.
splitUploadPath
()
+
"images/"
,
OssImagesPath
:
f
.
splitUploadPath
()
+
"images/"
,
},
},
n
:
n
ewNotify
()
,
n
:
n
,
}
}
return
file
,
nil
return
file
,
nil
}
}
...
@@ -167,18 +168,18 @@ func (f *ObtainFile) uploadPicture() error {
...
@@ -167,18 +168,18 @@ func (f *ObtainFile) uploadPicture() error {
// 上传packed.json
// 上传packed.json
func
(
f
*
ObtainFile
)
uploadPacked
()
error
{
func
(
f
*
ObtainFile
)
uploadPacked
()
error
{
for
i
:=
1
;
i
<=
f
.
pageCount
;
i
++
{
for
i
:=
1
;
i
<=
f
.
pageCount
;
i
++
{
f
.
packed
.
ImagesName
=
append
(
f
.
packed
.
ImagesName
,
fmt
.
Sprintf
(
"%05d"
,
i
)
+
".png"
)
f
.
packed
.
ImagesName
=
append
(
f
.
packed
.
ImagesName
,
fmt
.
Sprintf
(
"%05d"
,
i
)
+
".png"
)
}
}
packedBytes
,
err
:=
json
.
Marshal
(
f
.
packed
)
packedBytes
,
err
:=
json
.
Marshal
(
f
.
packed
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
oss
.
Upload
(
f
.
parser
.
splitUploadPath
()
+
"packed.json"
,
bytes
.
NewReader
(
packedBytes
))
return
oss
.
Upload
(
f
.
parser
.
splitUploadPath
()
+
"packed.json"
,
bytes
.
NewReader
(
packedBytes
))
}
}
// 拼接下载zip包地址
// 拼接下载zip包地址
func
(
f
*
ObtainFile
)
splitDownloadLink
()
string
{
func
(
f
*
ObtainFile
)
splitDownloadLink
()
string
{
return
fmt
.
Sprintf
(
"%s?info=1&words=%v&ssl=1&furl=%s/%s"
,
return
fmt
.
Sprintf
(
"%s?info=1&words=%v&ssl=1&furl=%s/%s"
,
parserFileLink
,
f
.
pageCount
,
g
.
Cfg
()
.
GetString
(
"oss.url"
),
parserFileLink
,
f
.
pageCount
,
g
.
Cfg
()
.
GetString
(
"oss.url"
),
f
.
parser
.
dataPath
())
f
.
parser
.
dataPath
())
}
}
...
@@ -259,7 +260,7 @@ func (f *ObtainFile) Success(roomID int) {
...
@@ -259,7 +260,7 @@ func (f *ObtainFile) Success(roomID int) {
"nickname"
:
f
.
R
.
NickName
,
"nickname"
:
f
.
R
.
NickName
,
"uuid"
:
f
.
R
.
Uuid
,
"uuid"
:
f
.
R
.
Uuid
,
"room_id"
:
roomID
,
"room_id"
:
roomID
,
"is_courseware"
:
1
,
"is_courseware"
:
1
,
});
err
!=
nil
{
});
err
!=
nil
{
g
.
Log
()
.
Async
()
.
Error
(
err
)
g
.
Log
()
.
Async
()
.
Error
(
err
)
}
}
...
...
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