-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
654 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package onedrive | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" | ||
|
||
"github.com/IceWhaleTech/CasaOS/internal/driver" | ||
"github.com/IceWhaleTech/CasaOS/model" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type Onedrive struct { | ||
model.StorageA | ||
Addition | ||
AccessToken string | ||
} | ||
|
||
func (d *Onedrive) Config() driver.Config { | ||
return 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 | ||
} | ||
if len(d.RefreshToken) == 0 { | ||
return d.getRefreshToken() | ||
} | ||
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) | ||
if err != nil { | ||
return "", "", "", err | ||
} | ||
|
||
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) { | ||
host := onedriveHostMap[d.Region] | ||
url := fmt.Sprintf("%s/v1.0/me/drive/quota", host.Api) | ||
size := About{} | ||
resp, err := d.Request(url, http.MethodGet, nil, &size) | ||
if err != nil { | ||
return used, total, err | ||
} | ||
logger.Info("resp", zap.Any("resp", resp)) | ||
used = strconv.Itoa(size.Used) | ||
total = strconv.Itoa(size.Total) | ||
return | ||
} | ||
func (d *Onedrive) Drop(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
var _ driver.Driver = (*Onedrive)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package onedrive | ||
|
||
import ( | ||
"github.com/IceWhaleTech/CasaOS/internal/driver" | ||
) | ||
|
||
type Host struct { | ||
Oauth string | ||
Api string | ||
} | ||
|
||
type TokenErr struct { | ||
Error string `json:"error"` | ||
ErrorDescription string `json:"error_description"` | ||
} | ||
|
||
type RespErr struct { | ||
Error struct { | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
} `json:"error"` | ||
} | ||
type Addition struct { | ||
Region string `json:"region" type:"select" required:"true" options:"global,cn,us,de" default:"global"` | ||
IsSharepoint bool `json:"is_sharepoint"` | ||
ClientID string `json:"client_id" required:"true"` | ||
ClientSecret string `json:"client_secret" required:"true"` | ||
RedirectUri string `json:"redirect_uri" required:"true" default:""` | ||
RefreshToken string `json:"refresh_token" required:"true"` | ||
SiteId string `json:"site_id"` | ||
ChunkSize int64 `json:"chunk_size" type:"number" default:"5"` | ||
RootFolderID string `json:"root_folder_id"` | ||
AuthUrl string `json:"auth_url" type:"string" default:""` | ||
Icon string `json:"icon" type:"string" default:""` | ||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"` | ||
} | ||
type About struct { | ||
Total int `json:"total"` | ||
Used int `json:"used"` | ||
State string `json:"state"` | ||
} | ||
|
||
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"` | ||
User struct { | ||
DisplayName string `json:"displayName"` | ||
ID string `json:"id"` | ||
} `json:"user"` | ||
} `json:"lastModifiedBy"` | ||
ParentReference struct { | ||
DriveID string `json:"driveId"` | ||
DriveType string `json:"driveType"` | ||
} `json:"parentReference"` | ||
} | ||
|
||
var config = driver.Config{ | ||
Name: "Onedrive", | ||
LocalSort: true, | ||
DefaultRoot: "/", | ||
} |
Oops, something went wrong.