diff --git a/app/controllers/api/ApiNoteController.go b/app/controllers/api/ApiNoteController.go
index 09439b5..d251494 100644
--- a/app/controllers/api/ApiNoteController.go
+++ b/app/controllers/api/ApiNoteController.go
@@ -8,8 +8,9 @@ import (
"gopkg.in/mgo.v2/bson"
"os"
"os/exec"
- "strings"
+ // "strings"
"time"
+ "regexp"
// "github.com/leanote/leanote/app/types"
// "io/ioutil"
// "fmt"
@@ -158,11 +159,31 @@ func (c ApiNote) fixPostNotecontent(noteOrContent *info.ApiNote) {
if noteOrContent.Content == "" {
return
}
+
files := noteOrContent.Files
if files != nil && len(files) > 0 {
for _, file := range files {
if file.LocalFileId != "" {
- noteOrContent.Content = strings.Replace(noteOrContent.Content, "fileId="+file.LocalFileId, "fileId="+file.FileId, -1)
+ LogJ(file)
+ if !file.IsAttach {
+ reg, _ := regexp.Compile(`"https*://[^/]*?/api/file/getImage\?fileId=`+file.LocalFileId)
+ // Log(reg)
+ noteOrContent.Content = reg.ReplaceAllString(noteOrContent.Content, `"/api/file/getImage?fileId=`+file.FileId)
+
+ // // "http://a.com/api/file/getImage?fileId=localId" => /api/file/getImage?fileId=serverId
+ // noteOrContent.Content = strings.Replace(noteOrContent.Content,
+ // baseUrl + "/api/file/getImage?fileId="+file.LocalFileId,
+ // "/api/file/getImage?fileId="+file.FileId, -1)
+ } else {
+ reg, _ := regexp.Compile(`"https*://[^/]*?/api/file/getAttach\?fileId=`+file.LocalFileId)
+ Log(reg)
+ noteOrContent.Content = reg.ReplaceAllString(noteOrContent.Content, `"/api/file/getAttach?fileId=`+file.FileId)
+ /*
+ noteOrContent.Content = strings.Replace(noteOrContent.Content,
+ baseUrl + "/api/file/getAttach?fileId="+file.LocalFileId,
+ "/api/file/getAttach?fileId="+file.FileId, -1)
+ */
+ }
}
}
}
@@ -352,6 +373,7 @@ func (c ApiNote) UpdateNote(noteOrContent info.ApiNote) revel.Result {
Log("conflict")
return c.RenderJson(re)
}
+ Log("没有冲突")
// 如果传了files
// TODO 测试
diff --git a/app/service/AttachService.go b/app/service/AttachService.go
index 31d1c0c..f3769ac 100644
--- a/app/service/AttachService.go
+++ b/app/service/AttachService.go
@@ -119,6 +119,7 @@ func (this *AttachService) DeleteAllAttachs(noteId, userId string) bool {
}
// delete attach
+// 删除附件为什么要incrNoteUsn ? 因为可能没有内容要修改的
func (this *AttachService) DeleteAttach(attachId, userId string) (bool, string) {
attach := info.Attach{}
db.Get(db.Attachs, attachId, &attach)
diff --git a/app/service/NoteService.go b/app/service/NoteService.go
index ef22248..6e8e449 100644
--- a/app/service/NoteService.go
+++ b/app/service/NoteService.go
@@ -415,9 +415,15 @@ func (this *NoteService) UpdateNote(updatedUserId, noteId string, needUpdate bso
}
}
+ /*
+ // 这里不再判断, 因为controller已经判断了, 删除附件会新增, 所以不用判断
if usn > 0 && note.Usn != usn {
+ Log("有冲突!!")
+ Log(note.Usn)
+ Log(usn)
return false, "conflict", 0
}
+ */
// 是否已自定义
if note.IsBlog && note.HasSelfDefined {
@@ -1017,6 +1023,8 @@ func (this *NoteService) FixContentBad(content string, isMarkdown bool) string {
return content
}
+// 得到笔记的内容, 此时将笔记内的链接转成标准的Leanote Url
+// 将笔记的图片, 附件链接转换成 site.url/file/getImage?fileId=xxx, site.url/file/getAttach?fileId=xxxx
// 性能更好, 5倍的差距
func (this *NoteService) FixContent(content string, isMarkdown bool) string {
baseUrl := configService.GetSiteUrl()
@@ -1029,12 +1037,19 @@ func (this *NoteService) FixContent(content string, isMarkdown bool) string {
} else {
baseUrlPattern = strings.Replace(baseUrl, "http://", "https*://", 1)
}
+ baseUrlPattern = "(?:" + baseUrlPattern + ")*"
+
+ Log(baseUrlPattern)
patterns := []map[string]string{
+ map[string]string{"src": "src", "middle": "/api/file/getImage", "param": "fileId", "to": "getImage?fileId="},
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": "/api/file/getAtach", "param": "fileId", "to": "getAttach?fileId="},
+
// 该链接已失效, 不再支持
- map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="},
+ // map[string]string{"src": "href", "middle": "/attach/downloadAll", "param": "noteId", "to": "getAllAttachs?noteId="},
}
for _, eachPattern := range patterns {
@@ -1056,6 +1071,8 @@ func (this *NoteService) FixContent(content string, isMarkdown bool) string {
reg2, _ = regexp.Compile("]+?)(" + eachPattern["src"] + `=['"]*` + baseUrlPattern + eachPattern["middle"] + `\?` + eachPattern["param"] + `=([a-z0-9A-Z]{24})["']*)[^>]*>`)
}
+ Log(reg2)
+
content = reg.ReplaceAllStringFunc(content, func(str string) string {
// str=这样的
//
diff --git a/app/tests/note_content_test.go b/app/tests/note_content_test.go
new file mode 100644
index 0000000..d7234a3
--- /dev/null
+++ b/app/tests/note_content_test.go
@@ -0,0 +1,32 @@
+package tests
+
+import (
+ "github.com/leanote/leanote/app/db"
+ "github.com/revel/revel"
+ "testing"
+ // . "github.com/leanote/leanote/app/lea"
+ "github.com/leanote/leanote/app/service"
+ // "regexp"
+ // "gopkg.in/mgo.v2"
+ // "fmt"
+ // "strings"
+)
+
+
+// 可在server端调试
+
+func init() {
+ revel.Init("dev", "github.com/leanote/leanote", "/Users/life/Documents/Go/package_base/src")
+ db.Init("mongodb://localhost:27017/leanote", "leanote")
+ service.InitService()
+ service.ConfigS.InitGlobalConfigs()
+}
+
+func TestApiFixNoteContent2(t *testing.T) {
+ note2 := service.NoteS.GetNote("585df83771c1b17e8a000000", "585df81199c37b6176000004")
+ note := service.NoteS.GetNoteContent("585df83771c1b17e8a000000", "585df81199c37b6176000004")
+ contentFixed := service.NoteS.FixContent(note.Content, false)
+ t.Log(note2.Title)
+ t.Log(note.Content)
+ t.Log(contentFixed)
+}
\ No newline at end of file
diff --git a/app/tests/reg_test.go b/app/tests/reg_test.go
new file mode 100644
index 0000000..706b0c8
--- /dev/null
+++ b/app/tests/reg_test.go
@@ -0,0 +1,26 @@
+package tests
+
+import (
+ // "github.com/leanote/leanote/app/db"
+ "testing"
+ // . "github.com/leanote/leanote/app/lea"
+ // "github.com/leanote/leanote/app/service"
+ // "gopkg.in/mgo.v2"
+ // "fmt"
+ "regexp"
+)
+
+
+// 测试登录
+func TestReg(t *testing.T) {
+ a := `proxy.go`
+ reg, _ := regexp.Compile(`"https*://[^/]*?/api/file/getAttach\?fileId=585e0e9c270a35609300000c`)
+
+ a2 := reg.ReplaceAllString(a, `"`)
+ t.Log(a2)
+}
+
+
+
+
+
diff --git a/app/views/album/index.html b/app/views/album/index.html
index a800bce..226313e 100644
--- a/app/views/album/index.html
+++ b/app/views/album/index.html
@@ -161,6 +161,6 @@ var UrlPrefix = '{{.siteUrl}}';
-->
-
+