Skip to content

Commit ba285cb

Browse files
authored
fix: update user info retrieval and clean up unused code (#2101)
1 parent 63f0148 commit ba285cb

File tree

4 files changed

+13
-61
lines changed

4 files changed

+13
-61
lines changed

drivers/onedrive/drive.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func (d *Onedrive) Config() driver.Config {
2626
func (d *Onedrive) GetAddition() driver.Additional {
2727
return &d.Addition
2828
}
29+
2930
func (d *Onedrive) Init(ctx context.Context) error {
3031
if d.ChunkSize < 1 {
3132
d.ChunkSize = 5
@@ -35,19 +36,20 @@ func (d *Onedrive) Init(ctx context.Context) error {
3536
}
3637
return d.refreshToken()
3738
}
39+
3840
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
3941
return "", nil
4042
}
43+
4144
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
4245
url := d.GetMetaUrl(false, "/")
4346
user := Info{}
44-
resp, err := d.Request(url, http.MethodGet, nil, &user)
47+
_, err := d.Request(url, http.MethodGet, nil, &user)
4548
if err != nil {
4649
return "", "", "", err
4750
}
4851

49-
logger.Info("resp", zap.Any("resp", resp))
50-
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
52+
return user.CreatedBy.User.Email, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
5153
}
5254

5355
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
@@ -63,6 +65,7 @@ func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string,
6365
total = strconv.Itoa(size.Total)
6466
return
6567
}
68+
6669
func (d *Onedrive) Drop(ctx context.Context) error {
6770
return nil
6871
}

drivers/onedrive/meta.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,12 @@ type About struct {
4343
}
4444

4545
type Info struct {
46-
LastModifiedBy struct {
47-
Application struct {
48-
DisplayName string `json:"displayName"`
49-
ID string `json:"id"`
50-
} `json:"application"`
51-
Device struct {
52-
ID string `json:"id"`
53-
} `json:"device"`
46+
CreatedBy struct {
5447
User struct {
48+
Email string `json:"email"`
5549
DisplayName string `json:"displayName"`
56-
ID string `json:"id"`
5750
} `json:"user"`
58-
} `json:"lastModifiedBy"`
51+
} `json:"createdBy"`
5952
ParentReference struct {
6053
DriveID string `json:"driveId"`
6154
DriveType string `json:"driveType"`

drivers/onedrive/util.go

+3-25
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ package onedrive
33
import (
44
"errors"
55
"fmt"
6-
"net/url"
7-
"strings"
86

97
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
108
"github.com/IceWhaleTech/CasaOS/drivers/base"
9+
"github.com/IceWhaleTech/CasaOS/pkg/utils"
1110
"go.uber.org/zap"
1211
)
1312

1413
var (
1514
client_id = "private build"
1615
client_secret = "private build"
1716
)
17+
1818
var onedriveHostMap = map[string]Host{
1919
"global": {
2020
Oauth: "https://login.microsoftonline.com",
@@ -34,31 +34,9 @@ var onedriveHostMap = map[string]Host{
3434
},
3535
}
3636

37-
func EncodePath(path string, all ...bool) string {
38-
seg := strings.Split(path, "/")
39-
toReplace := []struct {
40-
Src string
41-
Dst string
42-
}{
43-
{Src: "%", Dst: "%25"},
44-
{"%", "%25"},
45-
{"?", "%3F"},
46-
{"#", "%23"},
47-
}
48-
for i := range seg {
49-
if len(all) > 0 && all[0] {
50-
seg[i] = url.PathEscape(seg[i])
51-
} else {
52-
for j := range toReplace {
53-
seg[i] = strings.ReplaceAll(seg[i], toReplace[j].Src, toReplace[j].Dst)
54-
}
55-
}
56-
}
57-
return strings.Join(seg, "/")
58-
}
5937
func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
6038
host := onedriveHostMap[d.Region]
61-
path = EncodePath(path, true)
39+
path = utils.EncodePath(path, true)
6240
if auth {
6341
return host.Oauth
6442
}

route/v1/cloud.go

+1-23
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ import (
1616
)
1717

1818
func ListStorages(ctx echo.Context) error {
19-
// var req model.PageReq
20-
// if err := ctx.Bind(&req); err != nil {
21-
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.CLIENT_ERROR, Message: common_err.GetMsg(common_err.CLIENT_ERROR), Data: err.Error()})
22-
// return
23-
// }
24-
// req.Validate()
25-
26-
// logger.Info("ListStorages", zap.Any("req", req))
27-
// storages, total, err := service.MyService.Storage().GetStorages(req.Page, req.PerPage)
28-
// if err != nil {
29-
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
30-
// return
31-
// }
32-
// return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: model.PageResp{
33-
// Content: storages,
34-
// Total: total,
35-
// }})
3619
r, err := service.MyService.Storage().GetStorages()
3720
if err != nil {
3821
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
@@ -58,12 +41,7 @@ func ListStorages(ctx echo.Context) error {
5841
list := []httper.MountPoint{}
5942

6043
for _, v := range r.MountPoints {
61-
list = append(list, httper.MountPoint{
62-
Fs: v.Fs,
63-
Icon: v.Icon,
64-
MountPoint: v.MountPoint,
65-
Name: v.Name,
66-
})
44+
list = append(list, httper.MountPoint(v))
6745
}
6846

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

0 commit comments

Comments
 (0)