2023-08-28 11:25:31 +02:00
|
|
|
/*
|
2024-07-01 02:33:26 +02:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project , Type4ny-project
|
2023-08-28 11:25:31 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2024-02-08 05:28:49 +01:00
|
|
|
import { type SharedOptions, http, HttpResponse } from 'msw';
|
2023-04-04 02:38:34 +02:00
|
|
|
|
|
|
|
export const onUnhandledRequest = ((req, print) => {
|
2024-05-01 09:39:16 +02:00
|
|
|
const url = new URL(req.url);
|
|
|
|
if (url.hostname !== 'localhost' || /^\/(?:client-assets\/|fluent-emojis?\/|iframe.html$|node_modules\/|src\/|sb-|static-assets\/|vite\/)/.test(url.pathname)) {
|
2023-04-04 02:38:34 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
print.warning()
|
|
|
|
}) satisfies SharedOptions['onUnhandledRequest'];
|
|
|
|
|
|
|
|
export const commonHandlers = [
|
2024-02-08 05:28:49 +01:00
|
|
|
http.get('/fluent-emoji/:codepoints.png', async ({ params }) => {
|
|
|
|
const { codepoints } = params;
|
2023-04-13 05:20:39 +02:00
|
|
|
const value = await fetch(`https://raw.githubusercontent.com/misskey-dev/emojis/main/dist/${codepoints}.png`).then((response) => response.blob());
|
2024-02-08 05:28:49 +01:00
|
|
|
return new HttpResponse(value, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'image/png',
|
|
|
|
},
|
|
|
|
});
|
2023-04-13 05:20:39 +02:00
|
|
|
}),
|
2024-02-08 05:28:49 +01:00
|
|
|
http.get('/fluent-emojis/:codepoints.png', async ({ params }) => {
|
|
|
|
const { codepoints } = params;
|
2023-04-13 05:20:39 +02:00
|
|
|
const value = await fetch(`https://raw.githubusercontent.com/misskey-dev/emojis/main/dist/${codepoints}.png`).then((response) => response.blob());
|
2024-02-08 05:28:49 +01:00
|
|
|
return new HttpResponse(value, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'image/png',
|
|
|
|
},
|
|
|
|
});
|
2023-04-13 05:20:39 +02:00
|
|
|
}),
|
2024-02-08 05:28:49 +01:00
|
|
|
http.get('/twemoji/:codepoints.svg', async ({ params }) => {
|
|
|
|
const { codepoints } = params;
|
2023-12-18 06:51:29 +01:00
|
|
|
const value = await fetch(`https://unpkg.com/@discordapp/twemoji@15.0.2/dist/svg/${codepoints}.svg`).then((response) => response.blob());
|
2024-02-08 05:28:49 +01:00
|
|
|
return new HttpResponse(value, {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'image/svg+xml',
|
|
|
|
},
|
|
|
|
});
|
2023-04-04 02:38:34 +02:00
|
|
|
}),
|
|
|
|
];
|