-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (65 loc) · 2.09 KB
/
index.js
File metadata and controls
81 lines (65 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import path from "node:path";
import { fileURLToPath } from "node:url";
import express from "express";
import { readlaterController } from "./lib/controllers/readlater.js";
import { readlaterApiController } from "./lib/controllers/api.js";
import { createIndexes } from "./lib/storage/items.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const defaults = {
mountPath: "/readlater",
};
const router = express.Router();
const publicRouter = express.Router();
export default class ReadLaterEndpoint {
name = "Read It Later endpoint";
constructor(options = {}) {
this.options = { ...defaults, ...options };
this.mountPath = this.options.mountPath;
}
get localesDirectory() {
return path.join(__dirname, "locales");
}
get navigationItems() {
return {
href: this.options.mountPath,
text: "readlater.title",
requiresDatabase: true,
};
}
get shortcutItems() {
return {
url: this.options.mountPath,
name: "readlater.title",
iconName: "bookmark",
requiresDatabase: true,
};
}
get routes() {
router.get("/", readlaterController.list);
router.get("/bookmarklet", readlaterController.bookmarklet);
router.post("/save", readlaterController.save);
router.post("/delete", readlaterController.remove);
return router;
}
/**
* Public routes (no authentication required)
* Read-only JSON API for the frontend page
*/
get routesPublic() {
publicRouter.get("/api/items", readlaterApiController.listItems);
publicRouter.get("/api/sources", readlaterApiController.listSources);
return publicRouter;
}
init(Indiekit) {
console.info("[ReadLater] Initializing read-it-later plugin");
Indiekit.addCollection("readlater_items");
Indiekit.addEndpoint(this);
// Store mount path in application config for other plugins to detect
Indiekit.config.application.readlaterEndpoint = this.mountPath;
if (Indiekit.database) {
createIndexes(Indiekit).catch((error) => {
console.warn("[ReadLater] Index creation failed:", error.message);
});
}
}
}