From 6a1e84da0cadb873cc2317682123ad24de88565b Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 13:43:37 +0800 Subject: [PATCH 01/32] =?UTF-8?q?noteService=E6=94=AF=E6=8C=81=E4=BC=A0?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=B7=BB=E5=8A=A0/=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=AC=94=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/NoteService.go | 52 ++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/app/service/NoteService.go b/app/service/NoteService.go index fa3225e..504fc87 100644 --- a/app/service/NoteService.go +++ b/app/service/NoteService.go @@ -245,11 +245,14 @@ func (this *NoteService) AddNote(note info.Note, fromApi bool) info.Note { noteId := bson.NewObjectId() note.NoteId = noteId } - note.CreatedTime = time.Now() - note.UpdatedTime = note.CreatedTime + + // 关于创建时间, 可能是客户端发来, 此时判断时间是否有 + note.CreatedTime = FixUrlTime(note.CreatedTime) + note.UpdatedTime = FixUrlTime(note.UpdatedTime) + note.IsTrash = false note.UpdatedUserId = note.UserId - note.UrlTitle = GetUrTitle(note.UserId.Hex(), note.Title, "note") + note.UrlTitle = GetUrTitle(note.UserId.Hex(), note.Title, "note", note.NoteId.Hex()) note.Usn = userService.IncrUsn(note.UserId.Hex()) notebookId := note.NotebookId.Hex() @@ -287,8 +290,10 @@ func (this *NoteService) AddSharedNote(note info.Note, myUserId bson.ObjectId) i // 添加笔记本内容 // [ok] func (this *NoteService) AddNoteContent(noteContent info.NoteContent) info.NoteContent { - noteContent.CreatedTime = time.Now() - noteContent.UpdatedTime = noteContent.CreatedTime + + noteContent.CreatedTime = FixUrlTime(noteContent.CreatedTime) + noteContent.UpdatedTime = FixUrlTime(noteContent.UpdatedTime) + noteContent.UpdatedUserId = noteContent.UserId db.Insert(db.NoteContents, noteContent) @@ -419,7 +424,15 @@ func (this *NoteService) UpdateNote(updatedUserId, noteId string, needUpdate bso } needUpdate["UpdatedUserId"] = bson.ObjectIdHex(updatedUserId) - needUpdate["UpdatedTime"] = time.Now() + + // 可以将时间传过来 + updatedTime, ok := needUpdate["UpdatedTime"].(time.Time) + if ok { + needUpdate["UpdatedTime"] = FixUrlTime(updatedTime) + } else { + needUpdate["UpdatedTime"] = time.Now() + } + afterUsn := userService.IncrUsn(userId) needUpdate["Usn"] = afterUsn @@ -443,7 +456,7 @@ func (this *NoteService) UpdateNote(updatedUserId, noteId string, needUpdate bso } } - ok := db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, needUpdate) + ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, needUpdate) if !ok { return ok, "", 0 } @@ -460,14 +473,19 @@ func (this *NoteService) UpdateNote(updatedUserId, noteId string, needUpdate bso notebookId := notebookIdI.(bson.ObjectId) if notebookId != "" { notebookService.ReCountNotebookNumberNotes(note.NotebookId.Hex()) - hasRecount = true notebookService.ReCountNotebookNumberNotes(notebookId.Hex()) + hasRecount = true } } // 不要多次更新, isTrash = false, = true都要重新统计 - if !hasRecount { - if _, ok := needUpdate["IsTrash"]; ok { + if isTrashI, ok := needUpdate["IsTrash"]; ok { + // 如果是垃圾, 则删除之共享 + isTrash := isTrashI.(bool) + if isTrash { + shareService.DeleteShareNoteAll(noteId, userId) + } + if !hasRecount { notebookService.ReCountNotebookNumberNotes(note.NotebookId.Hex()) } } @@ -507,7 +525,9 @@ func (this *NoteService) UpdateNoteTitle(userId, updatedUserId, noteId, title st // [ok] TODO perm未测 // hasBeforeUpdateNote 之前是否更新过note其它信息, 如果有更新, usn不用更新 // TODO abstract这里生成 -func (this *NoteService) UpdateNoteContent(updatedUserId, noteId, content, abstract string, hasBeforeUpdateNote bool, usn int) (bool, string, int) { +func (this *NoteService) UpdateNoteContent(updatedUserId, noteId, content, abstract string, + hasBeforeUpdateNote bool, + usn int, updatedTime time.Time) (bool, string, int) { // 是否已自定义 note := this.GetNoteById(noteId) if note.NoteId == "" { @@ -522,11 +542,13 @@ func (this *NoteService) UpdateNoteContent(updatedUserId, noteId, content, abstr } } + updatedTime = FixUrlTime(updatedTime) + // abstract重置 data := bson.M{"UpdatedUserId": bson.ObjectIdHex(updatedUserId), "Content": content, "Abstract": abstract, - "UpdatedTime": time.Now()} + "UpdatedTime": updatedTime} if note.IsBlog && note.HasSelfDefined { delete(data, "Abstract") @@ -788,7 +810,11 @@ func (this *NoteService) searchNoteFromContent(notes []info.Note, userId, key st noteIds[i] = note.NoteId } noteContents := []info.NoteContent{} - query := bson.M{"_id": bson.M{"$nin": noteIds}, "UserId": bson.ObjectIdHex(userId), "Content": bson.M{"$regex": bson.RegEx{".*?" + key + ".*", "i"}}} + query := bson.M{ + "_id": bson.M{"$nin": noteIds}, + "UserId": bson.ObjectIdHex(userId), + "Content": bson.M{"$regex": bson.RegEx{".*?" + key + ".*", "i"}}, + } if isBlog { query["IsBlog"] = true } From d13447e6d0eb2970e3dcb7d977da468d5bcbad63 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 13:47:59 +0800 Subject: [PATCH 02/32] =?UTF-8?q?controller=20=E6=94=AF=E6=8C=81=E4=BC=A0?= =?UTF-8?q?=E9=80=92=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/NoteController.go | 5 +-- app/controllers/api/ApiNoteController.go | 41 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/controllers/NoteController.go b/app/controllers/NoteController.go index 9a911e8..db105cd 100644 --- a/app/controllers/NoteController.go +++ b/app/controllers/NoteController.go @@ -3,7 +3,6 @@ package controllers import ( "github.com/revel/revel" // "encoding/json" - "fmt" "github.com/leanote/leanote/app/info" . "github.com/leanote/leanote/app/lea" "gopkg.in/mgo.v2/bson" @@ -14,6 +13,7 @@ import ( "time" // "github.com/leanote/leanote/app/types" // "io/ioutil" + "fmt" // "bytes" // "os" ) @@ -248,7 +248,8 @@ func (c Note) UpdateNoteOrContent(noteOrContent NoteOrContent) revel.Result { // noteService.UpdateNoteContent(noteOrContent.UserId, c.GetUserId(), // noteOrContent.NoteId, noteOrContent.Content, noteOrContent.Abstract) contentOk, contentMsg, afterContentUsn = noteService.UpdateNoteContent(c.GetUserId(), - noteOrContent.NoteId, noteOrContent.Content, noteOrContent.Abstract, needUpdateNote, -1) + noteOrContent.NoteId, noteOrContent.Content, noteOrContent.Abstract, + needUpdateNote, -1, time.Now()) } Log(afterContentUsn) diff --git a/app/controllers/api/ApiNoteController.go b/app/controllers/api/ApiNoteController.go index 6c97c8c..176342c 100644 --- a/app/controllers/api/ApiNoteController.go +++ b/app/controllers/api/ApiNoteController.go @@ -85,7 +85,6 @@ func (c ApiNote) GetTrashNotes() revel.Result { "Title": "asdfadsf--=", "Desc": "", "Tags": [ - "" ], "Abstract": "", "Content": "", @@ -95,7 +94,7 @@ func (c ApiNote) GetTrashNotes() revel.Result { "Usn": 8, "Files": [ { - "FileId": "551975d599c37b970f000002", + "FileId": "551975d599c37b970f000000", "LocalFileId": "", "Type": "", "Title": "", @@ -103,18 +102,18 @@ func (c ApiNote) GetTrashNotes() revel.Result { "IsAttach": false }, { - "FileId": "551975de99c37b970f000003", + "FileId": "551975de99c37b970f000001", "LocalFileId": "", "Type": "doc", - "Title": "李铁-简历-ali-print-en.doc", + "Title": "李铁-print-en.doc", "HasBody": false, "IsAttach": true }, { - "FileId": "551975de99c37b970f000004", + "FileId": "551975de99c37b970f000002", "LocalFileId": "", "Type": "doc", - "Title": "李铁-简历-ali-print.doc", + "Title": "李铁-print.doc", "HasBody": false, "IsAttach": true } @@ -327,15 +326,20 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result { Tags: noteOrContent.Tags, Desc: noteOrContent.Desc, // ImgSrc: noteOrContent.ImgSrc, - IsBlog: noteOrContent.IsBlog, - IsMarkdown: noteOrContent.IsMarkdown, - AttachNum: attachNum, + IsBlog: noteOrContent.IsBlog, + IsMarkdown: noteOrContent.IsMarkdown, + AttachNum: attachNum, + CreatedTime: noteOrContent.CreatedTime, + UpdatedTime: noteOrContent.UpdatedTime, } noteContent := info.NoteContent{NoteId: note.NoteId, - UserId: userId, - IsBlog: note.IsBlog, - Content: noteOrContent.Content, - Abstract: noteOrContent.Abstract} + UserId: userId, + IsBlog: note.IsBlog, + Content: noteOrContent.Content, + Abstract: noteOrContent.Abstract, + CreatedTime: noteOrContent.CreatedTime, + UpdatedTime: noteOrContent.UpdatedTime, + } // 通过内容得到Desc, abstract if noteOrContent.Abstract == "" { @@ -447,6 +451,7 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result { // Log("after upload") // LogJ(noteOrContent.Files) + } // 移到外面来, 删除最后一个file时也要处理, 不然总删不掉 @@ -509,6 +514,8 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result { } } + noteUpdate["UpdatedTime"] = noteOrContent.UpdatedTime + afterNoteUsn := 0 noteOk := false noteMsg := "" @@ -532,10 +539,16 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result { if noteOrContent.Abstract == "" { noteOrContent.Abstract = SubStringHTML(noteOrContent.Content, 200, "") } + // Log("--------> afte fixed") // Log(noteOrContent.Content) contentOk, contentMsg, afterContentUsn = noteService.UpdateNoteContent(c.getUserId(), - noteOrContent.NoteId, noteOrContent.Content, noteOrContent.Abstract, needUpdateNote, noteOrContent.Usn) + noteOrContent.NoteId, + noteOrContent.Content, + noteOrContent.Abstract, + needUpdateNote, + noteOrContent.Usn, + noteOrContent.UpdatedTime) } if needUpdateNote { From b25bf0e16cedac0d6291eab8fe038776ac923942 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 13:49:00 +0800 Subject: [PATCH 03/32] =?UTF-8?q?util=20=E6=97=B6=E9=97=B4=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/lea/Util.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/lea/Util.go b/app/lea/Util.go index 4ff66f7..b2ea077 100644 --- a/app/lea/Util.go +++ b/app/lea/Util.go @@ -394,3 +394,40 @@ func FixFilename(filename string) string { } return filename } + +// 是否是合法的时间 +// 不是, 0001-01-01T00:00:00Z, 且比今天小 +func IsValidTime(t time.Time) bool { + if t.Year() > 20 { + now := time.Now() + Log("------") + Log(t) + Log(now) + if t.Before(now) { + return true + } + } + return false +} + +// url传过来的时间没有时区信息, 转到本地时间 +func ToLocalTime(t time.Time) time.Time { + return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, time.Local) +} + +// 修复传过来的时间, 如果比今天大, 则设为现在 +func FixUrlTime(t time.Time) time.Time { + localTime := ToLocalTime(t) + if IsValidTime(localTime) { + return localTime + } + return time.Now() +} + +// 得到用户的随机文件路径 3位/userId/2位 +func GetRandomFilePath(userId, uuid string) string { + if uuid == "" { + uuid = NewGuid() + } + return Digest3(userId) + "/" + userId + "/" + Digest2(uuid) +} From a7eaf6114aa283a7fba73d66bbb1cbd197fc06f7 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:16:10 +0800 Subject: [PATCH 04/32] =?UTF-8?q?urlTitle=20=E4=BC=98=E5=8C=96,=20?= =?UTF-8?q?=E5=87=8F=E5=B0=91=E7=94=9F=E6=88=90=E6=AC=A1=E6=95=B0,=20?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E4=BD=BF=E7=94=A8id=E4=BD=9C=E4=B8=BAurlTitl?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/BlogService.go | 8 ++++---- app/service/NotebookService.go | 8 ++++++-- app/service/UpgradeService.go | 4 ++-- app/service/init.go | 21 +++++++++++++++++++-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/service/BlogService.go b/app/service/BlogService.go index a4bbe27..89eb979 100644 --- a/app/service/BlogService.go +++ b/app/service/BlogService.go @@ -919,7 +919,7 @@ func (this *BlogService) UpateCateUrlTitle(userId string, cateId, urlTitle strin "UrlTitle": "", }) */ - url = GetUrTitle(userId, urlTitle, "notebook") + url = GetUrTitle(userId, urlTitle, "notebook", cateId) ok = db.UpdateByIdAndUserIdMap(db.Notebooks, cateId, userId, bson.M{ "UrlTitle": url, }) @@ -935,7 +935,7 @@ func (this *BlogService) UpateBlogUrlTitle(userId string, noteId, urlTitle strin ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, bson.M{ "UrlTitle": "", }) - url = GetUrTitle(userId, urlTitle, "note") + url = GetUrTitle(userId, urlTitle, "note", noteId) ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, bson.M{ "UrlTitle": url, }) @@ -1036,7 +1036,7 @@ func (this *BlogService) UpdateSingleUrlTitle(userId, singleId, urlTitle string) "UrlTitle": "", }) */ - url = GetUrTitle(userId, urlTitle, "single") + url = GetUrTitle(userId, urlTitle, "single", singleId) ok = db.UpdateByIdAndUserIdMap(db.BlogSingles, singleId, userId, bson.M{ "UrlTitle": url, }) @@ -1070,7 +1070,7 @@ func (this *BlogService) AddOrUpdateSingle(userId, singleId, title, content stri UserId: bson.ObjectIdHex(userId), Title: title, Content: content, - UrlTitle: GetUrTitle(userId, title, "single"), + UrlTitle: GetUrTitle(userId, title, "single", singleId), CreatedTime: time.Now(), } page.UpdatedTime = page.CreatedTime diff --git a/app/service/NotebookService.go b/app/service/NotebookService.go index a437004..4974e36 100644 --- a/app/service/NotebookService.go +++ b/app/service/NotebookService.go @@ -156,9 +156,13 @@ func (this *NotebookService) GetNotebooksByNotebookIds(notebookIds []bson.Object } // 添加 -// [ok] func (this *NotebookService) AddNotebook(notebook info.Notebook) (bool, info.Notebook) { - notebook.UrlTitle = GetUrTitle(notebook.UserId.Hex(), notebook.Title, "notebook") + + if notebook.NotebookId == "" { + notebook.NotebookId = bson.NewObjectId() + } + + notebook.UrlTitle = GetUrTitle(notebook.UserId.Hex(), notebook.Title, "notebook", notebook.NotebookId.Hex()) notebook.Usn = userService.IncrUsn(notebook.UserId.Hex()) now := time.Now() notebook.CreatedTime = now diff --git a/app/service/UpgradeService.go b/app/service/UpgradeService.go index f7cfcc3..ddd713f 100644 --- a/app/service/UpgradeService.go +++ b/app/service/UpgradeService.go @@ -65,7 +65,7 @@ func (this *UpgradeService) UpgradeBetaToBeta2(userId string) (ok bool, msg stri data["RecommendTime"] = note.UpdatedTime Log("Time " + noteId) } - data["UrlTitle"] = GetUrTitle(note.UserId.Hex(), note.Title, "note") + data["UrlTitle"] = GetUrTitle(note.UserId.Hex(), note.Title, "note", noteId) db.UpdateByIdAndUserIdMap2(db.Notes, note.NoteId, note.UserId, data) Log(noteId) } @@ -77,7 +77,7 @@ func (this *UpgradeService) UpgradeBetaToBeta2(userId string) (ok bool, msg stri for _, notebook := range notebooks { notebookId := notebook.NotebookId.Hex() data := bson.M{} - data["UrlTitle"] = GetUrTitle(notebook.UserId.Hex(), notebook.Title, "notebook") + data["UrlTitle"] = GetUrTitle(notebook.UserId.Hex(), notebook.Title, "notebook", notebookId) db.UpdateByIdAndUserIdMap2(db.Notebooks, notebook.NotebookId, notebook.UserId, data) Log(notebookId) } diff --git a/app/service/init.go b/app/service/init.go index 63e8194..a8ed2c6 100644 --- a/app/service/init.go +++ b/app/service/init.go @@ -2,6 +2,7 @@ package service import ( "github.com/leanote/leanote/app/db" + . "github.com/leanote/leanote/app/lea" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "net/url" @@ -150,12 +151,28 @@ func getUniqueUrlTitle(userId string, urlTitle string, types string, padding int return urlTitle2 } +// 截取id 24位变成12位 +// 先md5, 再取12位 +func subIdHalf(id string) string { + idMd5 := Md5(id) + return idMd5[:12] +} + // types == note,notebook,single -func GetUrTitle(userId string, title string, types string) string { +// id noteId, notebookId, singleId 当title没的时候才有用, 用它来替换 +func GetUrTitle(userId string, title string, types string, id string) string { urlTitle := strings.Trim(title, " ") if urlTitle == "" { - urlTitle = "Untitled-" + userId + if id == "" { + urlTitle = "Untitled-" + userId + } else { + urlTitle = subIdHalf(id) + } + // 不允许title是ObjectId + } else if bson.IsObjectIdHex(title) { + urlTitle = subIdHalf(id) } + urlTitle = fixUrlTitle(urlTitle) return getUniqueUrlTitle(userId, urlTitle, types, 1) } From df4ec53647cd376602a699e6ecdd34540154894c Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:21:23 +0800 Subject: [PATCH 05/32] =?UTF-8?q?api=20fixContent=E4=BC=98=E5=8C=96;=20exp?= =?UTF-8?q?ortPDF=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/NoteController.go | 6 +- app/controllers/api/ApiNoteController.go | 78 ++-------- app/service/NoteService.go | 186 +++++++++++++++++++++++ 3 files changed, 199 insertions(+), 71 deletions(-) diff --git a/app/controllers/NoteController.go b/app/controllers/NoteController.go index db105cd..1e029fe 100644 --- a/app/controllers/NoteController.go +++ b/app/controllers/NoteController.go @@ -434,7 +434,7 @@ func (c Note) ExportPdf(noteId string) revel.Result { // path 判断是否需要重新生成之 guid := NewGuid() - fileUrlPath := "files/" + Digest3(noteUserId) + "/" + noteUserId + "/" + Digest2(guid) + "/images/pdf" + fileUrlPath := "files/export_pdf" dir := revel.BasePath + "/" + fileUrlPath if !MkdirAll(dir) { return c.RenderText("error, no dir") @@ -463,9 +463,9 @@ func (c Note) ExportPdf(noteId string) revel.Result { // wkhtmltopdf参数大全 var cc string if note.IsMarkdown { - cc = binPath + " --window-status done \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" + cc = binPath + " --lowquality --window-status done \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" } else { - cc = binPath + " \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" + cc = binPath + " --lowquality \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" } cmd := exec.Command("/bin/sh", "-c", cc) diff --git a/app/controllers/api/ApiNoteController.go b/app/controllers/api/ApiNoteController.go index 176342c..d7254c6 100644 --- a/app/controllers/api/ApiNoteController.go +++ b/app/controllers/api/ApiNoteController.go @@ -8,7 +8,6 @@ import ( "gopkg.in/mgo.v2/bson" "os" "os/exec" - "regexp" "strings" "time" // "github.com/leanote/leanote/app/types" @@ -147,68 +146,10 @@ func (c ApiNote) GetNoteAndContent(noteId string) revel.Result { apiNotes := noteService.ToApiNotes([]info.Note{noteAndContent.Note}) apiNote := apiNotes[0] - apiNote.Content = noteAndContent.Content + apiNote.Content = noteService.FixContent(noteAndContent.Content, noteAndContent.IsMarkdown) return c.RenderJson(apiNote) } -// 处理笔记内容数据 http://leanote.com/file/outputImage -> https://leanote.com/api/file/getImage -// 图片, 附件都替换 -func (c ApiNote) fixContent(content string) string { - // TODO, 这个url需要从config中取 - // baseUrl := "http://leanote.com" - baseUrl := configService.GetSiteUrl() - // baseUrl := "http://localhost:9000" - - patterns := []map[string]string{ - map[string]string{"src": "src", "middle": "/file/outputImage", "param": "fileId", "to": "getImage?fileId="}, - map[string]string{"src": "href", "middle": "/attach/download", "param": "attachId", "to": "getAttach?fileId="}, - map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="}, - } - - for _, eachPattern := range patterns { - - // src="http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1" - // href="http://leanote.com/attach/download?attachId=5504243a38f4111dcb00017d" - // href="http://leanote.com/attach/downloadAll?noteId=55041b6a38f4111dcb000159" - - regImage, _ := regexp.Compile(eachPattern["src"] + `=('|")` + baseUrl + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})("|')`) - findsImage := regImage.FindAllStringSubmatch(content, -1) // 查找所有的 - - // [[src='http://leanote.com/file/outputImage?fileId=54672e8d38f411286b000069" ' 54672e8d38f411286b000069 "] [src="http://leanote.com/file/outputImage?fileId=54672e8d38f411286b000069" " 54672e8d38f411286b000069 "] [src="http://leanote.com/file/outputImage?fileId=54672e8d38f411286b000069" " 54672e8d38f411286b000069 "] [src="http://leanote.com/file/outputImage?fileId=54672e8d38f411286b000069" " 54672e8d38f411286b000069 "]] - for _, eachFind := range findsImage { - // [src='http://leanote.com/file/outputImage?fileId=54672e8d38f411286b000069" ' 54672e8d38f411286b000069 "] - if len(eachFind) == 4 { - content = strings.Replace(content, - eachFind[0], - eachPattern["src"]+"=\""+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+"\"", - 1) - } - } - - // markdown处理 - // ![](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) - // [selection 2.html](http://leanote.com/attach/download?attachId=5504262638f4111dcb00017f) - // [all.tar.gz](http://leanote.com/attach/downloadAll?noteId=5503b57d59f81b4eb4000000) - - pre := "!" // 默认图片 - if eachPattern["src"] == "href" { // 是attach - pre = "" - } - - regImageMarkdown, _ := regexp.Compile(pre + `\[(.*?)\]\(` + baseUrl + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})\)`) - findsImageMarkdown := regImageMarkdown.FindAllStringSubmatch(content, -1) // 查找所有的 - // [[![](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 5503537b38f4111dcb0000d1] [![你好啊, 我很好, 为什么?](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 5503537b38f4111dcb0000d1]] - for _, eachFind := range findsImageMarkdown { - // [![你好啊, 我很好, 为什么?](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 你好啊, 我很好, 为什么? 5503537b38f4111dcb0000d1] - if len(eachFind) == 3 { - content = strings.Replace(content, eachFind[0], pre+"["+eachFind[1]+"]("+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+")", 1) - } - } - } - - return content -} - // content里的image, attach链接是 // https://leanote.com/api/file/getImage?fileId=xx // https://leanote.com/api/file/getAttach?fileId=xx @@ -228,12 +169,13 @@ func (c ApiNote) fixPostNotecontent(noteOrContent *info.ApiNote) { } // 得到内容 -// [OK] func (c ApiNote) GetNoteContent(noteId string) revel.Result { + userId := c.getUserId() + note := noteService.GetNote(noteId, userId) // re := info.NewRe() - noteContent := noteService.GetNoteContent(noteId, c.getUserId()) + noteContent := noteService.GetNoteContent(noteId, userId) if noteContent.Content != "" { - noteContent.Content = c.fixContent(noteContent.Content) + noteContent.Content = noteService.FixContent(noteContent.Content, note.IsMarkdown) } apiNoteContent := info.ApiNoteContent{ @@ -242,7 +184,6 @@ func (c ApiNote) GetNoteContent(noteId string) revel.Result { Content: noteContent.Content, } - // re.Item = noteContent return c.RenderJson(apiNoteContent) } @@ -259,7 +200,8 @@ func (c ApiNote) AddNote(noteOrContent info.ApiNote) revel.Result { } */ // Log(noteOrContent.Title) - // LogJ(noteOrContent) + // LogJ(noteOrContent) + /* LogJ(c.Params) for name, _ := range c.Params.Files { @@ -625,7 +567,7 @@ func (c ApiNote) ExportPdf(noteId string) revel.Result { // path 判断是否需要重新生成之 guid := NewGuid() - fileUrlPath := "files/" + Digest3(noteUserId) + "/" + noteUserId + "/" + Digest2(guid) + "/images/pdf" + fileUrlPath := "files/export_pdf" dir := revel.BasePath + "/" + fileUrlPath if !MkdirAll(dir) { re.Msg = "noDir" @@ -649,9 +591,9 @@ func (c ApiNote) ExportPdf(noteId string) revel.Result { url := configService.GetSiteUrl() + "/note/toPdf?noteId=" + noteId + "&appKey=" + appKey var cc string if note.IsMarkdown { - cc = binPath + " --window-status done \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" + cc = binPath + " --lowquality --window-status done \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" } else { - cc = binPath + " \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" + cc = binPath + " --lowquality \"" + url + "\" \"" + path + "\"" // \"" + cookieDomain + "\" \"" + cookieName + "\" \"" + cookieValue + "\"" } cmd := exec.Command("/bin/sh", "-c", cc) diff --git a/app/service/NoteService.go b/app/service/NoteService.go index 504fc87..fa06448 100644 --- a/app/service/NoteService.go +++ b/app/service/NoteService.go @@ -5,6 +5,8 @@ import ( "github.com/leanote/leanote/app/info" . "github.com/leanote/leanote/app/lea" "gopkg.in/mgo.v2/bson" + "regexp" + "strings" "time" ) @@ -921,3 +923,187 @@ func (this *NoteService) UpdateNoteToDeleteTag(userId string, targetTag string) } return ret } + +// api + +// 得到笔记的内容, 此时将笔记内的链接转成标准的Leanote Url +// 将笔记的图片, 附件链接转换成 site.url/file/getImage?fileId=xxx, site.url/file/getAttach?fileId=xxxx +func (this *NoteService) FixContentBad(content string, isMarkdown bool) string { + baseUrl := configService.GetSiteUrl() + + baseUrlPattern := baseUrl + + // 避免https的url + if baseUrl[0:8] == "https://" { + baseUrlPattern = strings.Replace(baseUrl, "https://", "https*://", 1) + } else { + baseUrlPattern = strings.Replace(baseUrl, "http://", "https*://", 1) + } + + patterns := []map[string]string{ + map[string]string{"src": "src", "middle": "/file/outputImage", "param": "fileId", "to": "getImage?fileId="}, + map[string]string{"src": "href", "middle": "/attach/download", "param": "attachId", "to": "getAttach?fileId="}, + // 该链接已失效, 不再支持 + map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="}, + } + + for _, eachPattern := range patterns { + + if !isMarkdown { + + // 富文本处理 + + // + // + + var reg *regexp.Regexp + if eachPattern["src"] == "src" { + reg, _ = regexp.Compile("]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`) + } else { + reg, _ = regexp.Compile("]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`) + } + + finds := reg.FindAllStringSubmatch(content, -1) // 查找所有的 + + for _, eachFind := range finds { + if len(eachFind) == 3 { + // 这一行会非常慢!, content是全部的内容, 多次replace导致 + content = strings.Replace(content, + eachFind[1], + eachPattern["src"]+"=\""+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+"\"", + 1) + } + } + } else { + + // markdown处理 + // ![](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) + // [selection 2.html](http://leanote.com/attach/download?attachId=5504262638f4111dcb00017f) + // [all.tar.gz](http://leanote.com/attach/downloadAll?noteId=5503b57d59f81b4eb4000000) + + pre := "!" // 默认图片 + if eachPattern["src"] == "href" { // 是attach + pre = "" + } + + regImageMarkdown, _ := regexp.Compile(pre + `\[([^]]*?)\]\(` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})\)`) + findsImageMarkdown := regImageMarkdown.FindAllStringSubmatch(content, -1) // 查找所有的 + // [[![](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 5503537b38f4111dcb0000d1] [![你好啊, 我很好, 为什么?](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 5503537b38f4111dcb0000d1]] + for _, eachFind := range findsImageMarkdown { + // [![你好啊, 我很好, 为什么?](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 你好啊, 我很好, 为什么? 5503537b38f4111dcb0000d1] + if len(eachFind) == 3 { + content = strings.Replace(content, eachFind[0], pre+"["+eachFind[1]+"]("+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+")", 1) + } + } + } + } + + return content +} + +// 性能更好, 5倍的差距 +func (this *NoteService) FixContent(content string, isMarkdown bool) string { + baseUrl := configService.GetSiteUrl() + + baseUrlPattern := baseUrl + + // 避免https的url + if baseUrl[0:8] == "https://" { + baseUrlPattern = strings.Replace(baseUrl, "https://", "https*://", 1) + } else { + baseUrlPattern = strings.Replace(baseUrl, "http://", "https*://", 1) + } + + patterns := []map[string]string{ + map[string]string{"src": "src", "middle": "/file/outputImage", "param": "fileId", "to": "getImage?fileId="}, + map[string]string{"src": "href", "middle": "/attach/download", "param": "attachId", "to": "getAttach?fileId="}, + // 该链接已失效, 不再支持 + map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="}, + } + + for _, eachPattern := range patterns { + + if !isMarkdown { + + // 富文本处理 + + // + // + + var reg *regexp.Regexp + var reg2 *regexp.Regexp + if eachPattern["src"] == "src" { + reg, _ = regexp.Compile("]+?)(?:" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=(?:[a-z0-9A-Z]{24})["']*)[^>]*>`) + reg2, _ = regexp.Compile("]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`) + } else { + reg, _ = regexp.Compile("]+?)(?:" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=(?:[a-z0-9A-Z]{24})["']*)[^>]*>`) + reg2, _ = regexp.Compile("]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`) + } + + content = reg.ReplaceAllStringFunc(content, func(str string) string { + // str=这样的 + // + + eachFind := reg2.FindStringSubmatch(str) + str = strings.Replace(str, + eachFind[1], + eachPattern["src"]+"=\""+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+"\"", + 1) + + // fmt.Println(str) + return str + }) + /* + finds := reg.FindAllStringSubmatch(content, -1) // 查找所有的 + + for _, eachFind := range finds { + if len(eachFind) == 3 { + // 这一行会非常慢!, content是全部的内容, 多次replace导致 + content = strings.Replace(content, + eachFind[1], + eachPattern["src"]+"=\""+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+"\"", + 1) + } + } + */ + } else { + + // markdown处理 + // ![](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) + // [selection 2.html](http://leanote.com/attach/download?attachId=5504262638f4111dcb00017f) + // [all.tar.gz](http://leanote.com/attach/downloadAll?noteId=5503b57d59f81b4eb4000000) + + pre := "!" // 默认图片 + if eachPattern["src"] == "href" { // 是attach + pre = "" + } + + regImageMarkdown, _ := regexp.Compile(pre + `\[(?:[^]]*?)\]\(` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=(?:[a-z0-9A-Z]{24})\)`) + regImageMarkdown2, _ := regexp.Compile(pre + `\[([^]]*?)\]\(` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})\)`) + + content = regImageMarkdown.ReplaceAllStringFunc(content, func(str string) string { + // str=这样的 + // + + eachFind := regImageMarkdown2.FindStringSubmatch(str) + str = strings.Replace(str, eachFind[0], pre+"["+eachFind[1]+"]("+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+")", 1) + + // fmt.Println(str) + return str + }) + + /* + findsImageMarkdown := regImageMarkdown.FindAllStringSubmatch(content, -1) // 查找所有的 + // [[![](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 5503537b38f4111dcb0000d1] [![你好啊, 我很好, 为什么?](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 5503537b38f4111dcb0000d1]] + for _, eachFind := range findsImageMarkdown { + // [![你好啊, 我很好, 为什么?](http://leanote.com/file/outputImage?fileId=5503537b38f4111dcb0000d1) 你好啊, 我很好, 为什么? 5503537b38f4111dcb0000d1] + if len(eachFind) == 3 { + content = strings.Replace(content, eachFind[0], pre+"["+eachFind[1]+"]("+baseUrl+"/api/file/"+eachPattern["to"]+eachFind[2]+")", 1) + } + } + */ + } + } + + return content +} From f0521179890de58d43fa253ab4a7d5f48f513a9f Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:22:10 +0800 Subject: [PATCH 06/32] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=AC=94=E8=AE=B0?= =?UTF-8?q?=E6=97=B6=E5=88=A0=E9=99=A4=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/TrashService.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/service/TrashService.go b/app/service/TrashService.go index e5ef218..7f2f6f5 100644 --- a/app/service/TrashService.go +++ b/app/service/TrashService.go @@ -85,6 +85,9 @@ func (this *TrashService) DeleteTrash(noteId, userId string) bool { // delete content ok = db.DeleteByIdAndUserId(db.NoteContents, noteId, userId) + // 删除content history + ok = db.DeleteByIdAndUserId(db.NoteContentHistories, noteId, userId) + // 重新统计tag's count // TODO 这里会改变tag's Usn tagService.reCountTagCount(userId, note.Tags) @@ -115,6 +118,13 @@ func (this *TrashService) DeleteTrashApi(noteId, userId string, usn int) (bool, // delete content ok = db.DeleteByIdAndUserId(db.NoteContents, noteId, userId) + // 删除content history + ok = db.DeleteByIdAndUserId(db.NoteContentHistories, noteId, userId) + + // 一个BUG, iOS删除直接调用这个API, 结果没有重新recount + // recount notebooks' notes number + notebookService.ReCountNotebookNumberNotes(note.NotebookId.Hex()) + return ok, "", afterUsn } From bba57ea302205fc985da0a34301841e95704d89d Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:25:45 +0800 Subject: [PATCH 07/32] configservice --- app/service/ConfigService.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/service/ConfigService.go b/app/service/ConfigService.go index c1a49d1..806d2ce 100644 --- a/app/service/ConfigService.go +++ b/app/service/ConfigService.go @@ -577,6 +577,14 @@ func (this *ConfigService) GetUploadSize(key string) float64 { f, _ := strconv.ParseFloat(this.GetGlobalStringConfig(key), 64) return f } +func (this *ConfigService) GetInt64(key string) int64 { + f, _ := strconv.ParseInt(this.GetGlobalStringConfig(key), 10, 64) + return f +} +func (this *ConfigService) GetInt32(key string) int32 { + f, _ := strconv.ParseInt(this.GetGlobalStringConfig(key), 10, 32) + return int32(f) +} func (this *ConfigService) GetUploadSizeLimit() map[string]float64 { return map[string]float64{ "uploadImageSize": this.GetUploadSize("uploadImageSize"), From 10f23c19abe76a0d7e05e9e38d1289bb504002c3 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:28:51 +0800 Subject: [PATCH 08/32] =?UTF-8?q?group=20i18n,=20pwd=20=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/GroupService.go | 10 +++++----- app/service/PwdService.go | 8 +++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/service/GroupService.go b/app/service/GroupService.go index a2cab44..1cb6660 100644 --- a/app/service/GroupService.go +++ b/app/service/GroupService.go @@ -185,16 +185,16 @@ func (this *GroupService) AddUser(ownUserId, groupId, userId string) (ok bool, m // groupId是否是ownUserId的? /* if !this.IsExistsGroupUser(ownUserId, groupId) { - return false, "forbidden" + return false, "forbiddenNotMyGroup" } */ if !this.isMyGroup(ownUserId, groupId) { - return false, "forbidden" + return false, "forbiddenNotMyGroup" } // 是否已存在 if db.Has(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId), "UserId": bson.ObjectIdHex(userId)}) { - return false, "hasUsers" + return false, "userExistsInGroup" } return db.Insert(db.GroupUsers, info.GroupUser{ @@ -210,11 +210,11 @@ func (this *GroupService) DeleteUser(ownUserId, groupId, userId string) (ok bool // groupId是否是ownUserId的? /* if !this.IsExistsGroupUser(ownUserId, groupId) { - return false, "forbidden" + return false, "forbiddenNotMyGroup" } */ if !this.isMyGroup(ownUserId, groupId) { - return false, "forbidden" + return false, "forbiddenNotMyGroup" } // 删除该用户分享到本组的笔记本, 笔记 diff --git a/app/service/PwdService.go b/app/service/PwdService.go index 6e7637b..e11c369 100644 --- a/app/service/PwdService.go +++ b/app/service/PwdService.go @@ -34,6 +34,7 @@ func (this *PwdService) FindPwd(email string) (ok bool, msg string) { return } +// 重置密码时 // 修改密码 // 先验证 func (this *PwdService) UpdatePwd(token, pwd string) (bool, string) { @@ -45,11 +46,12 @@ func (this *PwdService) UpdatePwd(token, pwd string) (bool, string) { if ok, msg, tokenInfo = tokenService.VerifyToken(token, info.TokenPwd); !ok { return ok, msg } - digest, err := GenerateHash(pwd) - if err != nil { + + passwd := GenPwd(pwd) + if passwd == "" { return false, "GenerateHash error" } - passwd := string(digest) + // 修改密码之 ok = db.UpdateByQField(db.Users, bson.M{"_id": tokenInfo.UserId}, "Pwd", passwd) From 0dab71e72b6af27521e9c9794c40dc530d003463 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:35:46 +0800 Subject: [PATCH 09/32] delete unused --- app/controllers/UserController.go | 36 ------------------- .../member/MemberUserController.go | 6 ---- app/controllers/member/个人中心.md | 2 -- app/service/UserService.go | 22 +----------- app/views/member/nav.html | 11 +----- app/views/member/个人中心.md | 0 6 files changed, 2 insertions(+), 75 deletions(-) delete mode 100644 app/controllers/member/个人中心.md delete mode 100644 app/views/member/个人中心.md diff --git a/app/controllers/UserController.go b/app/controllers/UserController.go index e678c8d..44d5f8a 100644 --- a/app/controllers/UserController.go +++ b/app/controllers/UserController.go @@ -93,21 +93,6 @@ func (c User) ReSendActiveEmail() revel.Result { return c.RenderJson(re) } -// 修改Email发送激活邮箱 -func (c User) updateEmailSendActiveEmail(email, pwd string) revel.Result { - re := info.NewRe() - if c.GetUserId() == configService.GetGlobalStringConfig("demoUserId") { - re.Msg = "cannotUpdateDemo" - return c.RenderJson(re) - } - if re.Ok, re.Msg = Vd("email", email); !re.Ok { - return c.RenderRe(re) - } - - re.Ok, re.Msg = emailService.UpdateEmailSendActiveEmail(c.GetUserInfo(), email) - return c.RenderRe(re) -} - // 通过点击链接 // 修改邮箱 func (c User) UpdateEmail(token string) revel.Result { @@ -147,27 +132,6 @@ func (c User) ActiveEmail(token string) revel.Result { return c.RenderTemplate("user/active_email.html") } -//------------ -// 第三方账号添加leanote账号 -func (c User) AddAccount(email, pwd string) revel.Result { - re := info.NewRe() - - if re.Ok, re.Msg = Vd("email", email); !re.Ok { - return c.RenderRe(re) - } - if re.Ok, re.Msg = Vd("password", pwd); !re.Ok { - return c.RenderRe(re) - } - - re.Ok, re.Msg = userService.ThirdAddUser(c.GetUserId(), email, pwd) - - if re.Ok { - c.UpdateSession("Email", email) - } - - return c.RenderRe(re) -} - //----------------- // 用户偏爱 func (c User) UpdateColumnWidth(notebookWidth, noteListWidth, mdEditorWidth int) revel.Result { diff --git a/app/controllers/member/MemberUserController.go b/app/controllers/member/MemberUserController.go index 408daf0..e7f18b6 100644 --- a/app/controllers/member/MemberUserController.go +++ b/app/controllers/member/MemberUserController.go @@ -38,9 +38,3 @@ func (c MemberUser) Avatar() revel.Result { c.RenderArgs["globalConfigs"] = configService.GetGlobalConfigForUser() return c.RenderTemplate("member/user/avatar.html") } -func (c MemberUser) AddAccount() revel.Result { - c.SetUserInfo() - c.SetLocale() - c.RenderArgs["title"] = "Add Account" - return c.RenderTemplate("member/user/add_account.html") -} diff --git a/app/controllers/member/个人中心.md b/app/controllers/member/个人中心.md deleted file mode 100644 index ab0218f..0000000 --- a/app/controllers/member/个人中心.md +++ /dev/null @@ -1,2 +0,0 @@ -包括基本信息设置 -博客设置 diff --git a/app/service/UserService.go b/app/service/UserService.go index dea7841..4fc5224 100644 --- a/app/service/UserService.go +++ b/app/service/UserService.go @@ -47,7 +47,7 @@ func (this *UserService) AddUser(user info.User) bool { go func() { emailService.RegisterSendActiveEmail(user, user.Email) // 发送给我 life@leanote.com - emailService.SendEmail("life@leanote.com", "新增用户", "{header}用户名"+user.Email+"{footer}") + // emailService.SendEmail("life@leanote.com", "新增用户", "{header}用户名"+user.Email+"{footer}") }() } @@ -412,26 +412,6 @@ func (this *UserService) UpdateEmail(token string) (ok bool, msg, email string) return } -//--------- -// 第三方添加账号 -func (this *UserService) ThirdAddUser(userId, email, pwd string) (ok bool, msg string) { - // 判断该用户是否已有了帐户 - userInfo := this.GetUserInfo(userId) - if userInfo.Email != "" { - msg = "你已有帐户" - return - } - - // 判断email是否存在 - if this.IsExistsUser(email) { - msg = "该用户已存在" - return - } - - ok = db.UpdateByQMap(db.Users, bson.M{"_id": bson.ObjectIdHex(userId)}, bson.M{"Email": email, "Pwd": Md5(pwd)}) - return -} - //------------ // 偏好设置 diff --git a/app/views/member/nav.html b/app/views/member/nav.html index 7e04ba4..443f381 100644 --- a/app/views/member/nav.html +++ b/app/views/member/nav.html @@ -39,7 +39,6 @@ - {{if $.userInfo.Email}}
  • @@ -62,15 +61,7 @@
  • - {{else}} -
  • - - - {{msg . "addLeanoteAccount"}} - - -
  • - {{end}} + diff --git a/app/views/member/个人中心.md b/app/views/member/个人中心.md deleted file mode 100644 index e69de29..0000000 From bc0e09f222d8bac7a70fadc3123c0fd54dc3698d Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 14:44:07 +0800 Subject: [PATCH 10/32] =?UTF-8?q?file=20upload=20path=20=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E5=8C=96=20GetRandomFilePath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/AttachController.go | 16 ++++++++++++---- app/controllers/FileController.go | 6 ++++-- app/controllers/api/ApiBaseController.go | 6 ++++-- app/service/FileService.go | 12 +++++++----- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/app/controllers/AttachController.go b/app/controllers/AttachController.go index 3852fad..e82d142 100644 --- a/app/controllers/AttachController.go +++ b/app/controllers/AttachController.go @@ -67,7 +67,9 @@ func (c Attach) uploadAttach(noteId string) (re info.Re) { } // 生成上传路径 - filePath := "files/" + c.GetUserId() + "/attachs" + // filePath := "files/" + c.GetUserId() + "/attachs" + newGuid := NewGuid() + filePath := "files/" + GetRandomFilePath(c.GetUserId(), newGuid) + "/attachs" dir := revel.BasePath + "/" + filePath err = os.MkdirAll(dir, 0755) if err != nil { @@ -76,7 +78,7 @@ func (c Attach) uploadAttach(noteId string) (re info.Re) { // 生成新的文件名 filename := handel.Filename _, ext := SplitFilename(filename) // .doc - filename = NewGuid() + ext + filename = newGuid + ext toPath := dir + "/" + filename err = ioutil.WriteFile(toPath, data, 0777) if err != nil { @@ -165,10 +167,16 @@ func (c Attach) DownloadAll(noteId string) revel.Result { filename = "all.tar.gz" } + dir := revel.BasePath + "/files/attach_all" + + if !MkdirAll(dir) { + return c.RenderText("error") + } + // file write - fw, err := os.Create(revel.BasePath + "/files/" + filename) + fw, err := os.Create(dir + "/" + filename) if err != nil { - return c.RenderText("") + return c.RenderText("error") } // defer fw.Close() // 不需要关闭, 还要读取给用户下载 diff --git a/app/controllers/FileController.go b/app/controllers/FileController.go index 0f54e8f..8a1fda8 100644 --- a/app/controllers/FileController.go +++ b/app/controllers/FileController.go @@ -109,7 +109,8 @@ func (c File) uploadImage(from, albumId string) (re info.Re) { if from == "logo" || from == "blogLogo" { fileUrlPath = "public/upload/" + Digest3(userId) + "/" + userId + "/images/logo" } else { - fileUrlPath = "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images" + // fileUrlPath = "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images" + fileUrlPath = "files/" + GetRandomFilePath(userId, newGuid) + "/images" } dir := revel.BasePath + "/" + fileUrlPath @@ -242,7 +243,8 @@ func (c File) CopyHttpImage(src string) revel.Result { // 生成上传路径 newGuid := NewGuid() userId := c.GetUserId() - fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images" + // fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images" + fileUrlPath := "files/" + GetRandomFilePath(userId, newGuid) + "/images" dir := revel.BasePath + "/" + fileUrlPath err := os.MkdirAll(dir, 0755) if err != nil { diff --git a/app/controllers/api/ApiBaseController.go b/app/controllers/api/ApiBaseController.go index 1b975aa..e0b8e34 100644 --- a/app/controllers/api/ApiBaseController.go +++ b/app/controllers/api/ApiBaseController.go @@ -75,7 +75,8 @@ func (c ApiBaseContrller) uploadAttach(name string, noteId string) (ok bool, msg // 生成上传路径 newGuid := NewGuid() - filePath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/attachs" + // filePath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/attachs" + filePath := "files/" + GetRandomFilePath(userId, newGuid) + "/attachs" dir := revel.BasePath + "/" + filePath err = os.MkdirAll(dir, 0755) @@ -130,7 +131,8 @@ func (c ApiBaseContrller) upload(name string, noteId string, isAttach bool) (ok newGuid := NewGuid() // 生成上传路径 userId := c.getUserId() - fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images" + // fileUrlPath := "files/" + Digest3(userId) + "/" + userId + "/" + Digest2(newGuid) + "/images" + fileUrlPath := "files/" + GetRandomFilePath(userId, newGuid) + "/images" dir := revel.BasePath + "/" + fileUrlPath err = os.MkdirAll(dir, 0755) diff --git a/app/service/FileService.go b/app/service/FileService.go index 9e3569a..2710ce8 100644 --- a/app/service/FileService.go +++ b/app/service/FileService.go @@ -242,6 +242,7 @@ func (this *FileService) GetFile(userId, fileId string) string { return "" } +// 复制共享的笔记时, 复制其中的图片到我本地 // 复制图片 func (this *FileService) CopyImage(userId, fileId, toUserId string) (bool, string) { // 是否已经复制过了 @@ -252,7 +253,6 @@ func (this *FileService) CopyImage(userId, fileId, toUserId string) (bool, strin } // 复制之 - file := info.File{} db.GetByIdAndUserId(db.Files, fileId, userId, &file) @@ -261,18 +261,20 @@ func (this *FileService) CopyImage(userId, fileId, toUserId string) (bool, strin } _, ext := SplitFilename(file.Name) - newFilename := NewGuid() + ext + guid := NewGuid() + newFilename := guid + ext - dir := "files/" + toUserId + "/images" + // TODO 统一目录格式 + // dir := "files/" + toUserId + "/images" + dir := "files/" + GetRandomFilePath(toUserId, guid) + "/images" filePath := dir + "/" + newFilename - err := os.MkdirAll(dir, 0755) + err := os.MkdirAll(revel.BasePath+dir, 0755) if err != nil { return false, "" } _, err = CopyFile(revel.BasePath+"/"+file.Path, revel.BasePath+"/"+filePath) if err != nil { - Log(err) return false, "" } From b1f36dfbf1719ef819e9387625f192492a4bdf44 Mon Sep 17 00:00:00 2001 From: lealife Date: Sat, 28 Nov 2015 15:17:36 +0800 Subject: [PATCH 11/32] member i18n --- app/controllers/AuthController.go | 5 + app/controllers/NoteController.go | 6 +- app/controllers/PreviewController.go | 2 +- app/controllers/api/ApiNoteController.go | 1 - .../member/MemberBlogController.go | 28 +++--- .../member/MemberGroupController.go | 2 +- .../member/MemberIndexController.go | 2 +- .../member/MemberUserController.go | 8 +- app/service/ShareService.go | 3 +- app/service/ThemeService.go | 4 - app/views/member/blog/add_single.html | 26 ++--- app/views/member/blog/base.html | 1 - app/views/member/blog/cate.html | 8 +- app/views/member/blog/list.html | 8 +- app/views/member/blog/single.html | 14 +-- app/views/member/blog/theme.html | 32 +++--- app/views/member/blog/update_abstract.html | 97 ++++++++++++------- app/views/member/blog/update_theme.html | 54 +++++++---- app/views/member/footer.html | 6 +- app/views/member/group/index.html | 14 +-- app/views/member/nav.html | 23 +++-- app/views/member/top.html | 2 +- app/views/member/user/avatar.html | 2 +- app/views/member/user/email.html | 2 +- app/views/member/user/password.html | 2 +- app/views/member/user/username.html | 4 +- 26 files changed, 197 insertions(+), 159 deletions(-) diff --git a/app/controllers/AuthController.go b/app/controllers/AuthController.go index ecfe5ed..7463217 100644 --- a/app/controllers/AuthController.go +++ b/app/controllers/AuthController.go @@ -4,6 +4,7 @@ import ( "github.com/leanote/leanote/app/info" . "github.com/leanote/leanote/app/lea" "github.com/revel/revel" + "strings" // "strconv" ) @@ -127,6 +128,8 @@ func (c Auth) DoRegister(email, pwd, iu string) revel.Result { return c.RenderRe(re) } + email = strings.ToLower(email) + // 注册 re.Ok, re.Msg = authService.Register(email, pwd, iu) @@ -141,6 +144,7 @@ func (c Auth) DoRegister(email, pwd, iu string) revel.Result { //-------- // 找回密码 func (c Auth) FindPassword() revel.Result { + c.SetLocale() c.RenderArgs["title"] = c.Message("findPassword") c.RenderArgs["subTitle"] = c.Message("findPassword") return c.RenderTemplate("home/find_password.html") @@ -154,6 +158,7 @@ func (c Auth) DoFindPassword(email string) revel.Result { // 点击链接后, 先验证之 func (c Auth) FindPassword2(token string) revel.Result { + c.SetLocale() c.RenderArgs["title"] = c.Message("findPassword") c.RenderArgs["subTitle"] = c.Message("findPassword") if token == "" { diff --git a/app/controllers/NoteController.go b/app/controllers/NoteController.go index 1e029fe..1c34cde 100644 --- a/app/controllers/NoteController.go +++ b/app/controllers/NoteController.go @@ -335,11 +335,11 @@ func (c Note) ToPdf(noteId, appKey string) revel.Result { // 虽然传了cookie但是这里还是不能得到userId, 所以还是通过appKey来验证之 appKeyTrue, _ := revel.Config.String("app.secret") if appKeyTrue != appKey { - return c.RenderText("error") + return c.RenderText("auth error") } note := noteService.GetNoteById(noteId) if note.NoteId == "" { - return c.RenderText("error") + return c.RenderText("no note") } noteUserId := note.UserId.Hex() @@ -428,7 +428,7 @@ func (c Note) ExportPdf(noteId string) revel.Result { // 是否是有权限协作的 if !note.IsBlog && !shareService.HasReadPerm(noteUserId, userId, noteId) { re.Msg = "No Perm" - return c.RenderText("error") + return c.RenderText("No Perm") } } diff --git a/app/controllers/PreviewController.go b/app/controllers/PreviewController.go index 45e7524..0ef55d6 100644 --- a/app/controllers/PreviewController.go +++ b/app/controllers/PreviewController.go @@ -23,7 +23,7 @@ type Preview struct { // 得到要预览的主题绝对路径 func (c Preview) getPreviewThemeAbsolutePath(themeId string) bool { if themeId != "" { - c.Session["themeId"] = themeId // 存到session中, 下次的url就不能带了 + c.Session["themeId"] = themeId // 存到session中, 下次的url就不能带了, 待优化, 有时会取不到 } else { themeId = c.Session["themeId"] // 直接从session中获取 } diff --git a/app/controllers/api/ApiNoteController.go b/app/controllers/api/ApiNoteController.go index d7254c6..09439b5 100644 --- a/app/controllers/api/ApiNoteController.go +++ b/app/controllers/api/ApiNoteController.go @@ -540,7 +540,6 @@ func (c ApiNote) GetHistories(noteId string) revel.Result { // 0.2 新增 // 导出成PDF -// test localhost:9000/api/note/exportPdf?noteId=554f07bf05fcd15fa9000000&token=562211dc99c37ba6a7000001 func (c ApiNote) ExportPdf(noteId string) revel.Result { re := info.NewApiRe() userId := c.getUserId() diff --git a/app/controllers/member/MemberBlogController.go b/app/controllers/member/MemberBlogController.go index a546bd2..304a343 100644 --- a/app/controllers/member/MemberBlogController.go +++ b/app/controllers/member/MemberBlogController.go @@ -74,7 +74,7 @@ func (c MemberBlog) Index(sorter, keywords string) revel.Result { userInfo := userService.GetUserInfo(userId) c.RenderArgs["userInfo"] = userInfo - c.RenderArgs["title"] = "Posts" + c.RenderArgs["title"] = c.Message("Posts") pageNumber := c.GetPage() sorterField, isAsc := c.getSorter("CreatedTime", false, []string{"title", "urlTitle", "updatedTime", "publicTime", "createdTime"}) pageInfo, blogs := blogService.ListAllBlogs(c.GetUserId(), "", keywords, false, pageNumber, userPageSize, sorterField, isAsc) @@ -85,6 +85,8 @@ func (c MemberBlog) Index(sorter, keywords string) revel.Result { userAndBlog := userService.GetUserAndBlog(c.GetUserId()) c.RenderArgs["userAndBlog"] = userAndBlog + c.common() + return c.RenderTemplate("member/blog/list.html") } @@ -97,7 +99,8 @@ func (c MemberBlog) UpdateBlogUrlTitle(noteId, urlTitle string) revel.Result { // 修改笔记的urlTitle func (c MemberBlog) UpdateBlogAbstract(noteId string) revel.Result { - c.RenderArgs["title"] = "Update Post Abstract" + c.common() + c.RenderArgs["title"] = c.Message("Update Post Abstract") note := noteService.GetNoteAndContent(noteId, c.GetUserId()) if !note.Note.IsBlog { return c.E404() @@ -107,7 +110,6 @@ func (c MemberBlog) UpdateBlogAbstract(noteId string) revel.Result { return c.RenderTemplate("member/blog/update_abstract.html") } func (c MemberBlog) DoUpdateBlogAbstract(noteId, imgSrc, desc, abstract string) revel.Result { - re := info.NewRe() re.Ok = blogService.UpateBlogAbstract(c.GetUserId(), noteId, imgSrc, desc, abstract) return c.RenderJson(re) @@ -116,24 +118,24 @@ func (c MemberBlog) DoUpdateBlogAbstract(noteId, imgSrc, desc, abstract string) // 基本信息设置 func (c MemberBlog) Base() revel.Result { c.common() - c.RenderArgs["title"] = "Blog Base Info" + c.RenderArgs["title"] = c.Message("Blog Base Info") return c.RenderTemplate("member/blog/base.html") } func (c MemberBlog) Comment() revel.Result { c.common() - c.RenderArgs["title"] = "Comment" + c.RenderArgs["title"] = c.Message("Comment") return c.RenderTemplate("member/blog/comment.html") } func (c MemberBlog) Paging() revel.Result { c.common() - c.RenderArgs["title"] = "Paging" + c.RenderArgs["title"] = c.Message("Paging") return c.RenderTemplate("member/blog/paging.html") } func (c MemberBlog) Cate() revel.Result { userBlog := c.common() - c.RenderArgs["title"] = "Cate" + c.RenderArgs["title"] = c.Message("Category") notebooks := blogService.ListBlogNotebooks(c.GetUserId()) notebooksMap := map[string]info.Notebook{} @@ -190,10 +192,10 @@ func (c MemberBlog) DoAddOrUpdateSingle(singleId, title, content string) revel.R } func (c MemberBlog) AddOrUpdateSingle(singleId string) revel.Result { c.common() - c.RenderArgs["title"] = "Add Single" + c.RenderArgs["title"] = c.Message("Add Single") c.RenderArgs["singleId"] = singleId if singleId != "" { - c.RenderArgs["title"] = "Update Single" + c.RenderArgs["title"] = c.Message("Update Single") c.RenderArgs["single"] = blogService.GetSingle(singleId) } return c.RenderTemplate("member/blog/add_single.html") @@ -219,7 +221,7 @@ func (c MemberBlog) UpdateSingleUrlTitle(singleId, urlTitle string) revel.Result func (c MemberBlog) Single() revel.Result { c.common() - c.RenderArgs["title"] = "Cate" + c.RenderArgs["title"] = c.Message("Single") c.RenderArgs["singles"] = blogService.GetSingles(c.GetUserId()) return c.RenderTemplate("member/blog/single.html") @@ -234,7 +236,7 @@ func (c MemberBlog) Theme() revel.Result { c.RenderArgs["optionThemes"] = themeService.GetDefaultThemes() - c.RenderArgs["title"] = "Theme" + c.RenderArgs["title"] = c.Message("Theme") return c.RenderTemplate("member/blog/theme.html") } @@ -251,7 +253,7 @@ func (c MemberBlog) UpdateTheme(themeId string, isNew int) revel.Result { } c.common() - c.RenderArgs["title"] = "Upate Theme" + c.RenderArgs["title"] = c.Message("Update Theme") c.RenderArgs["isNew"] = isNew // 先复制之 @@ -443,8 +445,8 @@ func (c MemberBlog) ImportTheme() revel.Result { if err != nil { re.Msg = fmt.Sprintf("%v", err) return c.RenderJson(re) - } + defer file.Close() // 生成上传路径 userId := c.GetUserId() diff --git a/app/controllers/member/MemberGroupController.go b/app/controllers/member/MemberGroupController.go index dc6072a..f5fcf5a 100644 --- a/app/controllers/member/MemberGroupController.go +++ b/app/controllers/member/MemberGroupController.go @@ -14,7 +14,7 @@ type MemberGroup struct { func (c MemberGroup) Index() revel.Result { c.SetUserInfo() c.SetLocale() - c.RenderArgs["title"] = "My Group" + c.RenderArgs["title"] = c.Message("My Group") c.RenderArgs["groups"] = groupService.GetGroupsAndUsers(c.GetUserId()) return c.RenderTemplate("member/group/index.html") } diff --git a/app/controllers/member/MemberIndexController.go b/app/controllers/member/MemberIndexController.go index 50caac6..98b570b 100644 --- a/app/controllers/member/MemberIndexController.go +++ b/app/controllers/member/MemberIndexController.go @@ -13,7 +13,7 @@ type MemberIndex struct { // admin 主页 func (c MemberIndex) Index() revel.Result { c.SetUserInfo() - c.RenderArgs["title"] = "Leanote Member Center" + c.RenderArgs["title"] = c.Message("Leanote Member Center") c.RenderArgs["countNote"] = noteService.CountNote(c.GetUserId()) c.RenderArgs["countBlog"] = noteService.CountBlog(c.GetUserId()) diff --git a/app/controllers/member/MemberUserController.go b/app/controllers/member/MemberUserController.go index e7f18b6..4d22301 100644 --- a/app/controllers/member/MemberUserController.go +++ b/app/controllers/member/MemberUserController.go @@ -13,28 +13,28 @@ type MemberUser struct { func (c MemberUser) Username() revel.Result { c.SetUserInfo() c.SetLocale() - c.RenderArgs["title"] = "Username" + c.RenderArgs["title"] = c.Message("Username") return c.RenderTemplate("member/user/username.html") } func (c MemberUser) Email() revel.Result { c.SetUserInfo() c.SetLocale() - c.RenderArgs["title"] = "Email" + c.RenderArgs["title"] = c.Message("Email") return c.RenderTemplate("member/user/email.html") } func (c MemberUser) Password() revel.Result { c.SetUserInfo() c.SetLocale() - c.RenderArgs["title"] = "Password" + c.RenderArgs["title"] = c.Message("Password") return c.RenderTemplate("member/user/password.html") } func (c MemberUser) Avatar() revel.Result { c.SetUserInfo() c.SetLocale() - c.RenderArgs["title"] = "Avatar" + c.RenderArgs["title"] = c.Message("Avatar") c.RenderArgs["globalConfigs"] = configService.GetGlobalConfigForUser() return c.RenderTemplate("member/user/avatar.html") } diff --git a/app/service/ShareService.go b/app/service/ShareService.go index 6e251fe..45e3c7e 100644 --- a/app/service/ShareService.go +++ b/app/service/ShareService.go @@ -470,7 +470,8 @@ func (this *ShareService) GetShareNoteContent(noteId, myUserId, sharedUserId str // 或者, 其notebook共享了我 // Log(this.HasSharedNote(noteId, myUserId)) // Log(this.HasSharedNotebook(noteId, myUserId, sharedUserId)) - Log(this.HasReadPerm(sharedUserId, myUserId, noteId)) + // Log(this.HasReadPerm(sharedUserId, myUserId, noteId)) + if this.HasReadPerm(sharedUserId, myUserId, noteId) { // if this.HasSharedNote(noteId, myUserId) || this.HasSharedNotebook(noteId, myUserId, sharedUserId) { db.Get(db.NoteContents, noteId, ¬eContent) diff --git a/app/service/ThemeService.go b/app/service/ThemeService.go index e09d7f9..92c693f 100644 --- a/app/service/ThemeService.go +++ b/app/service/ThemeService.go @@ -618,8 +618,6 @@ func (this *ThemeService) hasRound(vector [][]int, size int) (ok bool) { for i := 0; i < size; i++ { visited := make([]int, size) if this.hasRoundEach(vector, i, size, visited) { - Log(">>") - Log(i) return true } } @@ -629,8 +627,6 @@ func (this *ThemeService) hasRound(vector [][]int, size int) (ok bool) { // 从每个节点出发, 判断是否有环 func (this *ThemeService) hasRoundEach(vector [][]int, index int, size int, visited []int) (ok bool) { if visited[index] > 0 { - Log("<") - Log(index) return true } visited[index] = 1 diff --git a/app/views/member/blog/add_single.html b/app/views/member/blog/add_single.html index 9b00f62..47c4dfd 100644 --- a/app/views/member/blog/add_single.html +++ b/app/views/member/blog/add_single.html @@ -28,8 +28,10 @@
    -
    - +
    +
    +
    {{if .single}}{{.single.Content|raw}}{{end}}
    +
    @@ -40,28 +42,16 @@ - {{template "member/footer.html" .}} -{{template "member/end.html" .}} \ No newline at end of file +{{template "member/end.html" .}} diff --git a/app/views/member/blog/single.html b/app/views/member/blog/single.html index 23aa5bf..9310bf8 100644 --- a/app/views/member/blog/single.html +++ b/app/views/member/blog/single.html @@ -1,5 +1,5 @@ {{template "member/top.html" .}} -

    {{msg . "single"}}

    +

    {{msg . "Single"}}

    @@ -47,22 +47,22 @@ $(function() { }); ajaxPost("/member/blog/sortSingles", {singleIds: ids}, function(re){ if(reIsOk(re)) { - art.tips("Success"); + art.tips(getMsg("Success")); } else { - art.alert(re.Msg || "error"); + art.alert(re.Msg || getMsg("Error")); } }); }); $(".page-delete").click(function() { var singleId = $(this).data('id'); - art.confirm("Are you sure ?", function() { + art.confirm(getMsg("Are you sure ?"), function() { ajaxPost("/member/blog/deleteSingle", {singleId: singleId}, function(re){ if(reIsOk(re)) { - art.tips("Success"); + art.tips(getMsg("Success")); location.reload(); } else { - art.alert(re.Msg || "error"); + art.alert(re.Msg || getMsg("Error")); } }); }); @@ -76,7 +76,7 @@ $(function() { if(reIsOk(re)) { $t.val(re.Item); } else { - art.alert(re.Msg || "error"); + art.alert(re.Msg || getMsg("Error")); } }); }); diff --git a/app/views/member/blog/theme.html b/app/views/member/blog/theme.html index 7c62b29..fb1823d 100644 --- a/app/views/member/blog/theme.html +++ b/app/views/member/blog/theme.html @@ -1,7 +1,7 @@ {{template "member/top.html" .}}

    - {{msg . "themeSet"}} + {{msg . "theme"}} ({{msg . "needHelp"}} Leanote Blog Theme Api) @@ -138,10 +138,10 @@

    {{template "member/footer.html" .}} - + + + diff --git a/app/views/member/blog/update_theme.html b/app/views/member/blog/update_theme.html index 7947b3d..d39871d 100644 --- a/app/views/member/blog/update_theme.html +++ b/app/views/member/blog/update_theme.html @@ -11,8 +11,8 @@ {{msg . "preview"}} - ({{msg . "needHelp"}} - Leanote Blog Theme Api) + + {{msg . "needHelp"}} {{msg . "Leanote Blog Theme Api"}}
    @@ -49,7 +49,7 @@
    {{msg . "tplStyleScript"}}:
    -
    +
    {{range .myTpls}} @@ -67,6 +67,7 @@
    +
    @@ -74,7 +75,7 @@
    -
    +
    @@ -107,7 +108,7 @@
    {{template "member/footer.html" .}} - + diff --git a/app/views/member/footer.html b/app/views/member/footer.html index ab40505..f6a00f0 100644 --- a/app/views/member/footer.html +++ b/app/views/member/footer.html @@ -23,13 +23,15 @@ $(function() { if(fullPath == "/member/index") { fullPath = "/member"; + } else if (fullPath == '/member/blog/updateTheme') { + fullPath = '/member/blog/theme'; } + $("#nav > li").removeClass("active"); - // alert(fullPath); // 自己 var $thisLi = $('#nav a[href="' + fullPath + '"]').parent(); $thisLi.addClass("active"); // 父也active $thisLi.parent().parent().addClass('active'); }); - \ No newline at end of file + diff --git a/app/views/member/group/index.html b/app/views/member/group/index.html index 715588e..9797416 100644 --- a/app/views/member/group/index.html +++ b/app/views/member/group/index.html @@ -113,7 +113,7 @@ var group = { addGroupEvent: function() { var self = this; $('.btn-add-group').click(function() { - ajaxPost("/member/group/addGroup", {title: "Group Title"}, function(re) { + ajaxPost("/member/group/addGroup", {title: getMsg("Group Title")}, function(re) { if(reIsOk(re)) { var group = re.Item; self.groupsO.prepend(self.tGroupO.render(group)) @@ -136,7 +136,7 @@ var group = { var groupId = $(this).closest(".each-group").data("id"); ajaxPost("/member/group/updateGroupTitle", {groupId: groupId, title: val}, function(re) { if(reIsOk(re)) { - art.tips("Success") + art.tips(getMsg("Success")); t.data('ever', val) } }) @@ -147,11 +147,11 @@ var group = { var self = this; self.groupsO.on("click", ".delete-group", function() { var t = $(this); - art.confirm("Are you sure ?", function() { + art.confirm(getMsg("Are you sure ?"), function() { var groupId = t.closest(".each-group").data("id"); ajaxPost("/member/group/deleteGroup", {groupId: groupId}, function(re) { if(reIsOk(re)) { - art.tips("Success"); + art.tips(getMsg("Success")); t.closest(".each-group").remove(); } else { art.alert(re.Msg); @@ -182,7 +182,7 @@ var group = { var p = t.closest("li"); ajaxPost("/member/group/addUser", {groupId: groupId, email: email}, function(re) { if(reIsOk(re)) { - art.tips("Success"); + art.tips(getMsg("Success")); var html = self.tUserO.render(re.Item) p.before(html); t.val(""); @@ -198,12 +198,12 @@ var group = { var self = this; self.groupsO.on("click", ".delete-user", function() { var t = $(this); - art.confirm("Are you sure ?", function() { + art.confirm(getMsg("Are you sure ?"), function() { var groupId = t.closest(".each-group").data("id"); var userId = t.closest("li").data("id"); ajaxPost("/member/group/deleteUser", {groupId: groupId, userId: userId}, function(re) { if(reIsOk(re)) { - art.tips("Success"); + art.tips(getMsg("Success")); t.closest("li").remove(); } else { art.alert(re.Msg); diff --git a/app/views/member/nav.html b/app/views/member/nav.html index 443f381..ef2bc66 100644 --- a/app/views/member/nav.html +++ b/app/views/member/nav.html @@ -1,4 +1,4 @@ - diff --git a/app/views/member/top.html b/app/views/member/top.html index 7911ed9..164edd9 100644 --- a/app/views/member/top.html +++ b/app/views/member/top.html @@ -50,7 +50,7 @@
    -