Notes/src/routes/api/other.ts

42 lines
1.0 KiB
TypeScript
Raw Normal View History

import type { Request } from "express";
2024-04-06 21:58:32 +03:00
import becca from "../../becca/becca.js";
import markdownService from "../../services/import/markdown.js";
function getIconUsage() {
2024-04-06 21:58:32 +03:00
const iconClassToCountMap: Record<string, number> = {};
2025-01-09 18:07:02 +02:00
for (const { value: iconClass, noteId } of becca.findAttributes("label", "iconClass")) {
if (noteId.startsWith("_")) {
continue; // ignore icons of "system" notes since they were not set by the user
}
if (!iconClass?.trim()) {
continue;
}
for (const clazz of iconClass.trim().split(/\s+/)) {
2025-01-09 18:07:02 +02:00
if (clazz === "bx") {
continue;
}
iconClassToCountMap[clazz] = (iconClassToCountMap[clazz] || 0) + 1;
}
}
return { iconClassToCountMap };
}
2024-04-06 21:58:32 +03:00
function renderMarkdown(req: Request) {
const { markdownContent } = req.body;
return {
2025-01-09 18:07:02 +02:00
htmlContent: markdownService.renderToHtml(markdownContent, "")
};
}
export default {
getIconUsage,
renderMarkdown
};