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
Commits
b7ae5b4d
Commit
b7ae5b4d
authored
Dec 16, 2022
by
chenhan wang
Browse files
暂时去掉cookie,能够接收发送文件,但是尚未与数据库交互,链接未编码隐藏(本地路径)
parent
0f59208b
Changes
5
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
b7ae5b4d
config.yaml
backend/files
\ No newline at end of file
backend/files
.history/
\ No newline at end of file
.history/backend/app/middleware/login_20221216215609.go
0 → 100644
View file @
b7ae5b4d
package
middleware
import
(
"github.com/labstack/echo/v4"
//"http/net"
//"pastebin_backend/app/controller"
)
func
Auth
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
//c.Bind("User")
/*
cookie, _ := c.Cookie("user")
if cookie == nil {
err := controller.AskPasswd(c)
if err != nil {
return nil
}
}*/
//c.Set("uid", cookie.Value)
c
.
Set
(
"uid"
,
114514
)
return
next
(
c
)
}
}
/*
func CookieAuth(c echo.Context) error{
cookie, err := c.Cookie()
if err != nil {
return err
}
}*/
.history/backend/app/middleware/login_20221216223311.go
0 → 100644
View file @
b7ae5b4d
package
middleware
import
(
"github.com/labstack/echo/v4"
//"http/net"
//"pastebin_backend/app/controller"
)
func
Auth
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
//c.Bind("User")
/*
cookie, _ := c.Cookie("user")
if cookie == nil {
err := controller.AskPasswd(c)
if err != nil {
return nil
}
}*/
//c.Set("uid", cookie.Value)
c
.
Set
(
"uid"
,
114514
)
return
next
(
c
)
}
}
/*
func CookieAuth(c echo.Context) error{
cookie, err := c.Cookie()
if err != nil {
return err
}
}*/
backend/app/controller/interface.go
View file @
b7ae5b4d
...
...
@@ -4,10 +4,11 @@ import (
"net"
"net/http"
"pastebin_backend/app/response"
//"pastebin_backend/model"
//"error"
"github.com/labstack/echo/v4"
//"time"
//"encoding/json"
"fmt"
"io"
...
...
@@ -23,6 +24,7 @@ type File struct {
Expiration
int
`json:"expiration"`
User
string
`json:"user"`
Passwd
string
`json:"passwd"`
//Expiry time.Time `json:"expiry"` // 有效期
//Content string `json:"content"`
}
...
...
@@ -115,7 +117,11 @@ func RecvFile(c echo.Context) error {
}
filePath
:=
"./files/"
+
info
.
FileType
+
"/"
+
file
.
Filename
dst
,
err
:=
os
.
Create
(
filePath
)
//dst, err := os.Create(file.Filename)
// 获取文件大小
fi
,
_
:=
dst
.
Stat
()
if
fi
.
Size
()
>
8
*
1024
*
10224
{
c
.
HTML
(
http
.
StatusOK
,
fmt
.
Sprintf
(
"<p>文件上传失败: 文件大小超过8MB</p>"
))
}
if
err
!=
nil
{
fmt
.
Println
(
err
)
...
...
@@ -128,6 +134,18 @@ func RecvFile(c echo.Context) error {
return
err
}
// 更新数据库
/*
dinfo:=model.Users{
Username: info.User,
Passwd: info.Passwd,
Name:info.FileName,// 无后缀
Size: uint(fi.Size()),
Route:filePath,
//Time1: info.Expiry,
}*/
return
c
.
HTML
(
http
.
StatusOK
,
fmt
.
Sprintf
(
"<p>文件上传成功: %s</p>"
,
file
.
Filename
))
}
...
...
@@ -146,10 +164,16 @@ func SendFile(c echo.Context) error {
fmt
.
Println
(
err
)
return
err
}
fi
,
err
:=
src
.
Stat
()
if
err
!=
nil
{
return
err
}
defer
func
()
{
src
.
Close
()
}()
data
:=
make
([]
byte
,
8
*
1024
*
1024
)
data
:=
make
([]
byte
,
fi
.
Size
())
count
,
err
:=
src
.
Read
(
data
)
//return response.SendResponse(c, http.StatusOK, "", "pong!")
count
=
count
...
...
backend/app/middleware/login.go
View file @
b7ae5b4d
...
...
@@ -3,19 +3,20 @@ package middleware
import
(
"github.com/labstack/echo/v4"
//"http/net"
"pastebin_backend/app/controller"
//
"pastebin_backend/app/controller"
)
func
Auth
(
next
echo
.
HandlerFunc
)
echo
.
HandlerFunc
{
return
func
(
c
echo
.
Context
)
error
{
//c.Bind("User")
cookie
,
_
:=
c
.
Cookie
(
"user"
)
if
cookie
==
nil
{
err
:=
controller
.
AskPasswd
(
c
)
if
err
!=
nil
{
return
nil
}
}
/*
cookie, _ := c.Cookie("user")
if cookie == nil {
err := controller.AskPasswd(c)
if err != nil {
return nil
}
}*/
//c.Set("uid", cookie.Value)
c
.
Set
(
"uid"
,
114514
)
return
next
(
c
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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