mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
🐛 Import plugins directly into svgr
This commit is contained in:
@@ -3,7 +3,27 @@ import type { RequestEvent } from '../$types';
|
||||
import { transform } from '@svgr/core';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
import { ratelimit } from '@/server/redis';
|
||||
|
||||
// SVGR Plugins:
|
||||
import svgrJSX from '@svgr/plugin-jsx';
|
||||
|
||||
export const POST = async ({ request }: RequestEvent) => {
|
||||
const ip = request.headers.get('x-forwarded-for') ?? '';
|
||||
const { success, reset } = await ratelimit.limit(ip);
|
||||
|
||||
// Error 429 | If rate limit is exceeded:
|
||||
if (!success) {
|
||||
const now = Date.now();
|
||||
const retryAfter = Math.floor((reset - now) / 500);
|
||||
return new Response('Too Many Requests', {
|
||||
status: 429,
|
||||
headers: {
|
||||
'Retry-After': retryAfter.toString()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const body = await request.json();
|
||||
|
||||
@@ -14,7 +34,7 @@ export const POST = async ({ request }: RequestEvent) => {
|
||||
const jsCode = await transform(
|
||||
svgCode,
|
||||
{
|
||||
plugins: ['@svgr/plugin-jsx'],
|
||||
plugins: [svgrJSX],
|
||||
icon: true,
|
||||
typescript: typescript
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user