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

Commit

Permalink
Merge pull request #21 from togls/master
Browse files Browse the repository at this point in the history
fix bug
  • Loading branch information
LinkLeong authored Nov 24, 2021
2 parents 9ed9474 + d4113f4 commit b59ef52
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
42 changes: 26 additions & 16 deletions aliyun/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package aliyun
import (
"encoding/json"
"fmt"
"os"
"io/ioutil"
"go-aliyun-webdav/aliyun/cache"
"go-aliyun-webdav/aliyun/model"
"go-aliyun-webdav/aliyun/net"
"io/ioutil"
"net/http"
"os"
"strconv"

"github.com/tidwall/gjson"
Expand Down Expand Up @@ -117,30 +117,40 @@ func RefreshToken(refreshToken string) model.RefreshTokenModel {
if _, err := os.Stat(path); err == nil {
buf, _ := ioutil.ReadFile(path)
refreshToken = string(buf)
if(len(refreshToken) >= 32){
if len(refreshToken) >= 32 {
refreshToken = refreshToken[:32] // refreshToken is only 32 bit?? FIXME
}
}
rs := net.Post(model.APIREFRESHTOKENURL, "", []byte(`{"refresh_token":"`+refreshToken+`"}`))
var refresh model.RefreshTokenModel
if len(rs) > 0 {
err := json.Unmarshal(rs, &refresh)
if err != nil {
fmt.Println("刷新token失败,失败信息", err)
fmt.Println("刷新token返回信息", refresh)
}
} else {

if len(rs) <= 0 {
fmt.Println("刷新token失败")
return refresh
}

if _, err := os.Stat(path); err == nil {
if(refreshToken != refresh.RefreshToken){
content := []byte(refresh.RefreshToken)
ioutil.WriteFile(path, content, 0600)
}
err := json.Unmarshal(rs, &refresh)
if err != nil {
fmt.Println("刷新token失败,失败信息", err)
fmt.Println("刷新token返回信息", refresh)
return refresh
}

if refreshToken == refresh.RefreshToken {
return refresh
}

if _, err := os.Stat(path); err != nil {
fmt.Printf("RefreshToken Err=%s", err)
return refresh
}
return refresh

err = ioutil.WriteFile(path, []byte(refresh.RefreshToken), 0600)
if err != nil {
fmt.Printf("RefreshToken Err=%s", err)
}

return refresh
}

func RemoveTrash(token string, driveId string, fileId string, parentFileId string) bool {
Expand Down
10 changes: 9 additions & 1 deletion webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,16 @@ func (h *Handler) handleGetHeadPost(w http.ResponseWriter, r *http.Request) (sta
reqPath, status, err := h.stripPrefix(r.URL.Path)
if len(reqPath) > 0 && !strings.HasSuffix(reqPath, "/") {
strArr := strings.Split(reqPath, "/")
list, _ := aliyun.GetList(h.Config.Token, h.Config.DriveId, "")

list, err := aliyun.GetList(h.Config.Token, h.Config.DriveId, "")
if err != nil {
return http.StatusNotFound, err
}

fi, err = findUrl(strArr, h.Config.Token, h.Config.DriveId, list)
if err != nil || fi.FileId == "" {
return http.StatusNotFound, err
}
//url := fi.Thumbnail
//url := fi.Url
//if len(url) == 0 {
Expand Down

0 comments on commit b59ef52

Please sign in to comment.