mirror of
https://github.com/pheralb/svgl.git
synced 2024-11-10 14:46:54 +08:00
🔧 Fix svgl route for all api endpoints.
This commit is contained in:
parent
eca3bce038
commit
c9e9d77d0a
@ -1,7 +1,27 @@
|
|||||||
import type { iSVG } from '@/types/svg';
|
import type { iSVG } from '@/types/svg';
|
||||||
import { svgs } from './svgs';
|
import { svgs } from './svgs';
|
||||||
|
|
||||||
|
// Add id on top of each svg:
|
||||||
export const svgsData = svgs.map((svg: iSVG, index: number) => {
|
export const svgsData = svgs.map((svg: iSVG, index: number) => {
|
||||||
svg.id = index;
|
return { id: index, ...svg };
|
||||||
return svg;
|
});
|
||||||
});
|
|
||||||
|
// Add full route of each svg, checking if theme support is added:
|
||||||
|
export const fullRouteSvgsData: iSVG[] = svgsData.map((svg) => {
|
||||||
|
const url = 'https://svgl.vercel.app';
|
||||||
|
if (typeof svg.route === 'object' && svg.route !== null) {
|
||||||
|
return {
|
||||||
|
...svg,
|
||||||
|
route: {
|
||||||
|
light: `${url}${svg.route.light}`,
|
||||||
|
dark: `${url}${svg.route.dark}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} else if (typeof svg.route === 'string') {
|
||||||
|
return {
|
||||||
|
...svg,
|
||||||
|
route: `${url}${svg.route}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return svg;
|
||||||
|
});
|
||||||
|
@ -1,23 +1,16 @@
|
|||||||
import type { RequestEvent } from './$types';
|
import type { RequestEvent } from './$types';
|
||||||
import type { iSVG } from '@/types/svg';
|
|
||||||
|
|
||||||
import { error, json } from '@sveltejs/kit';
|
import { error, json } from '@sveltejs/kit';
|
||||||
|
|
||||||
// Data:
|
// Data:
|
||||||
import { svgs } from '@/data/svgs';
|
import { fullRouteSvgsData } from '@/data';
|
||||||
|
|
||||||
export const GET = ({ url }: RequestEvent) => {
|
export const GET = ({ url }: RequestEvent) => {
|
||||||
const getParams = url.searchParams.get('limit');
|
const getParams = url.searchParams.get('limit');
|
||||||
|
|
||||||
// Modify svg route to add 'svgl.vercel.app' to the beginning:
|
|
||||||
const fullSVGRoute: iSVG[] = svgs.map((svg) => ({
|
|
||||||
...svg,
|
|
||||||
route: `https://svgl.vercel.app${svg.route}`
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Status 200 | If no limit is provided, return all svgs:
|
// Status 200 | If no limit is provided, return all svgs:
|
||||||
if (!getParams) {
|
if (!getParams) {
|
||||||
return json(fullSVGRoute, { status: 200 });
|
return json(fullRouteSvgsData, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const limit = Number(getParams);
|
const limit = Number(getParams);
|
||||||
@ -37,12 +30,12 @@ export const GET = ({ url }: RequestEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Error 400 | If limit is greater than the number of svgs:
|
// Error 400 | If limit is greater than the number of svgs:
|
||||||
if (limit > fullSVGRoute.length) {
|
if (limit > fullRouteSvgsData.length) {
|
||||||
throw error(400, {
|
throw error(400, {
|
||||||
message: 'Limit is greater than the number of svgs.'
|
message: 'Limit is greater than the number of svgs.'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Status 200 | If limit is a number:
|
// Status 200 | If limit is a number:
|
||||||
return json(fullSVGRoute.slice(0, limit), { status: 200 });
|
return json(fullRouteSvgsData.slice(0, limit), { status: 200 });
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user