feat: sign of file
This commit is contained in:
@ -33,17 +33,18 @@ func FsGet(c *gin.Context) {
|
||||
common.ErrorStrResp(c, "password is incorrect", 401)
|
||||
return
|
||||
}
|
||||
data, err := fs.Get(c, req.Path)
|
||||
obj, err := fs.Get(c, req.Path)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500, true)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, FsGetResp{
|
||||
ObjResp: ObjResp{
|
||||
Name: data.GetName(),
|
||||
Size: data.GetSize(),
|
||||
IsDir: data.IsDir(),
|
||||
Modified: data.ModTime(),
|
||||
Name: obj.GetName(),
|
||||
Size: obj.GetSize(),
|
||||
IsDir: obj.IsDir(),
|
||||
Modified: obj.ModTime(),
|
||||
Sign: Sign(obj),
|
||||
},
|
||||
// TODO: set raw url
|
||||
})
|
||||
|
@ -1,11 +1,11 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/setting"
|
||||
"github.com/alist-org/alist/v3/internal/sign"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -24,7 +24,7 @@ type ObjResp struct {
|
||||
Size int64 `json:"size"`
|
||||
IsDir bool `json:"is_dir"`
|
||||
Modified time.Time `json:"modified"`
|
||||
URL string `json:"url"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
type FsListResp struct {
|
||||
@ -99,9 +99,20 @@ func toObjResp(objs []model.Obj, path string, baseURL string) []ObjResp {
|
||||
Size: obj.GetSize(),
|
||||
IsDir: obj.IsDir(),
|
||||
Modified: obj.ModTime(),
|
||||
// TODO: sign url
|
||||
URL: fmt.Sprintf("%s/d%s", baseURL, stdpath.Join(path, obj.GetName())),
|
||||
Sign: Sign(obj),
|
||||
})
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func Sign(obj model.Obj) string {
|
||||
if obj.IsDir() {
|
||||
return ""
|
||||
}
|
||||
expire := setting.GetIntSetting("link_expiration", 0)
|
||||
if expire == 0 {
|
||||
return sign.NotExpired(obj.GetName())
|
||||
} else {
|
||||
return sign.WithDuration(obj.GetName(), time.Duration(expire)*time.Hour)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/alist-org/alist/v3/internal/conf"
|
||||
"github.com/alist-org/alist/v3/internal/db"
|
||||
"github.com/alist-org/alist/v3/internal/model"
|
||||
"github.com/alist-org/alist/v3/internal/sign"
|
||||
"github.com/alist-org/alist/v3/pkg/utils/random"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -17,6 +18,7 @@ func ResetToken(c *gin.Context) {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
sign.Instance()
|
||||
common.SuccessResp(c, token)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user