config

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright (c) 2020 tickstep.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// EnvVerbose 启用调试环境变量
	EnvVerbose = "ALIYUNPAN_VERBOSE"
	// EnvConfigDir 配置路径环境变量
	EnvConfigDir = "ALIYUNPAN_CONFIG_DIR"
	// ConfigName 配置文件名
	ConfigName = "aliyunpan_config.json"
	// ConfigVersion 配置文件版本
	ConfigVersion string = "1.0"

	// DefaultFileUploadParallelNum 默认的文件上传并发数量
	DefaultFileUploadParallelNum = 10

	// MaxFileUploadParallelNum 最大文件上传并发数量。过大会被阿里云盘风控,导致无法上传
	MaxFileUploadParallelNum = 20

	// DefaultFileDownloadParallelNum 默认的文件下载并发数量
	DefaultFileDownloadParallelNum = 5

	// MaxFileDownloadParallelNum 最大文件下载并发数量。过大会被阿里云盘风控,导致无法下载
	MaxFileDownloadParallelNum = 20

	// DefaultTokenServiceWebHost 默认的token服务
	DefaultTokenServiceWebHost = "https://api.tickstep.com"
)

Variables

View Source
var (
	//ErrNotLogin 未登录帐号错误
	ErrNotLogin = errors.New("user not login")
	//ErrConfigFilePathNotSet 未设置配置文件
	ErrConfigFilePathNotSet = errors.New("config file not set")
	//ErrConfigFileNotExist 未设置Config, 未初始化
	ErrConfigFileNotExist = errors.New("config file not exist")
	//ErrConfigFileNoPermission Config文件无权限访问
	ErrConfigFileNoPermission = errors.New("config file permission denied")
	//ErrConfigContentsParseError 解析Config数据错误
	ErrConfigContentsParseError = errors.New("config contents parse error")
)
View Source
var (
	CmdConfigVerbose = logger.New("CONFIG", EnvVerbose)

	// Config 配置信息, 由外部调用
	Config = NewConfig(configFilePath)

	AppVersion string
)

Functions

func AverageParallel

func AverageParallel(parallel, downloadLoad int) int

AverageParallel 返回平均的下载最大并发量

func DecryptString

func DecryptString(text string) string

DecryptString 解密

func EncryptString

func EncryptString(text string) string

EncryptString 加密

func GetConfigDir

func GetConfigDir() string

GetConfigDir 获取配置路径

func GetLogDir added in v0.1.7

func GetLogDir() string

GetLogDir 获取日志文件目录路径

func GetLogFilePath added in v0.1.7

func GetLogFilePath() string

GetLogFilePath 获取日志文件路径

func GetPluginDir added in v0.1.4

func GetPluginDir() string

GetPluginDir 获取插件文件夹路径

func GetSyncDriveDir added in v0.1.6

func GetSyncDriveDir() string

GetSyncDriveDir 获取同步备份的文件夹路径

func IsFolderExist added in v0.1.0

func IsFolderExist(pathStr string) bool

isFolderExist 判断文件夹是否存在

Types

type DriveInfo

type DriveInfo struct {
	DriveId   string `json:"driveId"`
	DriveName string `json:"driveName"`
	DriveTag  string `json:"driveTag"`
}

func (*DriveInfo) IsAlbumDrive

func (di *DriveInfo) IsAlbumDrive() bool

func (*DriveInfo) IsFileDrive

func (di *DriveInfo) IsFileDrive() bool

type DriveInfoList

type DriveInfoList []*DriveInfo

func (DriveInfoList) GetAlbumDriveId added in v0.1.3

func (d DriveInfoList) GetAlbumDriveId() string

func (DriveInfoList) GetFileDriveId added in v0.0.7

func (d DriveInfoList) GetFileDriveId() string

type PanConfig

type PanConfig struct {
	ConfigVer string `json:"configVer"`
	ActiveUID string `json:"activeUID"`

	UserList PanUserList `json:"userList"`

	CacheSize           int `json:"cacheSize"`           // 下载缓存
	MaxDownloadParallel int `json:"maxDownloadParallel"` // 最大下载并发量,即同时下载文件最大数量
	MaxUploadParallel   int `json:"maxUploadParallel"`   // 最大上传并发量,即同时上传文件最大数量

	MaxDownloadRate int64 `json:"maxDownloadRate"` // 限制最大下载速度,单位 B/s, 即字节/每秒
	MaxUploadRate   int64 `json:"maxUploadRate"`   // 限制最大上传速度,单位 B/s, 即字节/每秒
	TransferUrlType int   `json:"transferUrlType"` // 上传/下载URL类别,1-默认,2-阿里云ECS

	SaveDir string `json:"saveDir"` // 下载储存路径

	Proxy           string          `json:"proxy"`      // 代理
	LocalAddrs      string          `json:"localAddrs"` // 本地网卡地址
	UpdateCheckInfo UpdateCheckInfo `json:"updateCheckInfo"`
	// contains filtered or unexported fields
}

PanConfig 配置详情

func NewConfig

func NewConfig(configFilePath string) *PanConfig

NewConfig 返回 PanConfig 指针对象

func (*PanConfig) ActiveUser

func (c *PanConfig) ActiveUser() *PanUser

func (*PanConfig) Close

func (c *PanConfig) Close() error

Close 关闭配置文件

