Introduce token-based author authentication (register/verify API), skill forking with EditGate protection, tag metadata on skills, and download/push stats. Enhanced push scripts with token auth and per-skill filtering. Updated UI with stats, tags, and author info on skill cards.
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
import { h as hasToken, g as generateToken } from '../../../chunks/tokens_CAzj9Aj8.mjs';
|
|
export { renderers } from '../../../renderers.mjs';
|
|
|
|
const POST = async ({ request }) => {
|
|
let body;
|
|
try {
|
|
body = await request.json();
|
|
} catch {
|
|
return new Response(JSON.stringify({ error: "Invalid JSON" }), {
|
|
status: 400,
|
|
headers: { "Content-Type": "application/json" }
|
|
});
|
|
}
|
|
const { email, name } = body;
|
|
if (!email) {
|
|
return new Response(JSON.stringify({ error: "email is required" }), {
|
|
status: 400,
|
|
headers: { "Content-Type": "application/json" }
|
|
});
|
|
}
|
|
if (await hasToken(email)) {
|
|
return new Response(JSON.stringify({ error: "Email already registered" }), {
|
|
status: 409,
|
|
headers: { "Content-Type": "application/json" }
|
|
});
|
|
}
|
|
try {
|
|
const token = await generateToken(email, name || "");
|
|
return new Response(JSON.stringify({ token }), {
|
|
status: 201,
|
|
headers: { "Content-Type": "application/json" }
|
|
});
|
|
} catch (err) {
|
|
const message = err instanceof Error ? err.message : "Unknown error";
|
|
if (message.includes("already registered")) {
|
|
return new Response(JSON.stringify({ error: message }), {
|
|
status: 409,
|
|
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,
|
|
POST
|
|
}, Symbol.toStringTag, { value: 'Module' }));
|
|
|
|
const page = () => _page;
|
|
|
|
export { page };
|