// 新建文章 func newPost(params interface{}) string { username := params.([]interface{})[1].(string) password := params.([]interface{})[2].(string) result := login(username, password) if result { str := com.ReadFile("views/rpcxml/response_new_post.xml") title := params.([]interface{})[3].(map[string]interface{})["title"].(string) content := params.([]interface{})[3].(map[string]interface{})["description"].(string) keywords := "" categories := params.([]interface{})[3].(map[string]interface{})["categories"] if categories != nil { cata := categories.([]interface{}) for _, v := range cata { keywords = fmt.Sprintf(keywords+"%s,", v.(string)) } keywords = strings.TrimSuffix(keywords, ",") } id, err := AddArticle(title, content, keywords, com.SubString(content, 0, 100), username) if err == nil { return fmt.Sprintf(str, id) } else { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "文章发布失败! 注意标题不能重名") } } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
func setCata(params interface{}) string { username := params.([]interface{})[1].(string) password := params.([]interface{})[2].(string) result := login(username, password) if result { return com.ReadFile("views/rpcxml/response_set_post_catalog.xml") } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
func getBlog(params interface{}) string { username := params.([]interface{})[1].(string) password := params.([]interface{})[2].(string) result := login(username, password) if result { host := beego.AppConfig.String("host") str := com.ReadFile("views/rpcxml/response_login.xml") return fmt.Sprintf(str, host+"/", 1, "独孤影", host+"/xmlrpc") } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
// 新建Catalog func newCata(params interface{}) string { username := params.([]interface{})[1].(string) password := params.([]interface{})[2].(string) result := login(username, password) name := params.([]interface{})[3].(map[string]interface{})["name"] id, _ := NewTag(name.(string)) if result { str := com.ReadFile("views/rpcxml/response_new_catalog.xml") return fmt.Sprintf(str, id) } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
func (this *XmlrpcController) Get() { str := com.ReadFile("views/rpcxml/rsd.xml") host := beego.AppConfig.String("host") result := fmt.Sprintf(str, host, host) this.Ctx.WriteString(result) this.ServeXml() }
func (this *Info) getLog(file string) string { path := filepath.Join(this.buildPath, this.sid, fmt.Sprintf("%d", this.id), file) if com.PathExist(path) { return com.ReadFile(path) } else { return "" } }
// 模版与应用版本匹配检查 func CheckTplVersion() { tmpVer := com.ReadFile("views/VERSION") if AppVer == tmpVer { return } else { log.Fatal("Template Version[", tmpVer, "] Not Matched App Version[", AppVer, "], Update and Rebuild Please.") return } }
// 编辑(更新)文章 func editPost(params interface{}) string { strId := params.([]interface{})[0].(string) username := params.([]interface{})[1].(string) password := params.([]interface{})[2].(string) result := login(username, password) if result { title := params.([]interface{})[3].(map[string]interface{})["title"].(string) content := params.([]interface{})[3].(map[string]interface{})["description"].(string) keywords := "" categories := params.([]interface{})[3].(map[string]interface{})["categories"] if categories != nil { cata := categories.([]interface{}) for _, v := range cata { keywords = fmt.Sprintf(keywords+"%s,", v.(string)) } keywords = strings.TrimSuffix(keywords, ",") } id, err := strconv.ParseInt(strId, 10, 64) if err != nil { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "非法文章ID") } var newArt Article newArt.Title = title newArt.Keywords = keywords newArt.Content = content err = UpdateArticle(id, "", newArt) if err == nil { return com.ReadFile("views/rpcxml/response_edit_post.xml") } else { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "文章发布失败! 注意标题不能重名") } } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
// 新建媒体文件 func newMedia(params interface{}) string { username := params.([]interface{})[1].(string) password := params.([]interface{})[2].(string) result := login(username, password) if result { name := params.([]interface{})[3].(map[string]interface{})["name"] filetype := params.([]interface{})[3].(map[string]interface{})["type"] bits := params.([]interface{})[3].(map[string]interface{})["bits"] err := utils.ParseMedia("static/upload/"+name.(string), bits.(string)) if nil != err { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "上传写入失败") } // 文件保存到OSS t := time.Now() ossFilename := fmt.Sprintf("%d/%d/%d/%s", t.Year(), t.Month(), t.Day(), name.(string)) err = utils.OssStore(ossFilename, "static/upload/"+name.(string)) if nil != err { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "图片保存到OSS失败") } else { os.Remove("./static/upload/" + name.(string)) id, err := AddFile(name.(string), ossFilename, "oss", filetype.(string)) if nil != err { log.Println(err) str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "图片信息添加到数据库失败") } str := com.ReadFile("views/rpcxml/response_new_media_object.xml") return fmt.Sprintf(str, id, name.(string), utils.OssGetURL(ossFilename), filetype.(string)) } } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
func (this *MapJsonController) Get() { staticMap := beego.AppConfig.String("static_map") content := com.ReadFile(staticMap) data, err := com.JsonDecode(content) if err != nil { this.Data["json"] = map[string]interface{}{"result": false, "msg": "can not get map.json"} } else { this.Data["json"] = data } this.ServeJson() }
// 删除文章 func deletePost(params interface{}) string { strId := params.([]interface{})[1].(string) username := params.([]interface{})[2].(string) password := params.([]interface{})[3].(string) result := login(username, password) id, err := strconv.ParseInt(strId, 10, 64) if err != nil { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "非法文章ID") } if result { _, err := DeleteArticle(id, "") if nil != err { str := com.ReadFile("views/rpcxml/response_failed.xml") return fmt.Sprintf(str, "文章删除失败!") } else { return com.ReadFile("views/rpcxml/response_delete_post.xml") } } else { return com.ReadFile("views/rpcxml/response_login_failed.xml") } }
// get the result func (this *Info) getResult(file string) int { path := filepath.Join(this.buildPath, this.sid, fmt.Sprintf("%d", this.id), file) if com.PathExist(path) { content := com.ReadFile(path) content = com.Strim(content) if result, err := strconv.Atoi(content); err != nil { log.Warnln(err) return -1 } else { return result } } else { return -1 } }
func (this *InstallController) Get() { o := orm.NewOrm() if com.FileExist("install.lock") { this.Abort("404") } else { sqls := com.ReadFile("etc/blog.sql") sqlArr := strings.Split(sqls, ";") for index, element := range sqlArr { this.Ctx.WriteString(fmt.Sprintf("[%d] ", index) + element) _, err := o.Raw(element).Exec() if err != nil { this.Ctx.WriteString(" ~~ ERROR!\n") } } utils.WriteFile("install.lock", " ") } }
// load map.json func loadMap() string { mapPath := beego.AppConfig.String("static_map") mapContent := com.ReadFile(mapPath) return mapContent }
func (this *UploadController) Get() { conf := com.ReadFile("conf/ueditor.json") this.Ctx.WriteString(conf) }