From 9cb548d4f7c792a84b9d04f09e49a7bbb96cbf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Sat, 27 Feb 2021 20:06:09 +0800 Subject: [PATCH] =?UTF-8?q?:star:=20=E8=B7=B3=E8=BF=87=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alidrive/req_bean.go | 1 + alidrive/request.go | 4 ++-- alidrive/resp_bean.go | 26 +++++++++++++++++++------- bootstrap/cmd.go | 5 ++++- conf/const.go | 2 ++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/alidrive/req_bean.go b/alidrive/req_bean.go index fea1cc4a..da7cf3cc 100644 --- a/alidrive/req_bean.go +++ b/alidrive/req_bean.go @@ -27,6 +27,7 @@ type DownloadReq struct { DriveId string `json:"drive_id"` FileId string `json:"file_id"` ExpireSec int `json:"expire_sec"` + FileName string `json:"file_name"` } // search request bean diff --git a/alidrive/request.go b/alidrive/request.go index 4fad0f3c..351268f2 100644 --- a/alidrive/request.go +++ b/alidrive/request.go @@ -29,14 +29,14 @@ func GetFile(fileId string) (*File, error) { } // get download_url -func GetDownLoadUrl(fileId string) (*File, error) { +func GetDownLoadUrl(fileId string) (*DownloadResp, error) { url:=conf.Conf.AliDrive.ApiUrl+"/file/get_download_url" req:=DownloadReq{ DriveId: User.DefaultDriveId, FileId: fileId, ExpireSec: 14400, } - var resp File + var resp DownloadResp if err := BodyToJson(url, req, &resp, true); err!=nil { return nil,err } diff --git a/alidrive/resp_bean.go b/alidrive/resp_bean.go index 5f787fd3..ce786ff0 100644 --- a/alidrive/resp_bean.go +++ b/alidrive/resp_bean.go @@ -10,9 +10,9 @@ import ( // response bean methods type RespHandle interface { - IsAvailable() bool // check available - GetCode() string // get err code - GetMessage() string // get err message + IsAvailable() bool // check available + GetCode() string // get err code + GetMessage() string // get err message SetCode(code string) // set err code } @@ -26,16 +26,16 @@ func (resp *RespError) IsAvailable() bool { return resp.Code == "" } -func (resp *RespError)GetCode() string { +func (resp *RespError) GetCode() string { return resp.Code } -func (resp *RespError)GetMessage() string { +func (resp *RespError) GetMessage() string { return resp.Message } -func (resp *RespError)SetCode(code string) { - resp.Code=code +func (resp *RespError) SetCode(code string) { + resp.Code = code } // user_info response bean @@ -104,6 +104,18 @@ type File struct { Paths []Path `json:"paths"` } +type DownloadResp struct { + RespError + Expiration string `json:"expiration"` + Method string `json:"method"` + Size int64 `json:"size"` + Url string `json:"url"` + //RateLimit struct{ + // PartSize int `json:"part_size"` + // PartSpeed int `json:"part_speed"` + //} `json:"rate_limit"`//rate limit +} + // token_login response bean type TokenLoginResp struct { RespError diff --git a/bootstrap/cmd.go b/bootstrap/cmd.go index 8a82621a..bdf5a758 100644 --- a/bootstrap/cmd.go +++ b/bootstrap/cmd.go @@ -14,6 +14,7 @@ func init() { flag.BoolVar(&conf.Help,"help",false,"show usage help") flag.BoolVar(&conf.Version,"version",false,"show version info") flag.StringVar(&conf.Con,"conf","conf.yml","config file") + flag.BoolVar(&conf.SkipUpdate,"skip-update",false,"skip update") } // bootstrap run @@ -48,7 +49,9 @@ func printASC() { func start() { InitLog() printASC() - CheckUpdate() + if !conf.SkipUpdate { + CheckUpdate() + } if !ReadConf(conf.Con) { log.Errorf("读取配置文件时出现错误,启动失败.") return diff --git a/conf/const.go b/conf/const.go index 1547602c..6f899b69 100644 --- a/conf/const.go +++ b/conf/const.go @@ -10,6 +10,8 @@ var( Help bool // is help command Version bool // is print version command Con string // config file + SkipUpdate bool // skip update + Client *http.Client // request client Authorization string // authorization string