Skip to content

Commit

Permalink
ActivityPubのAPIを/api配下に移動する
Browse files Browse the repository at this point in the history
  • Loading branch information
nagutabby committed Jan 21, 2025
1 parent ca82891 commit 9471252
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/routes/api/activitypub/create/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const POST: RequestHandler = async ({ request, fetch }) => {

if (data.id) {
try {
const createActivity = await fetch(`/articles/${data.id}/create`);
const createActivity = await fetch(`/api/articles/${data.id}/create`);
if (!createActivity.ok) {
console.error('Error fetching create activity:', await createActivity.text());
return new Response(null, { status: 500 });
Expand Down
14 changes: 14 additions & 0 deletions src/routes/api/articles/[name]/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { RequestHandler } from '@sveltejs/kit';

export const GET: RequestHandler = async ({ params, request }) => {
const acceptHeader = request.headers.get('Accept');
if (acceptHeader) {
console.log('acceptHeader: ', acceptHeader);
}
return new Response(null, {
status: 200,
headers: {
'Content-Type': 'application/activity+json'
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const GET: RequestHandler = async ({ params }) => {

// Noteオブジェクトの定義
const note = {
"id": `https://blog.nagutabby.uk/articles/${name}`,
"id": `https://blog.nagutabby.uk/api/articles/${name}`,
"type": "Note",
"attributedTo": "https://blog.nagutabby.uk/actor",
"name": articleData.title,
"content": `<p>${articleData.title}</p><a href="https://blog.nagutabby.uk/articles/${name}" target="_blank">https://blog.nagutabby.uk/articles/${name}</a>`,
"published": articleData.publishedAt,
"url": `https://blog.nagutabby.uk/articles/${name}`,
"url": `https://blog.nagutabby.uk/api/articles/${name}`,
"to": ["https://www.w3.org/ns/activitystreams#Public"]
};

Expand All @@ -35,20 +35,20 @@ export const GET: RequestHandler = async ({ params }) => {
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"id": `https://blog.nagutabby.uk/articles/${name}/create`,
"id": `https://blog.nagutabby.uk/api/articles/${name}/create`,
"type": "Create",
"actor": "https://blog.nagutabby.uk/actor",
"published": new Date().toISOString(),
"to": ["https://www.w3.org/ns/activitystreams#Public"],
"object": note
};

const signatureData = await signCreateActivity(createActivity, PRIVATE_KEY)
const signatureData = await signCreateActivity(createActivity, PRIVATE_KEY);

const signedActivity = {
...createActivity,
signature: signatureData
}
};

return new Response(JSON.stringify(signedActivity), {
headers: {
Expand Down

0 comments on commit 9471252

Please sign in to comment.