Skip to content

Commit

Permalink
临时保存优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Hansanshi committed Dec 31, 2020
1 parent 864c6aa commit e30469e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ public ServerResponse delNotebook(@PathVariable String notebookName){
*/
@DeleteMapping("/{notebookName}/{noteTitle}")
public ServerResponse delNote(@PathVariable String notebookName,
@PathVariable String noteTitle){
@PathVariable String noteTitle,
Boolean delDraft){
if (Boolean.TRUE.equals(delDraft)) {
noteService.delTmpSavedNote(noteTitle, notebookName);
return ServerResponse.buildSuccessResponse();
}
return noteService.deleteNote(notebookName, noteTitle);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/ink/markidea/note/service/INoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface INoteService {
*/
void tmpSaveNote(String noteTitle, String notebookName, String content);

void delTmpSavedNote(String noteTitle, String notebookName);

/**
* delete note
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ public void tmpSaveNote(String noteTitle, String notebookName, String content) {
invalidateCache(buildUserNoteKey(notebookName, noteTitle));
}

@Override
public void delTmpSavedNote(String noteTitle, String notebookName) {
GitUtil.discardChange(getOrCreateUserGit(), getRelativeFileName(notebookName, noteTitle));
}

@Override
public ServerResponse deleteNote(String notebookName, String noteTitle){
String relativeFileName = getRelativeFileName(notebookName,noteTitle);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/ink/markidea/note/util/GitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,13 @@ public static Set<String> getModifiedButUnCommitted(Git git, String dirPath) {
throw new RuntimeException("git status error");
}
}

public static void discardChange(Git git, String path){
try {
git.checkout().addPath(path).call();
} catch (GitAPIException e) {
e.printStackTrace();
}
}

}

0 comments on commit e30469e

Please sign in to comment.