Support for leanote-chrome plugin
This commit is contained in:
@ -156,6 +156,16 @@ func (c Note) GetNoteAndContent(noteId string) revel.Result {
|
|||||||
return c.RenderJson(noteService.GetNoteAndContent(noteId, c.GetUserId()))
|
return c.RenderJson(noteService.GetNoteAndContent(noteId, c.GetUserId()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Note) GetNoteAndContentBySrc(src string) revel.Result {
|
||||||
|
noteId, noteAndContent := noteService.GetNoteAndContentBySrc(src, c.GetUserId())
|
||||||
|
ret := info.Re{}
|
||||||
|
if noteId != "" {
|
||||||
|
ret.Ok = true
|
||||||
|
ret.Item = noteAndContent
|
||||||
|
}
|
||||||
|
return c.RenderJson(ret)
|
||||||
|
}
|
||||||
|
|
||||||
// 得到内容
|
// 得到内容
|
||||||
func (c Note) GetNoteContent(noteId string) revel.Result {
|
func (c Note) GetNoteContent(noteId string) revel.Result {
|
||||||
noteContent := noteService.GetNoteContent(noteId, c.GetUserId())
|
noteContent := noteService.GetNoteContent(noteId, c.GetUserId())
|
||||||
@ -177,6 +187,7 @@ func (c Note) UpdateNoteOrContent(noteOrContent info.NoteOrContent) revel.Result
|
|||||||
NoteId: bson.ObjectIdHex(noteOrContent.NoteId),
|
NoteId: bson.ObjectIdHex(noteOrContent.NoteId),
|
||||||
NotebookId: bson.ObjectIdHex(noteOrContent.NotebookId),
|
NotebookId: bson.ObjectIdHex(noteOrContent.NotebookId),
|
||||||
Title: noteOrContent.Title,
|
Title: noteOrContent.Title,
|
||||||
|
Src: noteOrContent.Src, // 来源
|
||||||
Tags: strings.Split(noteOrContent.Tags, ","),
|
Tags: strings.Split(noteOrContent.Tags, ","),
|
||||||
Desc: noteOrContent.Desc,
|
Desc: noteOrContent.Desc,
|
||||||
ImgSrc: noteOrContent.ImgSrc,
|
ImgSrc: noteOrContent.ImgSrc,
|
||||||
|
@ -15,6 +15,8 @@ type Note struct {
|
|||||||
Title string `Title` // 标题
|
Title string `Title` // 标题
|
||||||
Desc string `Desc` // 描述, 非html
|
Desc string `Desc` // 描述, 非html
|
||||||
|
|
||||||
|
Src string `Src,omitempty` // 来源, 2016/4/22
|
||||||
|
|
||||||
ImgSrc string `ImgSrc` // 图片, 第一张缩略图地址
|
ImgSrc string `ImgSrc` // 图片, 第一张缩略图地址
|
||||||
Tags []string `Tags,omitempty`
|
Tags []string `Tags,omitempty`
|
||||||
|
|
||||||
@ -92,6 +94,7 @@ type NoteOrContent struct {
|
|||||||
UserId string
|
UserId string
|
||||||
Title string
|
Title string
|
||||||
Desc string
|
Desc string
|
||||||
|
Src string
|
||||||
ImgSrc string
|
ImgSrc string
|
||||||
Tags string
|
Tags string
|
||||||
Content string
|
Content string
|
||||||
@ -101,3 +104,9 @@ type NoteOrContent struct {
|
|||||||
FromUserId string // 为共享而新建
|
FromUserId string // 为共享而新建
|
||||||
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
|
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分开的
|
||||||
|
type NoteAndContentSep struct {
|
||||||
|
NoteInfo Note
|
||||||
|
NoteContentInfo NoteContent
|
||||||
|
}
|
||||||
|
@ -62,6 +62,35 @@ func (this *NoteService) GetNoteAndContent(noteId, userId string) (noteAndConten
|
|||||||
return info.NoteAndContent{note, noteContent}
|
return info.NoteAndContent{note, noteContent}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *NoteService) GetNoteBySrc(src, userId string) (note info.Note) {
|
||||||
|
note = info.Note{}
|
||||||
|
if src == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
notes := []info.Note{}
|
||||||
|
q := db.Notes.Find(bson.M{
|
||||||
|
"UserId": bson.ObjectIdHex(userId),
|
||||||
|
"Src": src,
|
||||||
|
})
|
||||||
|
q.Sort("-Usn").Limit(1).All(¬es)
|
||||||
|
if len(notes) > 0 {
|
||||||
|
return notes[0]
|
||||||
|
}
|
||||||
|
// db.GetByQ(db.Notes, bson.M{"Src": src, "UserId": bson.ObjectIdHex(userId), "IsDeleted": false}, ¬e)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *NoteService) GetNoteAndContentBySrc(src, userId string) (noteId string, noteAndContent info.NoteAndContentSep) {
|
||||||
|
note := this.GetNoteBySrc(src, userId)
|
||||||
|
if (note.NoteId != "") {
|
||||||
|
noteId = note.NoteId.Hex()
|
||||||
|
noteContent := this.GetNoteContent(note.NoteId.Hex(), userId)
|
||||||
|
return noteId, info.NoteAndContentSep{note, noteContent}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 获取同步的笔记
|
// 获取同步的笔记
|
||||||
// > afterUsn的笔记
|
// > afterUsn的笔记
|
||||||
func (this *NoteService) GetSyncNotes(userId string, afterUsn, maxEntry int) []info.ApiNote {
|
func (this *NoteService) GetSyncNotes(userId string, afterUsn, maxEntry int) []info.ApiNote {
|
||||||
|
@ -40,6 +40,7 @@ POST /findPasswordUpdate Auth.FindPasswordUpdate
|
|||||||
* /note/setNote2Blog Note.SetNote2Blog
|
* /note/setNote2Blog Note.SetNote2Blog
|
||||||
* /note/exportPdf Note.ExportPDF
|
* /note/exportPdf Note.ExportPDF
|
||||||
* /note/toPdf Note.ToPdf
|
* /note/toPdf Note.ToPdf
|
||||||
|
* /note/getNoteAndContentBySrc Note.GetNoteAndContentBySrc
|
||||||
# pjax
|
# pjax
|
||||||
GET /note/:noteId Note.Index
|
GET /note/:noteId Note.Index
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user