diff --git a/api.go b/api.go index 2c6c273..9768414 100644 --- a/api.go +++ b/api.go @@ -89,7 +89,9 @@ func apiBlog(c *gin.Context) { return } - err := UpdateAccountField(mgo.M{"$set": mgo.M{"blogger.blogname": bn, "blogger.btitle": bt, "blogger.beian": ba, "blogger.subtitle": st, "blogger.seriessay": ss, "blogger.archivessay": as}}) + err := UpdateAccountField(mgo.M{"$set": mgo.M{"blogger.blogname": bn, + "blogger.btitle": bt, "blogger.beian": ba, "blogger.subtitle": st, + "blogger.seriessay": ss, "blogger.archivessay": as}}) if err != nil { responseNotice(c, NOTICE_NOTICE, err.Error(), "") return @@ -335,7 +337,7 @@ func apiSerieAdd(c *gin.Context) { responseNotice(c, NOTICE_SUCCESS, "操作成功", "") } -// 暂未启用 +// NOTE 暂未启用 func apiSerieSort(c *gin.Context) { err := c.Request.ParseForm() if err != nil { diff --git a/front.go b/front.go index c8a322c..5a2e940 100644 --- a/front.go +++ b/front.go @@ -379,7 +379,8 @@ func HandleDisqus(c *gin.Context) { } // 发表评论 -// [thread:[5279901489] parent:[] identifier:[post-troubleshooting-https] next:[] author_name:[你好] author_email:[chenqijing2@163.com] message:[fdsfdsf]] +// [thread:[5279901489] parent:[] identifier:[post-troubleshooting-https] +// next:[] author_name:[你好] author_email:[chenqijing2@163.com] message:[fdsfdsf]] type DisqusCreate struct { ErrNo int `json:"errno"` ErrMsg string `json:"errmsg"` diff --git a/ping.go b/ping.go index b46dc95..dd31f71 100644 --- a/ping.go +++ b/ping.go @@ -3,6 +3,7 @@ package main import ( "bytes" "encoding/xml" + "fmt" "io/ioutil" "net/http" "net/url" @@ -64,7 +65,7 @@ func (p *pingRPC) PingFunc(slug string) { if len(setting.Conf.PingRPCs) == 0 { return } - p.Params.Param[1].Value = "https://" + setting.Conf.Mode.Domain + "/post/" + slug + ".html" + p.Params.Param[1].Value = fmt.Sprintf("https://%s/post/%s.html", setting.Conf.Mode.Domain, slug) buf := &bytes.Buffer{} buf.WriteString(xml.Header) enc := xml.NewEncoder(buf) diff --git a/qiniu.go b/qiniu.go index 205b48c..224cdd6 100644 --- a/qiniu.go +++ b/qiniu.go @@ -11,18 +11,6 @@ import ( "github.com/qiniu/api.v7/storage" ) -type bucket struct { - name string - domain string - accessKey string - secretKey string -} - -type PutRet struct { - Hash string `json:"hash"` - Key string `json:"key"` -} - // 进度条 func onProgress(fsize, uploaded int64) { d := int(float64(uploaded) / float64(fsize) * 100) @@ -40,10 +28,6 @@ func FileUpload(name string, size int64, data io.Reader) (string, error) { } key := getKey(name) - if key == "" { - return "", errors.New("不支持的文件类型") - } - mac := qbox.NewMac(setting.Conf.Qiniu.AccessKey, setting.Conf.Qiniu.SecretKey) // 设置上传的策略 putPolicy := &storage.PutPolicy{ @@ -62,7 +46,8 @@ func FileUpload(name string, size int64, data io.Reader) (string, error) { // uploader uploader := storage.NewFormUploader(cfg) ret := new(storage.PutRet) - putExtra := &storage.PutExtra{OnProgress: onProgress} + putExtra := &storage.PutExtra{} + err := uploader.Put(nil, ret, upToken, key, data, size, putExtra) if err != nil { return "", err @@ -75,9 +60,6 @@ func FileUpload(name string, size int64, data io.Reader) (string, error) { // 删除文件 func FileDelete(name string) error { key := getKey(name) - if key == "" { - return errors.New("不支持的文件类型") - } mac := qbox.NewMac(setting.Conf.Qiniu.AccessKey, setting.Conf.Qiniu.SecretKey) // 上传配置 @@ -104,9 +86,12 @@ func getKey(name string) string { key = "blog/img/" + name case ".mov", ".mp4": key = "blog/video/" + name - case ".go", ".js", ".css", ".cpp", ".php", ".rb", ".java", ".py", ".sql", ".lua", ".html", ".sh", ".xml", ".cs": + case ".go", ".js", ".css", ".cpp", ".php", ".rb", + ".java", ".py", ".sql", ".lua", ".html", + ".sh", ".xml", ".cs": key = "blog/code/" + name - case ".txt", ".md", ".ini", ".yaml", ".yml", ".doc", ".ppt", ".pdf": + case ".txt", ".md", ".ini", ".yaml", ".yml", + ".doc", ".ppt", ".pdf": key = "blog/document/" + name case ".zip", ".rar", ".tar", ".gz": key = "blog/archive/" + name