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

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

parent 0f59208b
config.yaml
backend/files
\ No newline at end of file
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 (
"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
......
......@@ -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)
......
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