mirror of
https://github.com/ld3z/new-manga.git
synced 2026-11-09 19:53:45 -07:00
does this work?
This commit is contained in:
parent
8271bc4957
commit
24eeb93f68
5 changed files with 104 additions and 84 deletions
|
|
@ -7,18 +7,52 @@ const feedMappings = new Map<string, { slugs: string[], lang: string }>();
|
|||
|
||||
export const POST: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
const { slugs, lang } = await request.json();
|
||||
console.log("Handling create-feed API request");
|
||||
|
||||
if (!request.body) {
|
||||
console.error("Request has no body");
|
||||
return new Response("Request body is required", { status: 400 });
|
||||
}
|
||||
|
||||
let body;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch (parseError) {
|
||||
console.error("Failed to parse request JSON:", parseError);
|
||||
return new Response("Invalid JSON in request body", { status: 400 });
|
||||
}
|
||||
|
||||
const { slugs, lang } = body;
|
||||
|
||||
if (!Array.isArray(slugs) || slugs.length === 0) {
|
||||
console.error("Invalid slugs array:", slugs);
|
||||
return new Response("Invalid slugs array", { status: 400 });
|
||||
}
|
||||
|
||||
if (!lang) {
|
||||
console.error("Language not specified");
|
||||
return new Response("Language is required", { status: 400 });
|
||||
}
|
||||
|
||||
console.log(`Creating feed for ${slugs.length} slugs in language: ${lang}`);
|
||||
|
||||
// Create a unique hash based on slugs and language
|
||||
const dataString = `${slugs.sort().join(',')}:${lang}`;
|
||||
const hash = createHash('md5').update(dataString).digest('hex').slice(0, 8);
|
||||
|
||||
// Store the mapping in Vercel KV
|
||||
await storeFeedMapping(hash, slugs, lang);
|
||||
try {
|
||||
// Store the mapping in Redis
|
||||
await storeFeedMapping(hash, slugs, lang);
|
||||
console.log(`Successfully created feed with ID: ${hash}`);
|
||||
} catch (dbError: any) {
|
||||
console.error("Database error while storing feed mapping:", dbError);
|
||||
return new Response(`Database error: ${dbError.message || "Unknown error"}`, {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ feedId: hash }), {
|
||||
status: 200,
|
||||
|
|
@ -26,9 +60,18 @@ export const POST: APIRoute = async ({ request }) => {
|
|||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error creating feed:', error);
|
||||
return new Response("Internal server error", { status: 500 });
|
||||
} catch (error: any) {
|
||||
console.error('Unexpected error creating feed:', error);
|
||||
return new Response(JSON.stringify({
|
||||
error: "Internal server error",
|
||||
message: error.message || "Unknown error",
|
||||
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
|
||||
}), {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue