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

Commit

Permalink
添加容量
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Oct 14, 2021
1 parent 86c9f58 commit 25efe10
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions aliyun/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,13 @@ func GetDownloadUrl(token string, driveId string, fileId string) string {
return gjson.GetBytes(body, "url").Str

}
func GetBoxSize(token string) (string, string) {

postData := make(map[string]interface{})

data, _ := json.Marshal(postData)

body := net.Post(model.APITOTLESIZE, token, data)
return gjson.GetBytes(body, "personal_space_info.total_size").String(), gjson.GetBytes(body, "personal_space_info.used_size").String()

}
1 change: 1 addition & 0 deletions aliyun/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
APIFILEUPLOADFILE = APIBASE + "/v2/file/create_with_proof" //"/v2/file/create"
APIFILECOMPLETE = APIBASE + "/v2/file/complete"
APIFILEDOWNLOAD = APIBASE + "/v2/file/get_download_url"
APITOTLESIZE = APIBASE + "/v2/databox/get_personal_info"
)

type Config struct {
Expand Down
20 changes: 20 additions & 0 deletions webdav/prop.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ var liveProps = map[xml.Name]struct {
findFn: nil,
dir: false,
},
{Space: "DAV:", Local: "quota-available-bytes"}: {
findFn: quota,
dir: true,
},
{Space: "DAV:", Local: "quota-used-bytes"}: {
findFn: quotaU,
dir: true,
},
{Space: "DAV:", Local: "getcontenttype"}: {
findFn: findContentType,
dir: false,
Expand Down Expand Up @@ -413,6 +421,18 @@ func findLastModified(ctx context.Context, fs FileSystem, ls LockSystem, fi mode
func findCreate(ctx context.Context, fs FileSystem, ls LockSystem, fi model.ListModel) (string, error) {
return fi.CreatedAt.UTC().Format(http.TimeFormat), nil
}
func quota(ctx context.Context, fs FileSystem, ls LockSystem, fi model.ListModel) (string, error) {
if fi.Name == "" {
return "1056194496917", nil
}
return "", nil
}
func quotaU(ctx context.Context, fs FileSystem, ls LockSystem, fi model.ListModel) (string, error) {
if fi.Name == "" {
return "60497000043", nil
}
return "", nil
}

// ErrNotImplemented should be returned by optional interfaces if they
// want the original implementation to be used.
Expand Down
12 changes: 12 additions & 0 deletions webdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go-aliyun-webdav/aliyun/cache"
"go-aliyun-webdav/aliyun/model"
"io"
"io/ioutil"
"reflect"
"strconv"

Expand Down Expand Up @@ -715,6 +716,17 @@ func (h *Handler) handleUnlock(w http.ResponseWriter, r *http.Request) (status i
}

func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request) (status int, err error) {
if r.ContentLength > 0 {
available, _ := ioutil.ReadAll(r.Body)
if strings.Contains(string(available), "quota-available-bytes") {
totle, used := aliyun.GetBoxSize(h.Config.Token)
to, _ := strconv.ParseInt(string(totle), 10, 64)
us, _ := strconv.ParseInt(string(used), 10, 64)
w.Write([]byte(`<?xml version="1.0" encoding="utf-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/</D:href><D:propstat><D:prop><D:quota-available-bytes>` + strconv.FormatInt(to-us, 10) + `</D:quota-available-bytes><D:quota-used-bytes>` + used + `</D:quota-used-bytes></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
</D:multistatus>`))
return 0, nil
}
}
reqPath, status, err := h.stripPrefix(r.URL.Path)
var list model.FileListModel
var fi model.ListModel
Expand Down

0 comments on commit 25efe10

Please sign in to comment.