Skip to content

Build your personal knowledge base with Trilium Notes

feat(tasks): add GET API

Elian Doran98dff6130506
diff --git a/src/becca/becca-interface.ts b/src/becca/becca-interface.ts
index cdee5d1cd2..8da95c39fa 100644
--- a/src/becca/becca-interface.ts
+++ b/src/becca/becca-interface.ts
@@ -12,6 +12,7 @@ import type { AttachmentRow, BlobRow, RevisionRow } from "./entities/rows.js";
import BBlob from "./entities/bblob.js";
import BRecentNote from "./entities/brecent_note.js";
import type AbstractBeccaEntity from "./entities/abstract_becca_entity.js";
+import type BTask from "./entities/btask.js";
interface AttachmentOpts {
includeContentLength?: boolean;
@@ -32,6 +33,7 @@ export default class Becca {
attributeIndex!: Record<string, BAttribute[]>;
options!: Record<string, BOption>;
etapiTokens!: Record<string, BEtapiToken>;
+ tasks!: Record<string, BTask>;
allNoteSetCache: NoteSet | null;
@@ -48,6 +50,7 @@ export default class Becca {
this.attributeIndex = {};
this.options = {};
this.etapiTokens = {};
+ this.tasks = {};
this.dirtyNoteSetCache();
@@ -213,6 +216,10 @@ export default class Becca {
return this.etapiTokens[etapiTokenId];
}
+ getTasks(): BTask[] {
+ return Object.values(this.tasks);
+ }
+
getEntity<T extends AbstractBeccaEntity<T>>(entityName: string, entityId: string): AbstractBeccaEntity<T> | null {
if (!entityName || !entityId) {
return null;
diff --git a/src/becca/entities/btask.ts b/src/becca/entities/btask.ts
index a0c8ce2322..d84d09e7e5 100644
--- a/src/becca/entities/btask.ts
+++ b/src/becca/entities/btask.ts
@@ -31,6 +31,7 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
}
this.updateFromRow(row);
+ this.init();
}
get isDeleted() {
@@ -43,6 +44,16 @@ export default class BTask extends AbstractBeccaEntity<BOption> {
this.title = row.title;
this.dueDate = row.dueDate;
this._isDeleted = !!row.isDeleted;
+
+ if (this.taskId) {
+ this.becca.tasks[this.taskId] = this;
+ }
+ }
+
+ init() {
+ if (this.taskId) {
+ this.becca.tasks[this.taskId] = this;
+ }
}
getPojo() {
diff --git a/src/routes/api/tasks.ts b/src/routes/api/tasks.ts
new file mode 100644
index 0000000000..ac4d0a5b8b
--- /dev/null
+++ b/src/routes/api/tasks.ts
@@ -0,0 +1,5 @@
+import * as tasksService from "../../services/tasks.js";
+
+export function getTasks() {
+ return tasksService.getTasks();
+}
diff --git a/src/routes/routes.ts b/src/routes/routes.ts
index 05c7612f2d..8eaa1f96bb 100644
--- a/src/routes/routes.ts
+++ b/src/routes/routes.ts
@@ -72,6 +72,7 @@ import etapiSpecRoute from "../etapi/spec.js";
import etapiBackupRoute from "../etapi/backup.js";
import apiDocsRoute from "./api_docs.js";
+import * as tasksRoute from "./api/tasks.js";
const MAX_ALLOWED_FILE_SIZE_MB = 250;
const GET = "get",
@@ -279,6 +280,8 @@ function register(app: express.Application) {
apiRoute(PATCH, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.patchToken);
apiRoute(DEL, "/api/etapi-tokens/:etapiTokenId", etapiTokensApiRoutes.deleteToken);
+ apiRoute(GET, "/api/tasks", tasksRoute.getTasks);
+
// in case of local electron, local calls are allowed unauthenticated, for server they need auth
const clipperMiddleware = isElectron ? [] : [auth.checkEtapiToken];
diff --git a/src/services/tasks.ts b/src/services/tasks.ts
new file mode 100644
index 0000000000..58fa6d8bb1
--- /dev/null
+++ b/src/services/tasks.ts
@@ -0,0 +1,5 @@
+import becca from "../becca/becca.js";
+
+export function getTasks() {
+ return becca.getTasks();
+}