Initial commit
This commit is contained in:
76
dist/server/pages/api/skills/_slug_.astro.mjs
vendored
Normal file
76
dist/server/pages/api/skills/_slug_.astro.mjs
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { d as deleteSkill, g as getSkill, u as updateSkill } from '../../../chunks/skills_COWfD5oy.mjs';
|
||||
export { renderers } from '../../../renderers.mjs';
|
||||
|
||||
const GET = async ({ params }) => {
|
||||
const skill = await getSkill(params.slug);
|
||||
if (!skill) {
|
||||
return new Response("Not found", { status: 404 });
|
||||
}
|
||||
return new Response(skill.raw, {
|
||||
headers: { "Content-Type": "text/markdown; charset=utf-8" }
|
||||
});
|
||||
};
|
||||
const PUT = async ({ params, request }) => {
|
||||
let body;
|
||||
try {
|
||||
body = await request.json();
|
||||
} catch {
|
||||
return new Response(JSON.stringify({ error: "Invalid JSON" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
if (!body.content) {
|
||||
return new Response(JSON.stringify({ error: "content is required" }), {
|
||||
status: 400,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
try {
|
||||
const skill = await updateSkill(params.slug, body.content);
|
||||
return new Response(JSON.stringify(skill), {
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "Unknown error";
|
||||
if (message.includes("not found")) {
|
||||
return new Response(JSON.stringify({ error: message }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ error: message }), {
|
||||
status: 500,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
};
|
||||
const DELETE = async ({ params }) => {
|
||||
try {
|
||||
await deleteSkill(params.slug);
|
||||
return new Response(null, { status: 204 });
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "Unknown error";
|
||||
if (message.includes("not found")) {
|
||||
return new Response(JSON.stringify({ error: message }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
return new Response(JSON.stringify({ error: message }), {
|
||||
status: 500,
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
|
||||
__proto__: null,
|
||||
DELETE,
|
||||
GET,
|
||||
PUT
|
||||
}, Symbol.toStringTag, { value: 'Module' }));
|
||||
|
||||
const page = () => _page;
|
||||
|
||||
export { page };
|
||||
Reference in New Issue
Block a user