Skip to content

Commit

Permalink
fix: update user info retrieval and clean up unused code (#2101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ns2Kracy authored Dec 19, 2024
1 parent 63f0148 commit ba285cb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 61 deletions.
9 changes: 6 additions & 3 deletions drivers/onedrive/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (d *Onedrive) Config() driver.Config {
func (d *Onedrive) GetAddition() driver.Additional {
return &d.Addition
}

func (d *Onedrive) Init(ctx context.Context) error {
if d.ChunkSize < 1 {
d.ChunkSize = 5
Expand All @@ -35,19 +36,20 @@ func (d *Onedrive) Init(ctx context.Context) error {
}
return d.refreshToken()
}

func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
return "", nil
}

func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
url := d.GetMetaUrl(false, "/")
user := Info{}
resp, err := d.Request(url, http.MethodGet, nil, &user)
_, err := d.Request(url, http.MethodGet, nil, &user)
if err != nil {
return "", "", "", err
}

logger.Info("resp", zap.Any("resp", resp))
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
return user.CreatedBy.User.Email, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
}

func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
Expand All @@ -63,6 +65,7 @@ func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string,
total = strconv.Itoa(size.Total)
return
}

func (d *Onedrive) Drop(ctx context.Context) error {
return nil
}
Expand Down
13 changes: 3 additions & 10 deletions drivers/onedrive/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,12 @@ type About struct {
}

type Info struct {
LastModifiedBy struct {
Application struct {
DisplayName string `json:"displayName"`
ID string `json:"id"`
} `json:"application"`
Device struct {
ID string `json:"id"`
} `json:"device"`
CreatedBy struct {
User struct {
Email string `json:"email"`
DisplayName string `json:"displayName"`
ID string `json:"id"`
} `json:"user"`
} `json:"lastModifiedBy"`
} `json:"createdBy"`
ParentReference struct {
DriveID string `json:"driveId"`
DriveType string `json:"driveType"`
Expand Down
28 changes: 3 additions & 25 deletions drivers/onedrive/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ package onedrive
import (
"errors"
"fmt"
"net/url"
"strings"

"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
"github.com/IceWhaleTech/CasaOS/drivers/base"
"github.com/IceWhaleTech/CasaOS/pkg/utils"
"go.uber.org/zap"
)

var (
client_id = "private build"
client_secret = "private build"
)

var onedriveHostMap = map[string]Host{
"global": {
Oauth: "https://login.microsoftonline.com",
Expand All @@ -34,31 +34,9 @@ var onedriveHostMap = map[string]Host{
},
}

func EncodePath(path string, all ...bool) string {
seg := strings.Split(path, "/")
toReplace := []struct {
Src string
Dst string
}{
{Src: "%", Dst: "%25"},
{"%", "%25"},
{"?", "%3F"},
{"#", "%23"},
}
for i := range seg {
if len(all) > 0 && all[0] {
seg[i] = url.PathEscape(seg[i])
} else {
for j := range toReplace {
seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst)
}
}
}
return strings.Join(seg, "/")
}
func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
host := onedriveHostMap[d.Region]
path = EncodePath(path, true)
path = utils.EncodePath(path, true)
if auth {
return host.Oauth
}
Expand Down
24 changes: 1 addition & 23 deletions route/v1/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ import (
)

func ListStorages(ctx echo.Context) error {
// var req model.PageReq
// if err := ctx.Bind(&req); err != nil {
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: err.Error()})
// return
// }
// req.Validate()

// logger.Info("ListStorages", zap.Any("req", req))
// storages, total, err := service.MyService.Storage().GetStorages(req.Page, req.PerPage)
// if err != nil {
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
// return
// }
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: model.PageResp{
// Content: storages,
// Total: total,
// }})
r, err := service.MyService.Storage().GetStorages()
if err != nil {
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
Expand All @@ -58,12 +41,7 @@ func ListStorages(ctx echo.Context) error {
list := []httper.MountPoint{}

for _, v := range r.MountPoints {
list = append(list, httper.MountPoint{
Fs: v.Fs,
Icon: v.Icon,
MountPoint: v.MountPoint,
Name: v.Name,
})
list = append(list, httper.MountPoint(v))
}

return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})
Expand Down

0 comments on commit ba285cb

Please sign in to comment.