Skip to content

Commit e6ebfc4

Browse files
committed
edited notes: move edited-notes related code to own module
moved as-is
1 parent bbcc670 commit e6ebfc4

File tree

3 files changed

+89
-80
lines changed

3 files changed

+89
-80
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import beccaService from "../../becca/becca_service.js";
2+
import sql from "../../services/sql.js";
3+
import cls from "../../services/cls.js";
4+
import becca from "../../becca/becca.js";
5+
import type { Request } from "express";
6+
import { NotePojo } from "../../becca/becca-interface.js";
7+
import type BNote from "../../becca/entities/bnote.js";
8+
import { EditedNotesResponse } from "@triliumnext/commons";
9+
10+
interface NotePath {
11+
noteId: string;
12+
branchId?: string;
13+
title: string;
14+
notePath: string[];
15+
path: string;
16+
}
17+
18+
interface NotePojoWithNotePath extends NotePojo {
19+
notePath?: string[] | null;
20+
}
21+
22+
function getEditedNotesOnDate(req: Request) {
23+
24+
const noteIds = sql.getColumn<string>(/*sql*/`\
25+
SELECT notes.*
26+
FROM notes
27+
WHERE noteId IN (
28+
SELECT noteId FROM notes
29+
WHERE
30+
(notes.dateCreated LIKE :date OR notes.dateModified LIKE :date)
31+
AND (notes.noteId NOT LIKE '\\_%' ESCAPE '\\')
32+
UNION ALL
33+
SELECT noteId FROM revisions
34+
WHERE revisions.dateCreated LIKE :date
35+
)
36+
ORDER BY isDeleted
37+
LIMIT 50`,
38+
{ date: `${req.params.date}%` }
39+
);
40+
41+
let notes = becca.getNotes(noteIds, true);
42+
43+
// Narrow down the results if a note is hoisted, similar to "Jump to note".
44+
const hoistedNoteId = cls.getHoistedNoteId();
45+
if (hoistedNoteId !== "root") {
46+
notes = notes.filter((note) => note.hasAncestor(hoistedNoteId));
47+
}
48+
49+
return notes.map((note) => {
50+
const notePath = getNotePathData(note);
51+
52+
const notePojo: NotePojoWithNotePath = note.getPojo();
53+
notePojo.notePath = notePath ? notePath.notePath : null;
54+
55+
return notePojo;
56+
}) satisfies EditedNotesResponse;
57+
}
58+
59+
function getNotePathData(note: BNote): NotePath | undefined {
60+
const retPath = note.getBestNotePath();
61+
62+
if (retPath) {
63+
const noteTitle = beccaService.getNoteTitleForPath(retPath);
64+
65+
let branchId;
66+
67+
if (note.isRoot()) {
68+
branchId = "none_root";
69+
} else {
70+
const parentNote = note.parents[0];
71+
branchId = becca.getBranchFromChildAndParent(note.noteId, parentNote.noteId)?.branchId;
72+
}
73+
74+
return {
75+
noteId: note.noteId,
76+
branchId: branchId,
77+
title: noteTitle,
78+
notePath: retPath,
79+
path: retPath.join("/")
80+
};
81+
}
82+
}
83+
84+
export default {
85+
getEditedNotesOnDate,
86+
};

apps/server/src/routes/api/revisions.ts

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
11
"use strict";
22

3-
import beccaService from "../../becca/becca_service.js";
43
import utils from "../../services/utils.js";
54
import sql from "../../services/sql.js";
6-
import cls from "../../services/cls.js";
75
import path from "path";
86
import becca from "../../becca/becca.js";
97
import blobService from "../../services/blob.js";
108
import eraseService from "../../services/erase.js";
119
import type { Request, Response } from "express";
1210
import type BRevision from "../../becca/entities/brevision.js";
13-
import type BNote from "../../becca/entities/bnote.js";
14-
import type { NotePojo } from "../../becca/becca-interface.js";
15-
import { EditedNotesResponse, RevisionItem, RevisionPojo, RevisionRow } from "@triliumnext/commons";
16-
17-
interface NotePath {
18-
noteId: string;
19-
branchId?: string;
20-
title: string;
21-
notePath: string[];
22-
path: string;
23-
}
24-
25-
interface NotePojoWithNotePath extends NotePojo {
26-
notePath?: string[] | null;
27-
}
11+
import { RevisionItem, RevisionPojo } from "@triliumnext/commons";
2812

