-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
35 changed files
with
2,685 additions
and
278 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,27 @@ | ||
package main | ||
|
||
import ( | ||
interfaces "github.com/IceWhaleTech/CasaOS-Common" | ||
) | ||
|
||
type migrationTool struct{} | ||
|
||
func (u *migrationTool) IsMigrationNeeded() (bool, error) { | ||
return false, nil | ||
} | ||
|
||
func (u *migrationTool) PreMigrate() error { | ||
return nil | ||
} | ||
|
||
func (u *migrationTool) Migrate() error { | ||
return nil | ||
} | ||
|
||
func (u *migrationTool) PostMigrate() error { | ||
return nil | ||
} | ||
|
||
func NewMigrationDummy() interfaces.MigrationTool { | ||
return &migrationTool{} | ||
} |
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,12 @@ | ||
package drivers | ||
|
||
import ( | ||
_ "github.com/IceWhaleTech/CasaOS/drivers/dropbox" | ||
_ "github.com/IceWhaleTech/CasaOS/drivers/google_drive" | ||
) | ||
|
||
// All do nothing,just for import | ||
// same as _ import | ||
func All() { | ||
|
||
} |
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,30 @@ | ||
package base | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
"github.com/go-resty/resty/v2" | ||
) | ||
|
||
var NoRedirectClient *resty.Client | ||
var RestyClient = NewRestyClient() | ||
var HttpClient = &http.Client{} | ||
var UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36" | ||
var DefaultTimeout = time.Second * 30 | ||
|
||
func init() { | ||
NoRedirectClient = resty.New().SetRedirectPolicy( | ||
resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { | ||
return http.ErrUseLastResponse | ||
}), | ||
) | ||
NoRedirectClient.SetHeader("user-agent", UserAgent) | ||
} | ||
|
||
func NewRestyClient() *resty.Client { | ||
return resty.New(). | ||
SetHeader("user-agent", UserAgent). | ||
SetRetryCount(3). | ||
SetTimeout(DefaultTimeout) | ||
} |
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,12 @@ | ||
package base | ||
|
||
import "github.com/go-resty/resty/v2" | ||
|
||
type Json map[string]interface{} | ||
|
||
type TokenResp struct { | ||
AccessToken string `json:"access_token"` | ||
RefreshToken string `json:"refresh_token"` | ||
} | ||
|
||
type ReqCallback func(req *resty.Request) |
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,100 @@ | ||
package dropbox | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
|
||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" | ||
"github.com/IceWhaleTech/CasaOS/internal/driver" | ||
"github.com/IceWhaleTech/CasaOS/model" | ||
"github.com/IceWhaleTech/CasaOS/pkg/utils" | ||
"github.com/go-resty/resty/v2" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type Dropbox struct { | ||
model.StorageA | ||
Addition | ||
AccessToken string | ||
} | ||
|
||
func (d *Dropbox) Config() driver.Config { | ||
return config | ||
} | ||
|
||
func (d *Dropbox) GetAddition() driver.Additional { | ||
return &d.Addition | ||
} | ||
|
||
func (d *Dropbox) Init(ctx context.Context) error { | ||
if len(d.RefreshToken) == 0 { | ||
d.getRefreshToken() | ||
} | ||
return d.refreshToken() | ||
} | ||
|
||
func (d *Dropbox) Drop(ctx context.Context) error { | ||
|
||
return nil | ||
} | ||
|
||
func (d *Dropbox) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) { | ||
files, err := d.getFiles(dir.GetID()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return utils.SliceConvert(files, func(src File) (model.Obj, error) { | ||
return fileToObj(src), nil | ||
}) | ||
} | ||
|
||
func (d *Dropbox) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) { | ||
url := "https://content.dropboxapi.com/2/files/download" | ||
link := model.Link{ | ||
URL: url, | ||
Method: http.MethodPost, | ||
Header: http.Header{ | ||
"Authorization": []string{"Bearer " + d.AccessToken}, | ||
"Dropbox-API-Arg": []string{`{"path": "` + file.GetPath() + `"}`}, | ||
}, | ||
} | ||
return &link, nil | ||
} | ||
func (d *Dropbox) GetUserInfo(ctx context.Context) (string, error) { | ||
url := "https://api.dropboxapi.com/2/users/get_current_account" | ||
user := UserInfo{} | ||
resp, err := d.request(url, http.MethodPost, func(req *resty.Request) { | ||
req.SetHeader("Content-Type", "") | ||
}, &user) | ||
if err != nil { | ||
return "", err | ||
} | ||
logger.Info("resp", zap.Any("resp", string(resp))) | ||
return user.Email, nil | ||
} | ||
func (d *Dropbox) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error { | ||
return nil | ||
} | ||
|
||
func (d *Dropbox) Move(ctx context.Context, srcObj, dstDir model.Obj) error { | ||
return nil | ||
} | ||
|
||
func (d *Dropbox) Rename(ctx context.Context, srcObj model.Obj, newName string) error { | ||
return nil | ||
} | ||
|
||
func (d *Dropbox) Copy(ctx context.Context, srcObj, dstDir model.Obj) error { | ||
return errors.New("not support") | ||
} | ||
|
||
func (d *Dropbox) Remove(ctx context.Context, obj model.Obj) error { | ||
return nil | ||
} | ||
|
||
func (d *Dropbox) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error { | ||
return nil | ||
} | ||
|
||
var _ driver.Driver = (*Dropbox)(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,33 @@ | ||
package dropbox | ||
|
||
import ( | ||
"github.com/IceWhaleTech/CasaOS/internal/driver" | ||
"github.com/IceWhaleTech/CasaOS/internal/op" | ||
) | ||
|
||
const ICONURL = "./img/driver/Dropbox.svg" | ||
const APPKEY = "tciqajyazzdygt9" | ||
const APPSECRET = "e7gtmv441cwdf0n" | ||
|
||
type Addition struct { | ||
driver.RootID | ||
RefreshToken string `json:"refresh_token" required:"true" omit:"true"` | ||
AppKey string `json:"app_key" type:"string" default:"tciqajyazzdygt9" omit:"true"` | ||
AppSecret string `json:"app_secret" type:"string" default:"e7gtmv441cwdf0n" omit:"true"` | ||
OrderDirection string `json:"order_direction" type:"select" options:"asc,desc" omit:"true"` | ||
AuthUrl string `json:"auth_url" type:"string" default:"https://www.dropbox.com/oauth2/authorize?client_id=tciqajyazzdygt9&redirect_uri=https://cloudoauth.files.casaos.app&response_type=code&token_access_type=offline&state=${HOST}%2Fv1%2Frecover%2FDropbox&&force_reapprove=true&force_reauthentication=true"` | ||
Icon string `json:"icon" type:"string" default:"./img/driver/Dropbox.svg"` | ||
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"` | ||
} | ||
|
||
var config = driver.Config{ | ||
Name: "Dropbox", | ||
OnlyProxy: true, | ||
DefaultRoot: "root", | ||
} | ||
|
||
func init() { | ||
op.RegisterDriver(func() driver.Driver { | ||
return &Dropbox{} | ||
}) | ||
} |
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,88 @@ | ||
package dropbox | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" | ||
"github.com/IceWhaleTech/CasaOS/model" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type UserInfo struct { | ||
AccountID string `json:"account_id"` | ||
Name struct { | ||
GivenName string `json:"given_name"` | ||
Surname string `json:"surname"` | ||
FamiliarName string `json:"familiar_name"` | ||
DisplayName string `json:"display_name"` | ||
AbbreviatedName string `json:"abbreviated_name"` | ||
} `json:"name"` | ||
Email string `json:"email"` | ||
EmailVerified bool `json:"email_verified"` | ||
Disabled bool `json:"disabled"` | ||
Country string `json:"country"` | ||
Locale string `json:"locale"` | ||
ReferralLink string `json:"referral_link"` | ||
IsPaired bool `json:"is_paired"` | ||
AccountType struct { | ||
Tag string `json:".tag"` | ||
} `json:"account_type"` | ||
RootInfo struct { | ||
Tag string `json:".tag"` | ||
RootNamespaceID string `json:"root_namespace_id"` | ||
HomeNamespaceID string `json:"home_namespace_id"` | ||
} `json:"root_info"` | ||
} | ||
type TokenError struct { | ||
Error string `json:"error"` | ||
ErrorDescription string `json:"error_description"` | ||
} | ||
type File struct { | ||
Tag string `json:".tag"` | ||
Name string `json:"name"` | ||
PathLower string `json:"path_lower"` | ||
PathDisplay string `json:"path_display"` | ||
ID string `json:"id"` | ||
ClientModified time.Time `json:"client_modified,omitempty"` | ||
ServerModified time.Time `json:"server_modified,omitempty"` | ||
Rev string `json:"rev,omitempty"` | ||
Size int `json:"size,omitempty"` | ||
IsDownloadable bool `json:"is_downloadable,omitempty"` | ||
ContentHash string `json:"content_hash,omitempty"` | ||
} | ||
|
||
type Files struct { | ||
Files []File `json:"entries"` | ||
Cursor string `json:"cursor"` | ||
HasMore bool `json:"has_more"` | ||
} | ||
|
||
type Error struct { | ||
Error struct { | ||
Errors []struct { | ||
Domain string `json:"domain"` | ||
Reason string `json:"reason"` | ||
Message string `json:"message"` | ||
LocationType string `json:"location_type"` | ||
Location string `json:"location"` | ||
} | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
} `json:"error"` | ||
} | ||
|
||
func fileToObj(f File) *model.ObjThumb { | ||
logger.Info("dropbox file", zap.Any("file", f)) | ||
obj := &model.ObjThumb{ | ||
Object: model.Object{ | ||
ID: f.ID, | ||
Name: f.Name, | ||
Size: int64(f.Size), | ||
Modified: f.ClientModified, | ||
IsFolder: f.Tag == "folder", | ||
Path: f.PathDisplay, | ||
}, | ||
Thumbnail: model.Thumbnail{}, | ||
} | ||
return obj | ||
} |
Oops, something went wrong.