Support for leanote-chrome plugin

This commit is contained in:
lealife
2017-02-18 20:01:14 +08:00
parent 8c98f4da5c
commit ad644258f5
4 changed files with 50 additions and 0 deletions

View File

@ -156,6 +156,16 @@ func (c Note) GetNoteAndContent(noteId string) revel.Result {
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 {
noteContent := noteService.GetNoteContent(noteId, c.GetUserId())
@ -177,6 +187,7 @@ func (c Note) UpdateNoteOrContent(noteOrContent info.NoteOrContent) revel.Result
NoteId: bson.ObjectIdHex(noteOrContent.NoteId),
NotebookId: bson.ObjectIdHex(noteOrContent.NotebookId),
Title: noteOrContent.Title,
Src: noteOrContent.Src, // 来源
Tags: strings.Split(noteOrContent.Tags, ","),
Desc: noteOrContent.Desc,
ImgSrc: noteOrContent.ImgSrc,

View File

@ -15,6 +15,8 @@ type Note struct {
Title string `Title` // 标题
Desc string `Desc` // 描述, 非html
Src string `Src,omitempty` // 来源, 2016/4/22
ImgSrc string `ImgSrc` // 图片, 第一张缩略图地址
Tags []string `Tags,omitempty`
@ -92,6 +94,7 @@ type NoteOrContent struct {
UserId string
Title string
Desc string
Src string
ImgSrc string
Tags string
Content string
@ -101,3 +104,9 @@ type NoteOrContent struct {
FromUserId string // 为共享而新建
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
}
// 分开的
type NoteAndContentSep struct {
NoteInfo Note
NoteContentInfo NoteContent
}

View File

@ -62,6 +62,35 @@ func (this *NoteService) GetNoteAndContent(noteId, userId string) (noteAndConten
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(&notes)
if len(notes) > 0 {
return notes[0]
}
// db.GetByQ(db.Notes, bson.M{"Src": src, "UserId": bson.ObjectIdHex(userId), "IsDeleted": false}, &note)
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的笔记
func (this *NoteService) GetSyncNotes(userId string, afterUsn, maxEntry int) []info.ApiNote {

View File

@ -40,6 +40,7 @@ POST /findPasswordUpdate Auth.FindPasswordUpdate
* /note/setNote2Blog Note.SetNote2Blog
* /note/exportPdf Note.ExportPDF
* /note/toPdf Note.ToPdf
* /note/getNoteAndContentBySrc Note.GetNoteAndContentBySrc
# pjax
GET /note/:noteId Note.Index