2913
function getRevisionBlob(req: Request) {
3014
const preview = req.query.preview === "true";
@@ -151,73 +135,11 @@ function restoreRevision(req: Request) {
151135
}
152136
}
153137

154-
function getEditedNotesOnDate(req: Request) {
155-
const noteIds = sql.getColumn<string>(/*sql*/`\
156-
SELECT notes.*
157-
FROM notes
158-
WHERE noteId IN (
159-
SELECT noteId FROM notes
160-
WHERE
161-
(notes.dateCreated LIKE :date OR notes.dateModified LIKE :date)
162-
AND (notes.noteId NOT LIKE '\\_%' ESCAPE '\\')
163-
UNION ALL
164-
SELECT noteId FROM revisions
165-
WHERE revisions.dateCreated LIKE :date
166-
)
167-
ORDER BY isDeleted
168-
LIMIT 50`,
169-
{ date: `${req.params.date}%` }
170-
);
171-
172-
let notes = becca.getNotes(noteIds, true);
173-
174-
// Narrow down the results if a note is hoisted, similar to "Jump to note".
175-
const hoistedNoteId = cls.getHoistedNoteId();
176-
if (hoistedNoteId !== "root") {
177-
notes = notes.filter((note) => note.hasAncestor(hoistedNoteId));
178-
}
179-
180-
return notes.map((note) => {
181-
const notePath = getNotePathData(note);
182-
183-
const notePojo: NotePojoWithNotePath = note.getPojo();
184-
notePojo.notePath = notePath ? notePath.notePath : null;
185-
186-
return notePojo;
187-
}) satisfies EditedNotesResponse;
188-
}
189-
190-
function getNotePathData(note: BNote): NotePath | undefined {
191-
const retPath = note.getBestNotePath();
192-
193-
if (retPath) {
194-
const noteTitle = beccaService.getNoteTitleForPath(retPath);
195-
196-
let branchId;
197-
198-
if (note.isRoot()) {
199-
branchId = "none_root";
200-
} else {
201-
const parentNote = note.parents[0];
202-
branchId = becca.getBranchFromChildAndParent(note.noteId, parentNote.noteId)?.branchId;
203-
}
204-
205-
return {
206-
noteId: note.noteId,
207-
branchId: branchId,
208-
title: noteTitle,
209-
notePath: retPath,
210-
path: retPath.join("/")
211-
};
212-
}
213-
}
214-
215138
export default {
216139
getRevisionBlob,
217140
getRevisions,
218141
getRevision,
219142
downloadRevision,
220-
getEditedNotesOnDate,
221143
eraseAllRevisions,
222144
eraseAllExcessRevisions,
223145
eraseRevision,

apps/server/src/routes/routes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import attachmentsApiRoute from "./api/attachments.js";
2222
import autocompleteApiRoute from "./api/autocomplete.js";
2323
import cloningApiRoute from "./api/cloning.js";
2424
import revisionsApiRoute from "./api/revisions.js";
25+
import editedNotesApiRoute from "./api/edited-notes.js";
2526
import recentChangesApiRoute from "./api/recent_changes.js";
2627
import optionsApiRoute from "./api/options.js";
2728
import passwordApiRoute from "./api/password.js";
@@ -349,7 +350,7 @@ function register(app: express.Application) {
349350
apiRoute(GET, "/api/other/icon-usage", otherRoute.getIconUsage);
350351
apiRoute(PST, "/api/other/render-markdown", otherRoute.renderMarkdown);
351352
apiRoute(GET, "/api/recent-changes/:ancestorNoteId", recentChangesApiRoute.getRecentChanges);
352-
apiRoute(GET, "/api/edited-notes/:date", revisionsApiRoute.getEditedNotesOnDate);
353+
apiRoute(GET, "/api/edited-notes/:date", editedNotesApiRoute.getEditedNotesOnDate);
353354

354355
apiRoute(PST, "/api/note-map/:noteId/tree", noteMapRoute.getTreeMap);
355356
apiRoute(PST, "/api/note-map/:noteId/link", noteMapRoute.getLinkMap);

0 commit comments

Comments
 (0)