mirror of
https://github.com/pheralb/svgl.git
synced 2025-12-29 08:01:36 +08:00
⚙️ Delete custom api url + export themeOptions types
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { RequestEvent } from './$types';
|
||||
import type { iSVG } from '@/types/svg';
|
||||
import type { ThemeOptions, iSVG } from '@/types/svg';
|
||||
import type { tCategory } from '@/types/categories';
|
||||
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
@@ -9,6 +9,7 @@ import { ratelimit } from '@/server/redis';
|
||||
import { svgsData } from '@/data';
|
||||
|
||||
export const GET = async ({ url, request }: RequestEvent) => {
|
||||
const fullUrl = url.origin ?? 'svgl.app';
|
||||
const ip = request.headers.get('x-forwarded-for') ?? '';
|
||||
const { success, reset } = await ratelimit.limit(ip);
|
||||
|
||||
@@ -29,23 +30,25 @@ export const GET = async ({ url, request }: RequestEvent) => {
|
||||
const getCategoryParams = url.searchParams.get('category');
|
||||
const getSearchParams = url.searchParams.get('search');
|
||||
|
||||
// Add full route to svgs:
|
||||
const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
||||
if (typeof svg.route === 'object' && svg.route !== null) {
|
||||
const addFullUrl = (value: string | ThemeOptions): string | ThemeOptions => {
|
||||
if (typeof value === 'string') {
|
||||
return `${fullUrl}${value}`;
|
||||
} else if (typeof value === 'object') {
|
||||
return {
|
||||
...svg,
|
||||
route: {
|
||||
light: `${svg.route.light}`,
|
||||
dark: `${svg.route.dark}`
|
||||
}
|
||||
};
|
||||
} else if (typeof svg.route === 'string') {
|
||||
return {
|
||||
...svg,
|
||||
route: `${svg.route}`
|
||||
light: `${fullUrl}${value.light}`,
|
||||
dark: `${fullUrl}${value.dark}`
|
||||
};
|
||||
}
|
||||
return svg;
|
||||
return value;
|
||||
};
|
||||
|
||||
// Add full route to svgs:
|
||||
const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
||||
return {
|
||||
...svg,
|
||||
route: addFullUrl(svg.route),
|
||||
wordmark: svg.wordmark ? addFullUrl(svg.wordmark) : undefined
|
||||
};
|
||||
});
|
||||
|
||||
// Status 200 | If no limit is provided, return all svgs:
|
||||
|
||||
Reference in New Issue
Block a user