func (*PanConfig) DeleteUser

func (c *PanConfig) DeleteUser(uid string) (*PanUser, error)

DeleteUser 删除用户,并自动切换登录用户为用户列表第一个

func (*PanConfig) HTTPClient

func (c *PanConfig) HTTPClient(ua string) *requester.HTTPClient

HTTPClient 返回设置好的 HTTPClient

func (*PanConfig) Init

func (c *PanConfig) Init() error

Init 初始化配置

func (*PanConfig) NumLogins

func (c *PanConfig) NumLogins() int

NumLogins 获取登录的用户数量

func (*PanConfig) PrintTable

func (c *PanConfig) PrintTable()

PrintTable 输出表格

func (*PanConfig) Reload

func (c *PanConfig) Reload() error

Reload 从文件重载配置

func (*PanConfig) Save

func (c *PanConfig) Save() error

Save 保存配置信息到配置文件

func (*PanConfig) SetActiveUser

func (c *PanConfig) SetActiveUser(user *PanUser) *PanUser

func (*PanConfig) SetCacheSizeByStr

func (c *PanConfig) SetCacheSizeByStr(sizeStr string) error

SetCacheSizeByStr 设置cache_size

func (*PanConfig) SetLocalAddrs

func (c *PanConfig) SetLocalAddrs(localAddrs string)

SetLocalAddrs 设置localAddrs

func (*PanConfig) SetMaxDownloadRateByStr

func (c *PanConfig) SetMaxDownloadRateByStr(sizeStr string) error

SetMaxDownloadRateByStr 设置 max_download_rate

func (*PanConfig) SetMaxUploadRateByStr

func (c *PanConfig) SetMaxUploadRateByStr(sizeStr string) error

SetMaxUploadRateByStr 设置 max_upload_rate

func (*PanConfig) SetProxy

func (c *PanConfig) SetProxy(proxy string)

SetProxy 设置代理

func (*PanConfig) SwitchUser

func (c *PanConfig) SwitchUser(uid, username string) (*PanUser, error)

SwitchUser 切换登录用户

type PanUser

type PanUser struct {
	UserId      string `json:"userId"`
	Nickname    string `json:"nickname"`
	AccountName string `json:"accountName"`

	Workdir           string               `json:"workdir"`
	WorkdirFileEntity aliyunpan.FileEntity `json:"workdirFileEntity"`

	AlbumWorkdir           string               `json:"albumWorkdir"`
	AlbumWorkdirFileEntity aliyunpan.FileEntity `json:"albumWorkdirFileEntity"`

	ActiveDriveId string        `json:"activeDriveId"`
	DriveList     DriveInfoList `json:"driveList"`

	RefreshToken string                  `json:"refreshToken"`
	WebToken     aliyunpan.WebLoginToken `json:"webToken"`
	TokenId      string                  `json:"tokenId"`
	// contains filtered or unexported fields
}

func SetupUserByCookie

func SetupUserByCookie(webToken *aliyunpan.WebLoginToken) (user *PanUser, err *apierror.ApiError)

func (*PanUser) CacheFilesDirectoriesList added in v0.0.4

func (pu *PanUser) CacheFilesDirectoriesList(pathStr string) (fdl aliyunpan.FileList, apiError *apierror.ApiError)

CacheFilesDirectoriesList 缓存获取

func (*PanUser) DeleteCache added in v0.0.5

func (pu *PanUser) DeleteCache(dirs []string)

DeleteCache 删除含有 dirs 的缓存

func (*PanUser) DeleteOneCache added in v0.0.5

func (pu *PanUser) DeleteOneCache(dirPath string)

DeleteOneCache 删除缓存

func (*PanUser) FreshWorkdirInfo

func (pu *PanUser) FreshWorkdirInfo()

func (*PanUser) GetActiveDriveInfo

func (pu *PanUser) GetActiveDriveInfo() *DriveInfo

func (*PanUser) GetDriveById

func (pu *PanUser) GetDriveById(id string) *DriveInfo

func (*PanUser) GetDriveByTag

func (pu *PanUser) GetDriveByTag(tag string) *DriveInfo

func (*PanUser) GetSavePath

func (pu *PanUser) GetSavePath(filePanPath string) string

GetSavePath 根据提供的网盘文件路径 panpath, 返回本地储存路径, 返回绝对路径, 获取绝对路径出错时才返回相对路径...

func (*PanUser) IsAlbumDriveActive

func (pu *PanUser) IsAlbumDriveActive() bool

func (*PanUser) IsFileDriveActive

func (pu *PanUser) IsFileDriveActive() bool

func (*PanUser) PanClient

func (pu *PanUser) PanClient() *aliyunpan.PanClient

func (*PanUser) PathJoin

func (pu *PanUser) PathJoin(driveId, p string) string

PathJoin 合并工作目录和相对路径p, 若p为绝对路径则忽略

type PanUserList

type PanUserList []*PanUser

func (*PanUserList) String

func (pl *PanUserList) String() string

type UpdateCheckInfo

type UpdateCheckInfo struct {
	PreferUpdateSrv string `json:"preferUpdateSrv"` // 优先更新服务器,github | tickstep
	LatestVer       string `json:"latestVer"`       // 最后检测到的版本
	CheckTime       int64  `json:"checkTime"`       // 最后检测的时间戳,单位为秒
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL