From 8dd524e89ed4c6af8f4ab76c92329809eeea7e7f Mon Sep 17 00:00:00 2001 From: zicla Date: Sun, 5 May 2019 02:42:54 +0800 Subject: [PATCH] Add version feature for tank cli. --- code/rest/matter_model.go | 25 +++++++++++-------------- code/rest/matter_service.go | 2 +- code/rest/preference_dao.go | 2 +- code/support/tank_application.go | 14 +++++++++++++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/code/rest/matter_model.go b/code/rest/matter_model.go index ac9fc6d..b6067ea 100644 --- a/code/rest/matter_model.go +++ b/code/rest/matter_model.go @@ -11,18 +11,16 @@ const ( MATTER_ROOT = "root" //cache directory name. MATTER_CACHE = "cache" - //压缩文件的临时目录 - MATTER_ZIP = "zip" - //matter名称最大长度 + //zip file temp directory. + MATTER_ZIP = "zip" MATTER_NAME_MAX_LENGTH = 200 - //matter文件夹最大深度 - MATTER_NAME_MAX_DEPTH = 32 + MATTER_NAME_MAX_DEPTH = 32 //matter name pattern MATTER_NAME_PATTERN = `[\\/:*?"<>|]` ) /** - * 文件。 + * file */ type Matter struct { Base @@ -45,17 +43,16 @@ func (Matter) TableName() string { 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 { - return GetUserFileRootDir(this.Username) + this.Path + return GetUserMatterRootDir(this.Username) + this.Path } -// 获取该Matter的MimeType func (this *Matter) MimeType() string { 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 { matter := &Matter{} matter.Uuid = MATTER_ROOT @@ -69,15 +66,15 @@ func NewRootMatter(user *User) *Matter { return matter } -//获取到用户文件的根目录。 -func GetUserFileRootDir(username string) (rootDirPath string) { +//get user's root absolute path +func GetUserMatterRootDir(username string) (rootDirPath string) { rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ROOT) return rootDirPath } -//获取到用户缓存的根目录。 +//get user's cache absolute path func GetUserCacheRootDir(username string) (rootDirPath string) { rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_CACHE) @@ -85,7 +82,7 @@ func GetUserCacheRootDir(username string) (rootDirPath string) { return rootDirPath } -//获取到用户压缩临时文件的根目录。 +//get user's zip absolute path func GetUserZipRootDir(username string) (rootDirPath string) { rootDirPath = fmt.Sprintf("%s/%s/%s", core.CONFIG.MatterPath(), username, MATTER_ZIP) diff --git a/code/rest/matter_service.go b/code/rest/matter_service.go index 77f4ff4..706c863 100644 --- a/code/rest/matter_service.go +++ b/code/rest/matter_service.go @@ -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 diff --git a/code/rest/preference_dao.go b/code/rest/preference_dao.go index 38c5879..8049853 100644 --- a/code/rest/preference_dao.go +++ b/code/rest/preference_dao.go @@ -20,7 +20,7 @@ func (this *PreferenceDao) Fetch() *Preference { if db.Error != nil { if db.Error.Error() == result.DB_ERROR_NOT_FOUND { - preference.Name = "蓝眼云盘" + preference.Name = "EyeblueTank" preference.Version = core.VERSION this.Create(preference) return preference diff --git a/code/support/tank_application.go b/code/support/tank_application.go index ed62954..2bf88b0 100644 --- a/code/support/tank_application.go +++ b/code/support/tank_application.go @@ -23,7 +23,7 @@ const ( MODE_MIRROR = "mirror" //将远程的一个文件爬取到蓝眼云盘中 MODE_CRAWL = "crawl" - //TODO:查看当前蓝眼云盘版本 + //TODO: 查看当前蓝眼云盘版本 MODE_VERSION = "version" ) @@ -86,6 +86,11 @@ func (this *TankApplication) Start() { //直接web启动 this.HandleWeb() + } else if strings.ToLower(this.mode) == MODE_VERSION { + + //直接web启动 + this.HandleVersion() + } 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) + +}