Skip to content

Commit e0e0c6f

Browse files
sij411claude
andcommitted
Extract duplicated authorize callback into reusable function
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 5a8b490 commit e0e0c6f

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

packages/cli/src/inbox.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type Federation,
77
generateCryptoKeyPair,
88
MemoryKvStore,
9+
type RequestContext,
910
} from "@fedify/fedify";
1011
import {
1112
Accept,
@@ -141,6 +142,11 @@ export async function runInbox(
141142
const federationDocumentLoader = await getDocumentLoader();
142143
const authorizedFetchEnabled = command.authorizedFetch ?? false;
143144

145+
const authorize = async (ctx: RequestContext<ContextData>) => {
146+
if (!authorizedFetchEnabled) return true;
147+
return await ctx.getSignedKey() != null;
148+
};
149+
144150
const federation = createFederation<ContextData>({
145151
kv: new MemoryKvStore(),
146152
documentLoaderFactory: () => federationDocumentLoader,
@@ -187,10 +193,7 @@ export async function runInbox(
187193
}
188194
return actorKeyPairs;
189195
})
190-
.authorize(async (ctx, _identifier) => {
191-
if (!authorizedFetchEnabled) return true;
192-
return await ctx.getSignedKey() != null;
193-
});
196+
.authorize(authorize);
194197

195198
// Set up inbox listeners
196199
federation
@@ -251,29 +254,20 @@ export async function runInbox(
251254
if (identifier !== "i") return null;
252255
return Object.keys(followers).length;
253256
})
254-
.authorize(async (ctx, _identifier) => {
255-
if (!authorizedFetchEnabled) return true;
256-
return await ctx.getSignedKey() != null;
257-
});
257+
.authorize(authorize);
258258

259259
federation
260260
.setFollowingDispatcher(
261261
"/{identifier}/following",
262262
(_ctx, _identifier) => null,
263263
)
264264
.setCounter((_ctx, _identifier) => 0)
265-
.authorize(async (ctx, _identifier) => {
266-
if (!authorizedFetchEnabled) return true;
267-
return await ctx.getSignedKey() != null;
268-
});
265+
.authorize(authorize);
269266

270267
federation
271268
.setOutboxDispatcher("/{identifier}/outbox", (_ctx, _identifier) => null)
272269
.setCounter((_ctx, _identifier) => 0)
273-
.authorize(async (ctx, _identifier) => {
274-
if (!authorizedFetchEnabled) return true;
275-
return await ctx.getSignedKey() != null;
276-
});
270+
.authorize(authorize);
277271

278272
federation.setNodeInfoDispatcher("/nodeinfo/2.1", (_ctx) => {
279273
return {

0 commit comments

Comments
 (0)