public NoteAPIController(AttachService attachService , TokenSerivce tokenSerivce , NoteFileService noteFileService , UserService userService , ConfigFileService configFileService , IHttpContextAccessor accessor, NoteService noteService, NoteContentService noteContentService, NotebookService notebookService, NoteRepositoryService noteRepositoryService, TrashService trashService, EPassService ePass, GMService gMService, DataSignService dataSignService ) : base(attachService, tokenSerivce, noteFileService, userService, configFileService, accessor) { this.attachService = attachService; this.noteService = noteService; this.tokenSerivce = tokenSerivce; this.noteContentService = noteContentService; this.trashService = trashService; this.accessor = accessor; this.notebookService = notebookService; this.noteRepositoryService = noteRepositoryService; this.ePassService = ePass; this.dataSignService = dataSignService; this.gMService = gMService; }
//todo:格式化URL //todo:得到内容 public IActionResult GetNoteContent(string token, string noteId) { ApiRe falseRe = new ApiRe() { Ok = false, Msg = "GetNoteContent_is_error" }; Note note = NoteService.GetNote(MyConvert.HexToLong(noteId), getUserIdByToken(token)); NoteContent noteContent = NoteContentService.GetNoteContent(MyConvert.HexToLong(noteId), getUserIdByToken(token), false); if (noteContent == null || note == null) { return(Json(falseRe, MyJsonConvert.GetOptions())); } if (noteContent != null && !string.IsNullOrEmpty(noteContent.Content)) { noteContent.Content = NoteService.FixContent(noteContent.Content, note.IsMarkdown); } ApiNoteContent apiNote = new ApiNoteContent() { NoteId = note.NoteId, UserId = note.UserId, Content = noteContent.Content }; return(Json(apiNote, MyJsonConvert.GetOptions())); }
public void InsertNoteContentTest() { string ContentJson = System.IO.File.ReadAllText(@"E:\Project\JSON\note\getNoteContent.json"); NoteContent noteConteny = JsonSerializer.Deserialize <NoteContent>(ContentJson, MyJsonConvert.GetOptions()); noteConteny.NoteId = 201901; noteConteny.UpdatedUserId = SnowFlake_Net.GenerateSnowFlakeID(); noteConteny.UserId = SnowFlake_Net.GenerateSnowFlakeID(); NoteContentService.InsertNoteContent(noteConteny); }
public IActionResult getNoteContent(string noteId) { string a = System.IO.File.ReadAllText("TextFile.txt"); var options = new System.Text.Json.JsonSerializerOptions { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; //NoteContent noteContent1 = JsonSerializer.Deserialize<NoteContent>(a, options); //NoteService.InsertNoteContent(noteContent1); NoteContent noteContent = NoteContentService.SelectNoteContent(123123); string json = JsonSerializer.Serialize(noteContent, options); // return Content(a); return(Content(json)); }
public void GetNoteContentTest() { string a = System.IO.File.ReadAllText(@"E:\github\MoreNote\MoreNote\TextFile.txt"); NoteContent noteContent = NoteContentService.SelectNoteContent(123123); string json = JsonSerializer.Serialize(noteContent, MyJsonConvert.GetOptions()); NoteContent noteContent2 = JsonSerializer.Deserialize <NoteContent>(json, MyJsonConvert.GetOptions()); Console.WriteLine(noteContent2.UserId); Console.WriteLine(noteContent2.NoteId); Console.WriteLine(noteContent2.UpdatedUserId); //Console.WriteLine(noteContent2.Content); //string json=JsonConvert.SerializeObject(noteContent); //Console.WriteLine(json); // Assert.Fail(); }
public CommonController(AttachService attachService , TokenSerivce tokenSerivce , NoteFileService noteFileService , UserService userService , ConfigFileService configFileService , IHttpContextAccessor accessor, NoteService noteService, NoteContentService noteContentService, NotebookService notebookService, NoteRepositoryService noteRepositoryService, TrashService trashService ) : base(attachService, tokenSerivce, noteFileService, userService, configFileService, accessor) { this.attachService = attachService; this.noteService = noteService; this.tokenSerivce = tokenSerivce; this.noteContentService = noteContentService; this.trashService = trashService; this.accessor = accessor; this.notebookService = notebookService; this.noteRepositoryService = noteRepositoryService; }
public NoteController(AttachService attachService , TokenSerivce tokenSerivce , NoteFileService noteFileService , UserService userService , ShareService shareService , ConfigFileService configFileService , IWebHostEnvironment env , TagService tagService , TrashService trashService , IHttpContextAccessor accessor , NotebookService notebookService , NoteService noteService , NoteContentService noteContentService ) : base(attachService, tokenSerivce, noteFileService, userService, configFileService, accessor) { this.notebookService = notebookService; this.noteService = noteService; this.noteContentService = noteContentService; this.env = env; this.tagService = tagService; this.trashService = trashService; }
//todo:更新笔记 public JsonResult UpdateNote(ApiNote noteOrContent, string token) { Note noteUpdate = new Note(); var needUpdateNote = false; var re = new ReUpdate(); long tokenUserId = getUserIdByToken(token); var noteId = MyConvert.HexToLong(noteOrContent.NoteId); //-------------校验参数合法性 if (tokenUserId == 0) { re.Msg = "NOlogin"; re.Ok = false; return(Json(re, MyJsonConvert.GetSimpleOptions())); } if (string.IsNullOrEmpty(noteOrContent.NoteId)) { re.Msg = "noteIdNotExists"; re.Ok = false; return(Json(re, MyJsonConvert.GetSimpleOptions())); } if (noteOrContent.Usn < 1) { re.Msg = "usnNotExists"; re.Ok = false; return(Json(re, MyJsonConvert.GetSimpleOptions())); } // 先判断USN的问题, 因为很可能添加完附件后, 会有USN冲突, 这时附件就添错了 var note = NoteService.GetNote(noteId, tokenUserId); var noteContent = NoteContentService.GetNoteContent(note.NoteId, tokenUserId, false); if (note == null || note.NoteId == 0) { re.Msg = "notExists"; re.Ok = false; return(Json(re, MyJsonConvert.GetSimpleOptions())); } //判断服务器版本与客户端版本是否一致 if (note.Usn != noteOrContent.Usn) { re.Msg = "conflict"; re.Ok = false; return(Json(re, MyJsonConvert.GetSimpleOptions())); } //-------------更新文件和附件内容 if (noteOrContent.Files != null && noteOrContent.Files.Length > 0) { for (int i = 0; i < noteOrContent.Files.Length; i++) { var file = noteOrContent.Files[i]; if (file.HasBody) { if (!string.IsNullOrEmpty(file.LocalFileId)) { var result = upload("FileDatas[" + file.LocalFileId + "]", tokenUserId, noteId, file.IsAttach, out long serverFileId, out string msg); if (!result) { if (string.IsNullOrEmpty(msg)) { re.Msg = "fileUploadError"; } if (!string.Equals(msg, "notImage", System.StringComparison.OrdinalIgnoreCase)) { return(Json(re, MyJsonConvert.GetOptions())); } } else { // 建立映射 file.FileId = serverFileId.ToString("x"); noteOrContent.Files[i] = file; } } else { return(Json(new ReUpdate() { Ok = false, Msg = "LocalFileId_Is_NullOrEmpty", Usn = 0 }, MyJsonConvert.GetSimpleOptions())); } } } } //更新用户元数据 //int usn = UserService.IncrUsn(tokenUserId); // 移到外面来, 删除最后一个file时也要处理, 不然总删不掉 // 附件问题, 根据Files, 有些要删除的, 只留下这些 if (noteOrContent.Files != null) { AttachService.UpdateOrDeleteAttachApi(noteId, tokenUserId, noteOrContent.Files); } //-------------更新笔记内容 var afterContentUsn = 0; var contentOk = false; var contentMsg = ""; long contentId = 0; if (noteOrContent.Content != null) { // 把fileId替换下 FixPostNotecontent(ref noteOrContent); // 如果传了Abstract就用之 if (noteOrContent.Abstract != null) { noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Abstract, 200); } else { noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200); } } else { noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteContent.Content, 200); } //上传noteContent的变更 contentOk = NoteContentService.UpdateNoteContent( noteOrContent, out contentMsg, out contentId ); //返回处理结果 if (!contentOk) { re.Ok = false; re.Msg = contentMsg; re.Usn = afterContentUsn; return(Json(re, MyJsonConvert.GetOptions())); } //-------------更新笔记元数据 int afterNoteUsn = 0; var noteOk = false; var noteMsg = ""; noteOk = NoteService.UpdateNote( ref noteOrContent, tokenUserId, contentId, true, true, out noteMsg, out afterNoteUsn ); if (!noteOk) { re.Ok = false; re.Msg = noteMsg; return(Json(re, MyJsonConvert.GetOptions())); } //处理结果 //-------------API返回客户端信息 note = NoteService.GetNote(noteId, tokenUserId); // noteOrContent.NoteId = noteId.ToString("x"); // noteOrContent.UserId = tokenUserId.ToString("x"); // noteOrContent.Title = note.Title; // noteOrContent.Tags = note.Tags; // noteOrContent.IsMarkdown = note.IsMarkdown; // noteOrContent.IsBlog = note.IsBlog; //noteOrContent.IsTrash = note.IsTrash; //noteOrContent.IsDeleted = note.IsDeleted; //noteOrContent.IsTrash = note.IsTrash; //noteOrContent.Usn = note.Usn; //noteOrContent.CreatedTime = note.CreatedTime; //noteOrContent.UpdatedTime = note.UpdatedTime; //noteOrContent.PublicTime = note.PublicTime; noteOrContent.Content = ""; noteOrContent.Usn = afterNoteUsn; noteOrContent.UpdatedTime = DateTime.Now; noteOrContent.IsDeleted = false; noteOrContent.UserId = tokenUserId.ToString("x"); return(Json(noteOrContent, MyJsonConvert.GetOptions())); }