enhance: Provide Twemoji SVGs from Misskey server (#2) (#7897)

* Selfhosting Twemoji

* ちっ

* うざっ

* あ

* add test

Co-authored-by: mei23 <m@m544.net>
This commit is contained in:
tamaina 2021-10-24 21:10:45 +09:00 committed by GitHub
parent 1143606bc8
commit 5cf07fc50f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 2 deletions

View file

@ -1 +1 @@
export const twemojiSvgBase = 'https://twemoji.maxcdn.com/v/latest/svg';
export const twemojiSvgBase = '/twemoji';

View file

@ -101,6 +101,22 @@ router.get('/apple-touch-icon.png', async ctx => {
});
});
router.get('/twemoji/(.*)', async ctx => {
const path = ctx.path.replace('/twemoji/', '');
if (!path.match(/^[0-9a-f-]+\.svg$/)) {
ctx.status = 404;
return;
}
ctx.set('Content-Security-Policy', `default-src 'none'; style-src 'unsafe-inline'`);
await send(ctx as any, path, {
root: `${_dirname}/../../../node_modules/@discordapp/twemoji/dist/svg/`,
maxage: ms('30 days'),
});
});
// ServiceWorker
router.get('/sw.js', async ctx => {
await send(ctx as any, `/sw.${config.version}.js`, {