server-ts: Convert routes/api/other

This commit is contained in:
Elian Doran
2024-04-06 21:58:32 +03:00
parent 3d75366f02
commit eb7a7e4988
2 changed files with 8 additions and 6 deletions

41
src/routes/api/other.ts Normal file
View File

@@ -0,0 +1,41 @@
import { Request } from "express";
import becca = require('../../becca/becca');
import markdownService = require('../../services/import/markdown');
function getIconUsage() {
const iconClassToCountMap: Record<string, number> = {};
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+/)) {
if (clazz === 'bx') {
continue;
}
iconClassToCountMap[clazz] = (iconClassToCountMap[clazz] || 0) + 1;
}
}
return { iconClassToCountMap };
}
function renderMarkdown(req: Request) {
const { markdownContent } = req.body;
return {
htmlContent: markdownService.renderToHtml(markdownContent, '')
};
}
export = {
getIconUsage,
renderMarkdown
};