Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenhan wang
pastebin
Compare Revisions
1898bea4bf57165424912f2de15d801d77bf132b...b1dc3c4505664a686cfcc3a6d45226bcc5be1535
Commits (2)
fix:the wrong route path spelling
· 48db6746
chenhan wang
authored
Feb 14, 2023
48db6746
fix:response format fixed
· b1dc3c45
chenhan wang
authored
Feb 26, 2023
b1dc3c45
Hide whitespace changes
Inline
Side-by-side
backend/app/controller/foo.go
View file @
b1dc3c45
...
...
@@ -2,6 +2,8 @@ package controller
import
(
"backend/model"
"bytes"
"encoding/json"
"io"
"math/rand"
"mime/multipart"
...
...
@@ -163,7 +165,7 @@ func DBupdate(c echo.Context, info *Upload) (string, string) {
//num,_=strconv.ParseUint(GetSetting("maxDefaultAccess"), 10, 64)
info
.
MaxView
=
uint
(
Settings
.
MaxDefaultView
)
// 设置最大默认可访问次数
}
//
model.Savetext(info.Content, info.MaxView, info.Passwd, info.Expiration, url, info.Type, info.Name,info.HighLight)
model
.
Savetext
(
info
.
Content
,
info
.
MaxView
,
info
.
Passwd
,
info
.
Expiration
,
url
,
info
.
Type
,
info
.
Name
,
info
.
HighLight
)
return
sid
,
url
}
...
...
@@ -236,3 +238,13 @@ func TypeComplement(typ string) string {
}
return
typ
}
func
myMarshal
(
data
interface
{})
(
string
,
error
)
{
bf
:=
bytes
.
NewBuffer
([]
byte
{})
jsonEncoder
:=
json
.
NewEncoder
(
bf
)
jsonEncoder
.
SetEscapeHTML
(
false
)
if
err
:=
jsonEncoder
.
Encode
(
data
);
err
!=
nil
{
return
""
,
err
}
return
bf
.
String
(),
nil
}
backend/app/controller/handler.go
View file @
b1dc3c45
...
...
@@ -3,7 +3,6 @@ package controller
import
(
"backend/app/response"
"backend/model"
"encoding/json"
"net/http"
"time"
...
...
@@ -74,13 +73,13 @@ func FileUp(c echo.Context) error {
// 更新数据库
_
,
data
.
Url
=
DBupdate
(
c
,
info
)
// 不分配uid
data
.
Name
=
info
.
Name
dataj
,
err
:=
json
.
Marshal
(
data
)
dataj
,
err
:=
my
Marshal
(
data
)
if
err
!=
nil
{
logrus
.
Println
(
err
)
return
err
}
//return response.SendResponse2(c, http.StatusOK, "文件上传成功", info.TextName, GetTextContentType(info.TextType), url)
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
"文件上传成功"
,
string
(
dataj
)
)
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
"文件上传成功"
,
dataj
)
}
/*
...
...
@@ -104,6 +103,8 @@ func Down(c echo.Context) error {
SetCookie
(
c
,
cookie
,
IdGen
(
8
),
1800
,
time
.
Time
{})
}
c
.
SetParamNames
(
"url"
)
c
.
SetParamValues
(
info
.
Url
)
// 鉴权
stat
:=
Autheticate
(
cookie
,
info
.
Url
,
info
.
Passwd
,
time
.
Now
()
.
Add
(
1800
))
// 包含创建链接Createlink
// response
...
...
@@ -113,12 +114,11 @@ func Down(c echo.Context) error {
return
response
.
SendResponse
(
c
,
http
.
StatusForbidden
,
cookieMsg
+
"error:密码错误"
,
""
)
//403
case
1
:
// 鉴权通过
Data
:=
new
(
Msg
)
Data
.
Content
=
model
.
Find1
(
info
.
Url
,
"content"
)
// 文件内容
Data
.
Type
=
model
.
Find1
(
info
.
Url
,
"TextType"
)
// 文件类型
Data
.
Type
=
GetFileContentType
(
Data
.
Type
)
Data
.
Content
=
model
.
Find1
(
info
.
Url
,
"content"
)
// 文件内容
Data
.
Type
=
GetFileContentType
(
model
.
Find1
(
info
.
Url
,
"TextType"
))
// 文件类型
Data
.
Name
=
model
.
Find1
(
info
.
Url
,
"TextName"
)
dataj
,
_
:=
json
.
Marshal
(
Data
)
// 文件名
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
cookieMsg
+
"success"
,
string
(
dataj
)
)
// 返回数据
dataj
,
_
:=
my
Marshal
(
Data
)
// 文件名
return
response
.
SendResponse
(
c
,
http
.
StatusOK
,
cookieMsg
+
"success"
,
dataj
)
// 返回数据
case
2
:
return
response
.
SendResponse
(
c
,
http
.
StatusGone
,
cookieMsg
+
"error:内容过期"
,
""
)
//410
case
3
:
...
...
backend/app/routes.go
View file @
b1dc3c45
...
...
@@ -30,7 +30,7 @@ func addRoutes() {
* 若文件没设密码则不带密码也可访问
* 状态码: 403:密码错误; 410:内容过期; 200:访问成功; 401:请进行身份验证(输密码)
*/
api
.
POST
(
"/file/downl
a
od"
,
controller
.
Down
)
api
.
POST
(
"/file/downlo
a
d"
,
controller
.
Down
)
api
.
POST
(
"text/upload"
,
controller
.
TextUp
)
api
.
POST
(
"text/download"
,
controller
.
Down
)
}
...
...