Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
更新1.0.18bug
Browse files Browse the repository at this point in the history
添加检查token是否过期参数
  • Loading branch information
LinkLeong committed Nov 21, 2021
1 parent 1dff7ba commit f800f47
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ echo "your refreshToken" > /path/to/save/refreshToken
是否显示日志,默认不显示
-V
查看版本号
-crt
检查refreshToken是否过期


```

Expand Down
22 changes: 18 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go-aliyun-webdav/aliyun/cache"
"go-aliyun-webdav/aliyun/model"
"go-aliyun-webdav/webdav"
"reflect"

//"gorm.io/driver/sqlite"
//"gorm.io/gorm"
Expand All @@ -22,7 +23,7 @@ func init() {
cache.Init()
}

var Version = "v1.0.18"
var Version = "v1.0.19"

type Task struct {
Id string `json:"id"`
Expand All @@ -37,21 +38,36 @@ func main() {
var pwd *string
var versin *bool
var log *bool
var check *string
//
port = flag.String("port", "8085", "默认8085")
path = flag.String("path", "./", "")
user = flag.String("user", "admin", "用户名")
pwd = flag.String("pwd", "123456", "密码")
versin = flag.Bool("V", false, "显示版本")
log = flag.Bool("v", false, "是否显示日志(默认不显示)")
//refreshToken = flag.String("rt", "155f8c031dcb437a8f7c32a1ae63b60e", "refresh_token")
//log = flag.Bool("v", true, "是否显示日志(默认不显示)")
refreshToken = flag.String("rt", "", "refresh_token")

check = flag.String("crt", "", "检查refreshToken是否过期")

flag.Parse()
if *versin {
fmt.Println(Version)
return
}

if len(*check) > 0 {
refreshResult := aliyun.RefreshToken(*check)
if reflect.DeepEqual(refreshResult, model.RefreshTokenModel{}) {

fmt.Println("refreshToken已过期")
} else {
fmt.Println("refreshToken可以使用")
}
return
}

if len(*refreshToken) == 0 {
fmt.Println("rt为必填项,请输入refreshToken")
return
Expand All @@ -66,8 +82,6 @@ func main() {

address = "0.0.0.0:" + *port
}

//todo 判断
refreshResult := aliyun.RefreshToken(*refreshToken)

config := model.Config{
Expand Down
21 changes: 15 additions & 6 deletions webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,14 +734,18 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
var list model.FileListModel
var fi model.ListModel
fmt.Println(reqPath)
if strings.Contains(reqPath, "1111") {
fmt.Println("dddd")
}
var unfindListErr error
if len(reqPath) > 0 && strings.HasSuffix(reqPath, "/") {
dirName := strings.TrimRight(reqPath, "/")
dirName = strings.TrimLeft(dirName, "/")
list, err = aliyun.GetList(h.Config.Token, h.Config.DriveId, "")

strArr := strings.Split(dirName, "/")
fi, _ = findUrl(strArr, h.Config.Token, h.Config.DriveId, list)
list, _ = findList(strArr, h.Config.Token, h.Config.DriveId)
list, unfindListErr = findList(strArr, h.Config.Token, h.Config.DriveId)

} else if len(reqPath) == 0 {
list, err = aliyun.GetList(h.Config.Token, h.Config.DriveId, "")
Expand All @@ -760,7 +764,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status
ctx := r.Context()
if (err != nil || fi == model.ListModel{}) && reqPath != "" && reqPath != "/" && strings.Index(reqPath, "test.png") == -1 {
//新建或修改名称的时候需要判断是否已存在
if len(list.Items) == 0 {
if len(list.Items) == 0 || unfindListErr != nil {
return http.StatusNotFound, err
}

Expand Down Expand Up @@ -959,18 +963,23 @@ func findUrl(strArr []string, token, driveId string, list model.FileListModel) (

func findList(strArr []string, token, driveId string) (model.FileListModel, error) {
var list model.FileListModel
var listm model.FileListModel
var err error
err = errors.New("未找到数据")
list, _ = aliyun.GetList(token, driveId, "")
num := 0
for _, a := range strArr {
for _, v := range list.Items {
if v.Name == a {
listm, _ = aliyun.GetList(token, driveId, v.FileId)
list, _ = aliyun.GetList(token, driveId, v.FileId)
num += 1
break
}
}
}

return listm, errors.New("未找到数据")
if num == len(strArr) {
err = nil
}
return list, err
}

func makePropstatResponse(href string, pstats []Propstat) *response {
Expand Down

0 comments on commit f800f47

Please sign in to comment.