update controller
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
|||||||
"gopkg.in/mgo.v2/bson"
|
"gopkg.in/mgo.v2/bson"
|
||||||
. "github.com/leanote/leanote/app/lea"
|
. "github.com/leanote/leanote/app/lea"
|
||||||
"github.com/leanote/leanote/app/info"
|
"github.com/leanote/leanote/app/info"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
"strings"
|
||||||
// "time"
|
// "time"
|
||||||
// "github.com/leanote/leanote/app/types"
|
// "github.com/leanote/leanote/app/types"
|
||||||
@ -292,206 +291,6 @@ func (c Note) SearchNoteByTags(tags []string) revel.Result {
|
|||||||
return c.RenderJson(blogs)
|
return c.RenderJson(blogs)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------
|
|
||||||
// html2image
|
|
||||||
// 判断是否有权限生成
|
|
||||||
// 博客也可以调用
|
|
||||||
// 这是脚本调用, 没有cookie, 不执行权限控制, 通过传来的appKey判断
|
|
||||||
func (c Note) ToImage(noteId, appKey string) revel.Result {
|
|
||||||
// 虽然传了cookie但是这里还是不能得到userId, 所以还是通过appKey来验证之
|
|
||||||
/*
|
|
||||||
appKeyTrue, _ := revel.Config.String("app.secret")
|
|
||||||
if appKeyTrue != appKey {
|
|
||||||
return c.RenderText("")
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
note := noteService.GetNoteById(noteId)
|
|
||||||
if note.NoteId == "" {
|
|
||||||
return c.RenderText("")
|
|
||||||
}
|
|
||||||
|
|
||||||
c.SetLocale()
|
|
||||||
|
|
||||||
noteUserId := note.UserId.Hex()
|
|
||||||
content := noteService.GetNoteContent(noteId, noteUserId)
|
|
||||||
userInfo := userService.GetUserInfo(noteUserId);
|
|
||||||
|
|
||||||
c.RenderArgs["blog"] = note
|
|
||||||
c.RenderArgs["content"] = content.Content
|
|
||||||
c.RenderArgs["userInfo"] = userInfo
|
|
||||||
userBlog := blogService.GetUserBlog(noteUserId)
|
|
||||||
c.RenderArgs["userBlog"] = userBlog
|
|
||||||
|
|
||||||
return c.RenderTemplate("html2Image/index.html")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c Note) Html2Image(noteId string) revel.Result {
|
|
||||||
re := info.NewRe()
|
|
||||||
userId := c.GetUserId()
|
|
||||||
note := noteService.GetNoteById(noteId)
|
|
||||||
if note.NoteId == "" {
|
|
||||||
re.Msg = "No Note"
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
|
|
||||||
noteUserId := note.UserId.Hex()
|
|
||||||
// 是否有权限
|
|
||||||
if noteUserId != userId {
|
|
||||||
// 是否是有权限协作的
|
|
||||||
if !note.IsBlog && !shareService.HasReadPerm(noteUserId, userId, noteId) {
|
|
||||||
re.Msg = "No Perm"
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// path 判断是否需要重新生成之
|
|
||||||
fileUrlPath := "/upload/" + noteUserId + "/images/weibo"
|
|
||||||
dir := revel.BasePath + "/public/" + fileUrlPath
|
|
||||||
if !ClearDir(dir) {
|
|
||||||
re.Msg = "No Dir"
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
|
|
||||||
filename := note.NoteId.Hex() + ".png";
|
|
||||||
path := dir + "/" + filename
|
|
||||||
|
|
||||||
// cookie
|
|
||||||
cookieName := revel.CookiePrefix + "_SESSION"
|
|
||||||
cookie, err := c.Request.Cookie(cookieName)
|
|
||||||
cookieStr := cookie.String()
|
|
||||||
cookieValue := ""
|
|
||||||
if err == nil && len(cookieStr) > len(cookieName) {
|
|
||||||
cookieValue = cookieStr[len(cookieName)+1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
appKey, _ := revel.Config.String("app.secret")
|
|
||||||
cookieDomain, _ := revel.Config.String("cookie.domain")
|
|
||||||
// 生成之
|
|
||||||
url := configService.GetSiteUrl() + "/note/toImage?noteId=" + noteId + "&appKey=" + appKey;
|
|
||||||
// /Users/life/Documents/bin/phantomjs/bin/phantomjs /Users/life/Desktop/test/b.js
|
|
||||||
binPath := configService.GetGlobalStringConfig("toImageBinPath")
|
|
||||||
if binPath == "" {
|
|
||||||
return c.RenderJson(re);
|
|
||||||
}
|
|
||||||
cc := binPath + " \"" + url + "\" \"" + path + "\" \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\""
|
|
||||||
cmd := exec.Command("/bin/sh", "-c", cc)
|
|
||||||
Log(cc);
|
|
||||||
b, err := cmd.Output()
|
|
||||||
if err == nil {
|
|
||||||
re.Ok = true
|
|
||||||
re.Id = fileUrlPath + "/" + filename
|
|
||||||
} else {
|
|
||||||
re.Msg = string(b)
|
|
||||||
Log("error:......")
|
|
||||||
Log(string(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.RenderJson(re)
|
|
||||||
|
|
||||||
/*
|
|
||||||
// 这里速度慢, 生成不完全(图片和内容都不全)
|
|
||||||
content := noteService.GetNoteContent(noteId, noteUserId)
|
|
||||||
userInfo := userService.GetUserInfo(noteUserId);
|
|
||||||
|
|
||||||
c.SetLocale()
|
|
||||||
|
|
||||||
c.RenderArgs["blog"] = note
|
|
||||||
c.RenderArgs["content"] = content.Content
|
|
||||||
c.RenderArgs["userInfo"] = userInfo
|
|
||||||
userBlog := blogService.GetUserBlog(noteUserId)
|
|
||||||
c.RenderArgs["userBlog"] = userBlog
|
|
||||||
|
|
||||||
html := c.RenderTemplateStr("html2Image/index.html") // Result类型的
|
|
||||||
contentFile := dir + "/html";
|
|
||||||
fout, err := os.Create(contentFile)
|
|
||||||
if err != nil {
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
fout.WriteString(html);
|
|
||||||
fout.Close()
|
|
||||||
|
|
||||||
cc := "/Users/life/Documents/bin/phantomjs/bin/phantomjs /Users/life/Desktop/test/c.js \"" + contentFile + "\" \"" + path + "\""
|
|
||||||
cmd := exec.Command("/bin/sh", "-c", cc)
|
|
||||||
b, err := cmd.Output()
|
|
||||||
if err == nil {
|
|
||||||
re.Ok = true
|
|
||||||
re.Id = fileUrlPath + "/" + filename
|
|
||||||
} else {
|
|
||||||
Log(string(b))
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 导出成PDF
|
|
||||||
func (c Note) ExportPdf(noteId string) revel.Result {
|
|
||||||
re := info.NewRe()
|
|
||||||
userId := c.GetUserId()
|
|
||||||
note := noteService.GetNoteById(noteId)
|
|
||||||
if note.NoteId == "" {
|
|
||||||
re.Msg = "No Note"
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
|
|
||||||
noteUserId := note.UserId.Hex()
|
|
||||||
// 是否有权限
|
|
||||||
if noteUserId != userId {
|
|
||||||
// 是否是有权限协作的
|
|
||||||
if !note.IsBlog && !shareService.HasReadPerm(noteUserId, userId, noteId) {
|
|
||||||
re.Msg = "No Perm"
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// path 判断是否需要重新生成之
|
|
||||||
fileUrlPath := "upload/" + noteUserId + "/images/weibo"
|
|
||||||
dir := revel.BasePath + "/public/" + fileUrlPath
|
|
||||||
if !ClearDir(dir) {
|
|
||||||
re.Msg = "No Dir"
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
filename := note.Title + ".pdf";
|
|
||||||
if note.Title == "" {
|
|
||||||
filename = "Untitled.pdf";
|
|
||||||
}
|
|
||||||
path := dir + "/" + filename
|
|
||||||
|
|
||||||
// cookie
|
|
||||||
cookieName := revel.CookiePrefix + "_SESSION"
|
|
||||||
cookie, err := c.Request.Cookie(cookieName)
|
|
||||||
cookieStr := cookie.String()
|
|
||||||
cookieValue := ""
|
|
||||||
if err == nil && len(cookieStr) > len(cookieName) {
|
|
||||||
cookieValue = cookieStr[len(cookieName)+1:]
|
|
||||||
}
|
|
||||||
Log(cookieValue)
|
|
||||||
|
|
||||||
appKey, _ := revel.Config.String("app.secret")
|
|
||||||
// cookieDomain, _ := revel.Config.String("cookie.domain")
|
|
||||||
// 生成之
|
|
||||||
url := configService.GetSiteUrl() + "/note/toImage?noteId=" + noteId + "&appKey=" + appKey;
|
|
||||||
// /Users/life/Documents/bin/phantomjs/bin/phantomjs /Users/life/Desktop/test/b.js
|
|
||||||
binPath := "/usr/local/bin/wkhtmltopdf" // configService.GetGlobalStringConfig("toImageBinPath")
|
|
||||||
if binPath == "" {
|
|
||||||
return c.RenderJson(re);
|
|
||||||
}
|
|
||||||
// cc := binPath + " \"" + url + "\" \"" + path + "\" \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\""
|
|
||||||
cc := binPath + " \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\""
|
|
||||||
cmd := exec.Command("/bin/sh", "-c", cc)
|
|
||||||
Log(cc);
|
|
||||||
b, err := cmd.Output()
|
|
||||||
if err == nil {
|
|
||||||
re.Ok = true
|
|
||||||
re.Id = fileUrlPath + "/" + filename
|
|
||||||
} else {
|
|
||||||
re.Msg = string(b)
|
|
||||||
Log("error:......")
|
|
||||||
Log(string(b))
|
|
||||||
}
|
|
||||||
|
|
||||||
return c.RenderJson(re)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置/取消Blog; 置顶
|
// 设置/取消Blog; 置顶
|
||||||
func (c Note) SetNote2Blog(noteId string, isBlog, isTop bool) revel.Result {
|
func (c Note) SetNote2Blog(noteId string, isBlog, isTop bool) revel.Result {
|
||||||
re := noteService.ToBlog(c.GetUserId(), noteId, isBlog, isTop)
|
re := noteService.ToBlog(c.GetUserId(), noteId, isBlog, isTop)
|
||||||
|
@ -37,8 +37,6 @@ POST /findPasswordUpdate Auth.FindPasswordUpdate
|
|||||||
* /note/copyNote Note.CopyNote
|
* /note/copyNote Note.CopyNote
|
||||||
* /note/copySharedNote Note.CopySharedNote
|
* /note/copySharedNote Note.CopySharedNote
|
||||||
* /note/searchNoteByTags Note.SearchNoteByTags
|
* /note/searchNoteByTags Note.SearchNoteByTags
|
||||||
* /note/toImage Note.ToImage
|
|
||||||
* /note/html2Image Note.Html2Image
|
|
||||||
* /note/setNote2Blog Note.SetNote2Blog
|
* /note/setNote2Blog Note.SetNote2Blog
|
||||||
# pjax
|
# pjax
|
||||||
GET /note/:noteId Note.Index
|
GET /note/:noteId Note.Index
|
||||||
|
Reference in New Issue
Block a user