38 lines
913 B
TypeScript
38 lines
913 B
TypeScript
import { AccessDeniedError } from "@lib/errors.ts";
|
|
import { getAllRecommendations } from "@lib/recommendation.ts";
|
|
import { json } from "@lib/helpers.ts";
|
|
import { define } from "../../../utils.ts";
|
|
|
|
export const handler = define.handlers({
|
|
async GET(ctx) {
|
|
const session = ctx.state.session;
|
|
if (!session) {
|
|
throw new AccessDeniedError();
|
|
}
|
|
|
|
const recs = await getAllRecommendations();
|
|
|
|
const allKeywords: Record<string, number> = {};
|
|
|
|
for (const rec of recs) {
|
|
if (rec.keywords?.length) {
|
|
for (const keyword of rec.keywords) {
|
|
if (keyword in allKeywords) {
|
|
allKeywords[keyword] += 1;
|
|
} else {
|
|
allKeywords[keyword] = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
const keywords = Object.entries(allKeywords).sort((a, b) =>
|
|
a[1] > b[1] ? -1 : 1
|
|
).slice(0, 100);
|
|
|
|
return json({
|
|
keywords,
|
|
});
|
|
},
|
|
});
|