initial framework

This commit is contained in:
2026-02-11 21:05:26 +00:00
parent 1df6c91109
commit f318513b2f
17 changed files with 1754 additions and 63 deletions

31
actions.ts Normal file
View File

@ -0,0 +1,31 @@
"use server";
import { APIResult, GCIAPIResult } from "./types";
const feelingFree = async (query: string): Promise<APIResult> => {
console.log(query);
try {
const response = await fetch(
`https://guncadindex.com/api/releases/?${query}`,
);
if (!response.ok) {
console.error(response.status);
return { error: true, payload: "Something went wrong." };
}
const { results }: GCIAPIResult = await response.json();
const randomResult = results[Math.round(Math.random() * results.length)];
const slug = randomResult.url.split("/").filter(Boolean).pop();
if (!slug) {
return { error: true, payload: "Could not retrieve results." };
}
console.log(slug);
return { payload: `https://guncadindex.com/detail/${slug}` };
} catch (error) {
if (error instanceof Error) {
return { error: true, payload: error.message };
}
return { error: true, payload: "Something went wrong." };
}
};
export { feelingFree };