mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-17 11:35:33 -04:00
(refactor) migrate /api/banner/** route from express to h3
This commit is contained in:
parent
15ac0a1477
commit
f120779899
@ -2,19 +2,17 @@ import fs from 'node:fs/promises';
|
|||||||
|
|
||||||
import { createCanvas, loadImage } from 'canvas';
|
import { createCanvas, loadImage } from 'canvas';
|
||||||
import type { CanvasRenderingContext2D, Image } from 'canvas';
|
import type { CanvasRenderingContext2D, Image } from 'canvas';
|
||||||
import { Router } from 'express';
|
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import SQL from 'sql-template-strings';
|
import SQL from 'sql-template-strings';
|
||||||
|
|
||||||
import type { Translations } from '../../locale/translations.ts';
|
import type { Translations } from '../../../locale/translations.ts';
|
||||||
import { buildPronounUsage } from '../../src/buildPronoun.ts';
|
import { buildPronounUsage } from '../../../src/buildPronoun.ts';
|
||||||
import type { PronounUsage } from '../../src/classes.ts';
|
import type { PronounUsage } from '../../../src/classes.ts';
|
||||||
import { handleErrorAsync } from '../../src/helpers.ts';
|
import { Translator } from '../../../src/translator.ts';
|
||||||
import { Translator } from '../../src/translator.ts';
|
import type { User } from '../../../src/user.ts';
|
||||||
import type { User } from '../../src/user.ts';
|
import avatar from '../../avatar.ts';
|
||||||
import avatar from '../avatar.ts';
|
import { loadSuml, loadSumlFromBase } from '../../loader.ts';
|
||||||
import { loadSuml, loadSumlFromBase } from '../loader.ts';
|
import { registerLocaleFont } from '../../localeFont.ts';
|
||||||
import { registerLocaleFont } from '../localeFont.ts';
|
|
||||||
|
|
||||||
import { pronounLibrary } from '~/server/data.ts';
|
import { pronounLibrary } from '~/server/data.ts';
|
||||||
import type { Database } from '~/server/db.ts';
|
import type { Database } from '~/server/db.ts';
|
||||||
@ -46,8 +44,6 @@ const loadSvgImage = async (svg: string): Promise<Image> => {
|
|||||||
return await loadImage(pngBuffer);
|
return await loadImage(pngBuffer);
|
||||||
};
|
};
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
const width = 1200;
|
const width = 1200;
|
||||||
const height = 600;
|
const height = 600;
|
||||||
const mime = 'image/png';
|
const mime = 'image/png';
|
||||||
@ -142,12 +138,12 @@ const drawProfileBanner = async (
|
|||||||
return `user:${user.username}.png`;
|
return `user:${user.username}.png`;
|
||||||
};
|
};
|
||||||
|
|
||||||
router.get('/banner/:pronounName*.png', handleErrorAsync(async (req, res) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const path = (req.params.pronounName + req.params[0]).replace(/(&)+$/, '');
|
const path = (getRouterParam(event, 'path', { decode: true }) ?? '').replace(/(&)+$/, '').replace(/\.png$/, '');
|
||||||
|
const db = useDatabase();
|
||||||
|
|
||||||
const key = await getBannerKey(path, req.db);
|
const key = await getBannerKey(path, db);
|
||||||
const banner = await useStorage('data').getItemRaw<Buffer>(`banner:${key}`);
|
const banner = await useStorage('data').getItemRaw<Buffer>(`banner:${key}`);
|
||||||
return res.set('content-type', mime).send(banner);
|
appendHeader(event, 'content-type', mime);
|
||||||
}));
|
return banner;
|
||||||
|
});
|
||||||
export default router;
|
|
@ -18,7 +18,6 @@ import './globals.ts';
|
|||||||
import dbConnection from './db.ts';
|
import dbConnection from './db.ts';
|
||||||
import type { Database, SQLQuery } from './db.ts';
|
import type { Database, SQLQuery } from './db.ts';
|
||||||
import adminRoute from './express/admin.ts';
|
import adminRoute from './express/admin.ts';
|
||||||
import bannerRoute from './express/banner.ts';
|
|
||||||
import calendarRoute from './express/calendar.ts';
|
import calendarRoute from './express/calendar.ts';
|
||||||
import censusRoute from './express/census.ts';
|
import censusRoute from './express/census.ts';
|
||||||
import discord from './express/discord.ts';
|
import discord from './express/discord.ts';
|
||||||
@ -145,7 +144,6 @@ router.use(grantOverridesRoute);
|
|||||||
router.use(grant.express()(config));
|
router.use(grant.express()(config));
|
||||||
|
|
||||||
router.use(homeRoute);
|
router.use(homeRoute);
|
||||||
router.use(bannerRoute);
|
|
||||||
router.use(sentryRoute);
|
router.use(sentryRoute);
|
||||||
|
|
||||||
if (!global.config.macrolanguage?.enabled) {
|
if (!global.config.macrolanguage?.enabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user