import { Readable } from "node:stream"; import type { ReadableStream as NodeReadableStream } from "node:stream/web"; import { getLogger } from "@logtape/logtape"; import { inArray, isNotNull, asc, eq, ne, sql, and } from "drizzle-orm"; import { Hono } from "hono"; import { bodyLimit } from "hono/body-limit"; import { csrf } from "hono/csrf"; import mime from "mime"; import { DashboardLayout } from "../components/DashboardLayout"; import { EMOJI_IMPORT_MAX_ARCHIVE_BYTES } from "../custom-emoji-import-config"; import db from "../db"; import federation, { customEmojiImports } from "../federation/federation"; import { loginRequired } from "../login"; import { proxyUrl } from "../media-proxy"; import { customEmojiImportJobs, customEmojiImportResults, customEmojis, } from "../schema"; import { EMOJI_IMPORT_DISK } from "../storage-config"; import { isUuid, uuidv7 } from "../uuid"; const logger = getLogger(["hollo", "pages", "emojis"]); const emojis = new Hono(); const MEBIBYTE = 1024 * 1024; const MULTIPART_OVERHEAD_BYTES = MEBIBYTE; const MAX_EMOJI_IMAGE_BYTES = 32 * MEBIBYTE; function fileStream(file: File): Readable { // TypeScript's DOM and Node stream declarations disagree on BYOB readers. return Readable.fromWeb(file.stream() as unknown as NodeReadableStream); } emojis.use(csrf()); emojis.use(loginRequired); emojis.get("/", async (c) => { const emojis = await db.query.customEmojis.findMany({ orderBy: (customEmojis, { desc }) => [ customEmojis.category, desc(customEmojis.created), ], }); return c.html(

Custom emojis

Register custom emojis for your Hollo accounts.

{EMOJI_IMPORT_DISK != null ? ( ) : ( )}
{emojis.length > 0 ? (
{emojis.map((emoji) => { const previewUrl = proxyUrl(emoji.url, c.req.url); return ( ); })}
Select Category Shortcode Image
) : (
No custom emojis yet. Add one above to get started.
)} {emojis.length > 0 && (
)}
, ); }); emojis.get("/new", async (c) => { const categories = await db .select({ category: customEmojis.category }) .from(customEmojis) .where(isNotNull(customEmojis.category)) .groupBy(customEmojis.category); return c.html(

Custom emojis

Add a custom emoji

, ); }); emojis.get("/zip", async (c) => { return c.html(

Custom emojis

Upload custom emojis (ZIP)

Hollo supports Misskey's packed emoji format.

{EMOJI_IMPORT_DISK != null ? (
) : (

ZIP import requires EMOJI_IMPORT_FS_PATH or S3_EMOJI_IMPORT_BUCKET.

)}
, EMOJI_IMPORT_DISK == null ? 503 : 200, ); }); emojis.get("/imports/job_list", async (c) => { const jobList = await db.query.customEmojiImportJobs.findMany({ orderBy: { created: "desc" }, }); function formatDateTime(value: Date): string { // Access tokens carry no nickname, so the issue time is often the only thing // that tells two tokens from the same app apart; the date alone is not // enough. Same server-locale caveat as formatDate() above. return value.toLocaleString(); } return c.html(

Custom emojis

Custom emoji import list

{jobList.map((job) => { return ( ); })}
UPLOAD DATE JOBID RESULT ACTIONS
{job.completed && ( )} {job.id} {job.status} {/*
, ); }); emojis.get("/imports/:jobId", async (c) => { const jobId = c.req.param("jobId"); if (!isUuid(jobId)) { return c.notFound(); } const job = await db.query.customEmojiImportJobs.findFirst({ where: { id: { eq: jobId } }, }); if (job == null) { return c.notFound(); } const results = await db .select() .from(customEmojiImportResults) .where( and( eq(customEmojiImportResults.jobId, job.id), ne(customEmojiImportResults.reason, "imported"), ), ) .orderBy(asc(customEmojiImportResults.entryIndex)); const inProgress = job.status === "pending" || job.status === "processing"; const statusLabel = { pending: "Waiting", processing: "Importing", completed: "Completed", failed: "Failed", }[job.status]; const resultLabel = { imported: "The emoji was imported.", duplicate_existing: "An emoji with the same shortcode already exists.", duplicate_in_pack: "The emoji pack contains duplicate shortcodes.", not_downloaded: "The emoji image could not be downloaded.", unsafe_file_path: "The file path is unsafe or invalid.", image_missing: "The emoji image file is missing.", invalid_shortcode: "The emoji shortcode is invalid.", unsupported_image_type: "The image format is not supported.", image_too_large: "The image file exceeds the maximum allowed size.", invalid_or_corrupt_image: "The image file is invalid or corrupted.", import_failed: "The emoji could not be imported.", } as const; const { drive } = await import("../storage"); const canRetry = job.status === "failed" && EMOJI_IMPORT_DISK != null && (await drive.use("emojiImports").exists(job.archiveKey)); return c.html(

Custom emojis

Custom emoji import

Status
{statusLabel}
Imported
{job.importedCount}
Skipped
{job.skippedCount}
Failed
{job.failedCount}
{job.error != null && ( )} {canRetry && (
)} {inProgress && ( <>

This page refreshes every 5 seconds while the import is running.