Commit b7ae5b4d authored by chenhan wang's avatar chenhan wang
Browse files

暂时去掉cookie,能够接收发送文件,但是尚未与数据库交互,链接未编码隐藏(本地路径)

parent 0f59208b
config.yaml config.yaml
backend/files backend/files
.history/
\ No newline at end of file
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
}
}*/
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
}
}*/
...@@ -4,10 +4,11 @@ import ( ...@@ -4,10 +4,11 @@ import (
"net" "net"
"net/http" "net/http"
"pastebin_backend/app/response" "pastebin_backend/app/response"
//"pastebin_backend/model"
//"error" //"error"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
//"time"
//"encoding/json" //"encoding/json"
"fmt" "fmt"
"io" "io"
...@@ -23,6 +24,7 @@ type File struct { ...@@ -23,6 +24,7 @@ type File struct {
Expiration int `json:"expiration"` Expiration int `json:"expiration"`
User string `json:"user"` User string `json:"user"`
Passwd string `json:"passwd"` Passwd string `json:"passwd"`
//Expiry time.Time `json:"expiry"` // 有效期
//Content string `json:"content"` //Content string `json:"content"`
} }
...@@ -115,7 +117,11 @@ func RecvFile(c echo.Context) error { ...@@ -115,7 +117,11 @@ func RecvFile(c echo.Context) error {
} }
filePath := "./files/" + info.FileType + "/" + file.Filename filePath := "./files/" + info.FileType + "/" + file.Filename
dst, err := os.Create(filePath) 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 { if err != nil {
fmt.Println(err) fmt.Println(err)
...@@ -128,6 +134,18 @@ func RecvFile(c echo.Context) error { ...@@ -128,6 +134,18 @@ func RecvFile(c echo.Context) error {
return err 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)) return c.HTML(http.StatusOK, fmt.Sprintf("<p>文件上传成功: %s</p>", file.Filename))
} }
...@@ -146,10 +164,16 @@ func SendFile(c echo.Context) error { ...@@ -146,10 +164,16 @@ func SendFile(c echo.Context) error {
fmt.Println(err) fmt.Println(err)
return err return err
} }
fi,err:=src.Stat()
if err != nil{
return err
}
defer func() { defer func() {
src.Close() src.Close()
}() }()
data := make([]byte, 8*1024*1024)
data := make([]byte, fi.Size())
count, err := src.Read(data) count, err := src.Read(data)
//return response.SendResponse(c, http.StatusOK, "", "pong!") //return response.SendResponse(c, http.StatusOK, "", "pong!")
count = count count = count
......
...@@ -3,19 +3,20 @@ package middleware ...@@ -3,19 +3,20 @@ package middleware
import ( import (
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
//"http/net" //"http/net"
"pastebin_backend/app/controller" //"pastebin_backend/app/controller"
) )
func Auth(next echo.HandlerFunc) echo.HandlerFunc { func Auth(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
//c.Bind("User") //c.Bind("User")
/*
cookie, _ := c.Cookie("user") cookie, _ := c.Cookie("user")
if cookie == nil { if cookie == nil {
err := controller.AskPasswd(c) err := controller.AskPasswd(c)
if err != nil { if err != nil {
return nil return nil
} }
} }*/
//c.Set("uid", cookie.Value) //c.Set("uid", cookie.Value)
c.Set("uid", 114514) c.Set("uid", 114514)
return next(c) return next(c)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment