⚙️ Delete custom api url + export themeOptions types

This commit is contained in:
pheralb
2024-04-21 00:22:43 +01:00
parent f53455cbdb
commit 3e9eb405cb
4 changed files with 525 additions and 511 deletions
+18 -15
View File
@@ -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: