mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-24 11:45:33 +00:00
Compare commits
1 Commits
58f3c2f46a
...
6ca194c0a6
Author | SHA1 | Date | |
---|---|---|---|
|
6ca194c0a6 |
@ -26,7 +26,6 @@ func (d *Onedrive) Config() driver.Config {
|
|||||||
func (d *Onedrive) GetAddition() driver.Additional {
|
func (d *Onedrive) GetAddition() driver.Additional {
|
||||||
return &d.Addition
|
return &d.Addition
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Onedrive) Init(ctx context.Context) error {
|
func (d *Onedrive) Init(ctx context.Context) error {
|
||||||
if d.ChunkSize < 1 {
|
if d.ChunkSize < 1 {
|
||||||
d.ChunkSize = 5
|
d.ChunkSize = 5
|
||||||
@ -36,20 +35,19 @@ func (d *Onedrive) Init(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
return d.refreshToken()
|
return d.refreshToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
|
func (d *Onedrive) GetUserInfo(ctx context.Context) (string, error) {
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
|
func (d *Onedrive) GetInfo(ctx context.Context) (string, string, string, error) {
|
||||||
url := d.GetMetaUrl(false, "/")
|
url := d.GetMetaUrl(false, "/")
|
||||||
user := Info{}
|
user := Info{}
|
||||||
_, err := d.Request(url, http.MethodGet, nil, &user)
|
resp, err := d.Request(url, http.MethodGet, nil, &user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return user.CreatedBy.User.Email, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
logger.Info("resp", zap.Any("resp", resp))
|
||||||
|
return user.LastModifiedBy.User.DisplayName, user.ParentReference.DriveID, user.ParentReference.DriveType, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
|
func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string, err error) {
|
||||||
@ -65,7 +63,6 @@ func (d *Onedrive) GetSpaceSize(ctx context.Context) (used string, total string,
|
|||||||
total = strconv.Itoa(size.Total)
|
total = strconv.Itoa(size.Total)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Onedrive) Drop(ctx context.Context) error {
|
func (d *Onedrive) Drop(ctx context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,19 @@ type About struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
CreatedBy struct {
|
LastModifiedBy struct {
|
||||||
User struct {
|
Application struct {
|
||||||
Email string `json:"email"`
|
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
|
ID string `json:"id"`
|
||||||
|
} `json:"application"`
|
||||||
|
Device struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
} `json:"device"`
|
||||||
|
User struct {
|
||||||
|
DisplayName string `json:"displayName"`
|
||||||
|
ID string `json:"id"`
|
||||||
} `json:"user"`
|
} `json:"user"`
|
||||||
} `json:"createdBy"`
|
} `json:"lastModifiedBy"`
|
||||||
ParentReference struct {
|
ParentReference struct {
|
||||||
DriveID string `json:"driveId"`
|
DriveID string `json:"driveId"`
|
||||||
DriveType string `json:"driveType"`
|
DriveType string `json:"driveType"`
|
||||||
|
@ -3,10 +3,11 @@ package onedrive
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
"github.com/IceWhaleTech/CasaOS-Common/utils/logger"
|
||||||
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
"github.com/IceWhaleTech/CasaOS/drivers/base"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/utils"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +15,6 @@ var (
|
|||||||
client_id = "private build"
|
client_id = "private build"
|
||||||
client_secret = "private build"
|
client_secret = "private build"
|
||||||
)
|
)
|
||||||
|
|
||||||
var onedriveHostMap = map[string]Host{
|
var onedriveHostMap = map[string]Host{
|
||||||
"global": {
|
"global": {
|
||||||
Oauth: "https://login.microsoftonline.com",
|
Oauth: "https://login.microsoftonline.com",
|
||||||
@ -34,9 +34,31 @@ 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 {
|
func (d *Onedrive) GetMetaUrl(auth bool, path string) string {
|
||||||
host := onedriveHostMap[d.Region]
|
host := onedriveHostMap[d.Region]
|
||||||
path = utils.EncodePath(path, true)
|
path = EncodePath(path, true)
|
||||||
if auth {
|
if auth {
|
||||||
return host.Oauth
|
return host.Oauth
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func ListStorages(ctx echo.Context) error {
|
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()
|
r, err := service.MyService.Storage().GetStorages()
|
||||||
if err != nil {
|
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 ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
||||||
@ -41,7 +58,12 @@ func ListStorages(ctx echo.Context) error {
|
|||||||
list := []httper.MountPoint{}
|
list := []httper.MountPoint{}
|
||||||
|
|
||||||
for _, v := range r.MountPoints {
|
for _, v := range r.MountPoints {
|
||||||
list = append(list, httper.MountPoint(v))
|
list = append(list, httper.MountPoint{
|
||||||
|
Fs: v.Fs,
|
||||||
|
Icon: v.Icon,
|
||||||
|
MountPoint: v.MountPoint,
|
||||||
|
Name: v.Name,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})
|
return ctx.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: list})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user