Back to godoc.org

Package onedrive

v1.0.3
Latest Go to latest

The latest major version is .

Published: Feb 24, 2020 | License: Apache-2.0 | Module: git.dukx.net/dukangxu/dukx-drive

Index

Constants

const (
	MethodGET  = "GET"
	MethodPOST = "POST"
	//https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=ea2b36f6-b8ad-40be-bc0f-e5e4a4a7d4fa&scope=files.readwrite offline_access&response_type=code&redirect_uri=http://localhost/onedrive-login
	GetAuthCodeUrl          = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize" //?client_id={%s}&scope={%s}&response_type=code&redirect_uri={%s}
	GetOrRefreshAccessToken = "https://login.microsoftonline.com/common/oauth2/v2.0/token"
)
const (
	AuthId           = "34b0b5a2-9df6-4f56-93f7-793ba1fd0858"
	AuthSecret       = "p3zjb]3Ldkrii2Edk1?WGxY]xmwdyD]n"
	AuthScope        = "files.readwrite offline_access"
	AuthRedirectAddr = "localhost:53841"
	AuthRouter       = "/"
)
const (
	GraphUrl                      = "https://graph.microsoft.com/v1.0"
	DrivePathUrl                  = "/drives/me/root%s"
	DrivePathChildrenUrl          = "/drives/me/root%s/children??orderby=name"
	DriveItemPreviewUrl           = "/drives/me/items/%s/preview"
	DriveItemThumbnailsUrl        = "/drives/me/items/%s/thumbnails"
	DriveItemThumbnailsContentUrl = "/drives/me/items/%s/thumbnails/%s/%s/content"
	DriveItemsTimeFormat          = "2006-01-02T15:04:05Z"
)
const (
	KeyFilePrefix      = "onedrive_file"
	KeyDirectoryPrefix = "onedrive_directory"
)
const (
	LocationShanghaiKey = "Asia/Shanghai"
	TimeToFormat        = "2006-01-02 15:04:05"
)
const (
	B = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
	EB
)

Variables

var (
	FileBucketName      = zbolt.StringToBytes(KeyFilePrefix)
	DirectoryBucketName = AssembleDirectoryBucketName
)
var (
	LocationShanghai, _ = time.LoadLocation(LocationShanghaiKey)
)

func AssembleDirectoryBucketName

func AssembleDirectoryBucketName(id []byte) []byte

func AssembleDirectoryFilePath

func AssembleDirectoryFilePath(directory, name string) string

func AssembleListPath

func AssembleListPath(path string) string

func AssembleRouterDirectoryFilePath

func AssembleRouterDirectoryFilePath(router, directory, name string) string

func AssembleUrl

func AssembleUrl(reqUrl string, data map[string]string) string

func FormatSize

func FormatSize(size uint64) string

func GetFreePort

func GetFreePort() (int, error)

func HttpRequestAuth

func HttpRequestAuth(reqUrl, method string, data, headers map[string]string) ([]byte, error)

type Auth

type Auth struct {
	ClientID     string           `json:"client_id"`
	ClientSecret string           `json:"client_secret"`
	Scope        string           `json:"scope"`
	RedirectUri  string           `json:"redirect_uri"`
	Token        *Token           `json:"token"`
	Ch           chan interface{} `json:"ch"`
}

func NewAuth

func NewAuth(id, secret, scope, redirectAddr, redirectUrl string) *Auth

func (*Auth) GetAccessTokenWithAuthCode

func (a *Auth) GetAccessTokenWithAuthCode(code string) error

func (*Auth) GetAuthUrl

func (a *Auth) GetAuthUrl() string

func (*Auth) Graph

func (a *Auth) Graph() *Graph

func (*Auth) HttpAuthRequest

func (a *Auth) HttpAuthRequest(w http.ResponseWriter, r *http.Request)

func (*Auth) HttpRedirectOneDrive

func (a *Auth) HttpRedirectOneDrive(w http.ResponseWriter, r *http.Request)

func (*Auth) OpenAuthUrl

func (a *Auth) OpenAuthUrl()

func (*Auth) RefreshToken

func (a *Auth) RefreshToken() error

func (*Auth) RunRedirectHttp

func (a *Auth) RunRedirectHttp(addr, router string) *http.Server

func (*Auth) WithToken

func (a *Auth) WithToken(token *Token) *Auth

type Config

type Config struct {
	RootPath         string `json:"root_path"`
	TokenRefreshRate int64  `json:"token_cycle"`
	FileRefreshRate  int64  `json:"file_cycle"`
	DownloadTimeout  int64  `json:"download_timeout"`
	Token            *Token `json:"token"`
	RootPathModified int64  `json:"root_path_modified"`
}

func NewConfig

func NewConfig(rootPath string, tokenRefreshRate, fileRefreshRate, downloadTimeout int64, tokenBase64 string) (*Config, error)

func (Config) OneDriveConfig

func (cfg Config) OneDriveConfig() config.OneDriveConfig

type DB

type DB struct {
	// contains filtered or unexported fields
}

func NewZBolt

func NewZBolt(path string) (*DB, error)

func (*DB) DeleteDirectory

func (db *DB) DeleteDirectory()

func (*DB) DeleteFile

func (db *DB) DeleteFile(path string) error

func (*DB) GetDirectory

func (db *DB) GetDirectory(directory string) ([]*DriveFile, error)

func (*DB) GetFile

func (db *DB) GetFile(path string) (*DriveFile, error)

func (*DB) UpdateFile

func (db *DB) UpdateFile(ds []*DriveFile) error

type DriveFile

