mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-01-31 15:37:09 +01:00
* switch to nuxt assets for emojis * add auth to emoji endpoint * fix cache control header * fix type error
40 lines
940 B
TypeScript
40 lines
940 B
TypeScript
import aclManager from "~/server/internal/acls";
|
|
|
|
export default defineEventHandler(async (h3) => {
|
|
const allowed = await aclManager.hasACL(h3, [
|
|
"system:setup",
|
|
"user:emoji:read",
|
|
]);
|
|
if (!allowed)
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: "Requires authentication",
|
|
});
|
|
|
|
const codepoint = getRouterParam(h3, "codepoint");
|
|
if (!codepoint) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
statusMessage: "Missing codepoint parameter",
|
|
});
|
|
}
|
|
|
|
// Get the emoji SVG from server assets
|
|
const asset = await useStorage("assets:twemoji").getItemRaw(
|
|
`${codepoint}.svg`,
|
|
);
|
|
|
|
if (!asset) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: "Emoji not found",
|
|
});
|
|
}
|
|
|
|
// Set proper content type for SVG
|
|
setResponseHeader(h3, "Content-Type", "image/svg+xml");
|
|
setResponseHeader(h3, "Cache-Control", "private, max-age=31536000");
|
|
|
|
return asset;
|
|
});
|