Add version feature for tank cli.

This commit is contained in:
zicla 2019-05-05 02:42:54 +08:00
parent 5625149766
commit 8dd524e89e
4 changed files with 26 additions and 17 deletions

View File

@ -11,18 +11,16 @@ const (
MATTER_ROOT = "root" MATTER_ROOT = "root"
//cache directory name. //cache directory name.
MATTER_CACHE = "cache" MATTER_CACHE = "cache"
//压缩文件的临时目录 //zip file temp directory.
MATTER_ZIP = "zip" MATTER_ZIP = "zip"
//matter名称最大长度
MATTER_NAME_MAX_LENGTH = 200 MATTER_NAME_MAX_LENGTH = 200
//matter文件夹最大深度 MATTER_NAME_MAX_DEPTH = 32
MATTER_NAME_MAX_DEPTH = 32
//matter name pattern //matter name pattern
MATTER_NAME_PATTERN = `[\\/:*?"<>|]` MATTER_NAME_PATTERN = `[\\/:*?"<>|]`
) )
/** /**
* 文件 * file
*/ */
type Matter struct { type Matter struct {
Base Base
@ -45,17 +43,16 @@ func (Matter) TableName() string {
return core.TABLE_PREFIX + "matter" return core.TABLE_PREFIX + "matter"
} }
// 获取该Matter的绝对路径。path代表的是相对路径。 // get matter's absolute path. the Path property is relative path in db.
func (this *Matter) AbsolutePath() string { func (this *Matter) AbsolutePath() string {
return GetUserFileRootDir(this.Username) + this.Path return GetUserMatterRootDir(this.Username) + this.Path
} }
// 获取该Matter的MimeType
func (this *Matter) MimeType() string { func (this *Matter) MimeType() string {
return util.GetMimeType(util.GetExtension(this.Name)) return util.GetMimeType(util.GetExtension(this.Name))
} }
//创建一个 ROOT 的matter主要用于统一化处理移动复制等内容。 //Create a root matter. It's convenient for copy and move
func NewRootMatter(user *User) *Matter { func NewRootMatter(user *User) *Matter {
matter := &Matter{} matter := &Matter{}
matter.Uuid = MATTER_ROOT matter.Uuid = MATTER_ROOT
@ -69,15 +66,15 @@ func NewRootMatter(user *User) *Matter {
return matter return matter
} }
//获取到用户文件的根目录。 //get user's root absolute path
func GetUserFileRootDir(username string) (rootDirPath string) { func GetUserMatterRootDir(username string) (rootDirPath string) {
rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ROOT) rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ROOT)
return rootDirPath return rootDirPath
} }
//获取到用户缓存的根目录。 //get user's cache absolute path
func GetUserCacheRootDir(username string) (rootDirPath string) { func GetUserCacheRootDir(username string) (rootDirPath string) {
rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_CACHE) rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_CACHE)
@ -85,7 +82,7 @@ func GetUserCacheRootDir(username string) (rootDirPath string) {
return rootDirPath return rootDirPath
} }
//获取到用户压缩临时文件的根目录。 //get user's zip absolute path
func GetUserZipRootDir(username string) (rootDirPath string) { func GetUserZipRootDir(username string) (rootDirPath string) {
rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ZIP) rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ZIP)

View File

@ -413,7 +413,7 @@ func (this *MatterService) createDirectory(request *http.Request, dirMatter *Mat
} }
//绝对路径 //绝对路径
absolutePath := GetUserFileRootDir(user.Username) + dirMatter.Path + "/" + name absolutePath := GetUserMatterRootDir(user.Username) + dirMatter.Path + "/" + name
//相对路径 //相对路径
relativePath := dirMatter.Path + "/" + name relativePath := dirMatter.Path + "/" + name

View File

@ -20,7 +20,7 @@ func (this *PreferenceDao) Fetch() *Preference {
if db.Error != nil { if db.Error != nil {
if db.Error.Error() == result.DB_ERROR_NOT_FOUND { if db.Error.Error() == result.DB_ERROR_NOT_FOUND {
preference.Name = "蓝眼云盘" preference.Name = "EyeblueTank"
preference.Version = core.VERSION preference.Version = core.VERSION
this.Create(preference) this.Create(preference)
return preference return preference

View File

@ -23,7 +23,7 @@ const (
MODE_MIRROR = "mirror" MODE_MIRROR = "mirror"
//将远程的一个文件爬取到蓝眼云盘中 //将远程的一个文件爬取到蓝眼云盘中
MODE_CRAWL = "crawl" MODE_CRAWL = "crawl"
//TODO:查看当前蓝眼云盘版本 //TODO: 查看当前蓝眼云盘版本
MODE_VERSION = "version" MODE_VERSION = "version"
) )
@ -86,6 +86,11 @@ func (this *TankApplication) Start() {
//直接web启动 //直接web启动
this.HandleWeb() this.HandleWeb()
} else if strings.ToLower(this.mode) == MODE_VERSION {
//直接web启动
this.HandleVersion()
} else { } else {
//准备蓝眼云盘地址 //准备蓝眼云盘地址
@ -256,3 +261,10 @@ func (this *TankApplication) HandleCrawl() {
} }
} }
//fetch the application version
func (this *TankApplication) HandleVersion() {
fmt.Printf("EyeblueTank %s\r\n", core.VERSION)
}