type DriveFile struct {
	Id           string `json:"id"`
	Name         string `json:"name"`
	Size         uint64 `json:"size"`
	ModifiedTime int64  `json:"modifiedTime"`
	Path         string `json:"path"`
	DownloadUrl  string `json:"@microsoft.graph.downloadUrl"`
	MimeType     string `json:"mimeType"`
	ChildCount   uint64 `json:"childCount"`
	UpdateTime   int64  `json:"updateTime"`
}

func FilterFile

func FilterFile(localFile, remoteFile []*DriveFile) (insertFiles, updateFiles, deleteFiles []*DriveFile)

func ParseToDriveFile

func ParseToDriveFile(b []byte) (*DriveFile, error)

func SortDriveFile

func SortDriveFile(driveFiles []*DriveFile) (files, folders []*DriveFile)

func (*DriveFile) HandleRootPath

func (d *DriveFile) HandleRootPath(rootPath string) *DriveFile

func (*DriveFile) ToBytes

func (d *DriveFile) ToBytes() []byte

type DriveFiles

type DriveFiles []*DriveFile

func (DriveFiles) HandleRootPath

func (ds DriveFiles) HandleRootPath(rootPath string) DriveFiles

type DriveItemPreviewResp

type DriveItemPreviewResp struct {
	GetUrl string `json:"getUrl"`
}

type DrivePathChildren

type DrivePathChildren struct {
	NextLink   string       `json:"nextLink"`
	DrivePaths []*DriveFile `json:"drivePaths"`
}

type DrivePathChildrenResp

type DrivePathChildrenResp struct {
	NextLink       string          `json:"@odata.nextLink"`
	DrivePathResps []DrivePathResp `json:"value"`
}

func (*DrivePathChildrenResp) Folders

func (d *DrivePathChildrenResp) Folders() []string

func (DrivePathChildrenResp) ToDrivePathChildren

func (d DrivePathChildrenResp) ToDrivePathChildren() *DrivePathChildren

type DrivePathResp

type DrivePathResp struct {
	Id                   string          `json:"id"`
	Name                 string          `json:"name"`
	Size                 uint64          `json:"size"`
	LastModifiedDateTime string          `json:"lastModifiedDateTime"`
	DownloadUrl          string          `json:"@microsoft.graph.downloadUrl"`
	ParentReference      ParentReference `json:"parentReference"`
	Folder               *Folder         `json:"folder"`
	File                 *File           `json:"file"`
}

func (*DrivePathResp) ChildCount

func (d *DrivePathResp) ChildCount() uint64

func (*DrivePathResp) FormatTime

func (d *DrivePathResp) FormatTime(formatLocation, timeFromFormat string) int64

func (*DrivePathResp) MimeType

func (d *DrivePathResp) MimeType() string

func (*DrivePathResp) Path

func (d *DrivePathResp) Path() string

func (*DrivePathResp) ToDriveFile

func (d *DrivePathResp) ToDriveFile() *DriveFile

type File

type File struct {
	MimeType string `json:"mimeType"`
}

type Folder

type Folder struct {
	ChildCount uint64 `json:"childCount"`
}

type Graph

type Graph struct {
	AccessToken string `json:"access_token"`
}

func NewGraph

func NewGraph(token string) *Graph

func (*Graph) GetDriveItemPreview

func (g *Graph) GetDriveItemPreview(itemId string) (resp *DriveItemPreviewResp, err error)

func (*Graph) GetDrivePath

func (g *Graph) GetDrivePath(path string) (resp *DrivePathResp, err error)

func (*Graph) GetDrivePathChildren

func (g *Graph) GetDrivePathChildren(path string) (resp *DrivePathChildrenResp, err error)
func (g *Graph) GetDrivePathChildrenNextLink(nextLink string) (resp *DrivePathChildrenResp, err error)

type OneDrive

type OneDrive struct {
	// contains filtered or unexported fields
}

func NewOneDrive

func NewOneDrive(database string, cfg *Config) (*OneDrive, error)

func (*OneDrive) Cfg

func (od *OneDrive) Cfg() Config

func (*OneDrive) CheckUpdate

func (od *OneDrive) CheckUpdate(path string) (bool, error)

func (*OneDrive) ClearRepository

func (od *OneDrive) ClearRepository(path string) error

func (*OneDrive) GetFile

func (od *OneDrive) GetFile(path string) (driveFile *DriveFile, driveFileChildren, driveFolderChildren []*DriveFile, err error)

func (*OneDrive) RefreshDownloadUrl

func (od *OneDrive) RefreshDownloadUrl(driveFile *DriveFile) error

func (*OneDrive) RefreshToken

func (od *OneDrive) RefreshToken() error

func (*OneDrive) SyncRepository

func (od *OneDrive) SyncRepository(path string) error

type ParentReference

type ParentReference struct {
	DriveId   string `json:"driveId"`
	DriveType string `json:"driveType"`
	Path      string `json:"path"`
}

type Repository

type Repository interface {
	GetFile(path string) (*DriveFile, error)
	GetDirectory(directory string) ([]*DriveFile, error)
	UpdateFile(ds []*DriveFile) error
	DeleteFile(path string) error
}

type Token

type Token struct {
	TokenType    string `json:"token_type"`
	ExpiresIn    int64  `json:"expires_in"`
	Scope        string `json:"scope"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ModifiedTime int64  `json:"modified_time"`
}

func (*Token) Bytes

func (t *Token) Bytes() []byte

func (*Token) String

func (t *Token) String() string

Package Files

  • auth.go
  • config.go
  • graph.go
  • onedrive.go
  • repository.go
  • struct.go
  • util.go
Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier