-
Notifications
You must be signed in to change notification settings - Fork 738
Expand file tree
/
Copy pathSingleController.go
More file actions
72 lines (60 loc) · 1.58 KB
/
SingleController.go
File metadata and controls
72 lines (60 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package AdminControllers
import (
"net/http"
"time"
"github.com/astaxie/beego/orm"
"DocHub/models"
)
type SingleController struct {
BaseController
}
//单页列表
func (this *SingleController) Get() {
this.Data["IsSingle"] = true
this.Data["Lists"], _, _ = models.NewPages().List(1000)
this.TplName = "index.html"
}
//单页编辑,只编辑文本内容
func (this *SingleController) Edit() {
var (
page models.Pages
cs *models.CloudStore
err error
)
cs, err = models.NewCloudStore(false)
if err != nil {
this.CustomAbort(http.StatusInternalServerError, err.Error())
}
this.Data["IsSingle"] = true
alias := this.GetString(":alias")
if this.Ctx.Request.Method == "POST" {
this.ParseForm(&page)
page.TimeCreate = int(time.Now().Unix())
page.Content = cs.ImageWithoutDomain(page.Content)
_, err := orm.NewOrm().Update(&page)
if err != nil {
this.ResponseJson(false, err.Error())
}
this.ResponseJson(true, "更新成功")
} else {
page, _ = models.NewPages().One(alias)
page.Content = cs.ImageWithDomain(page.Content)
this.Data["Data"] = page
this.TplName = "edit.html"
}
}
//删除单页
func (this *SingleController) Del() {
id, _ := this.GetInt("id")
var page = models.Pages{Id: id}
err := orm.NewOrm().Read(&page)
if err != nil {
this.ResponseJson(false, err.Error())
}
if _, err = orm.NewOrm().QueryTable(models.GetTablePages()).Filter("Id", page.Id).Delete(); err != nil {
this.ResponseJson(false, err.Error())
}
cs, _ := models.NewCloudStore(false)
go cs.DeleteImageFromHtml(page.Content)
this.ResponseJson(true, "删除成功")
}