|
6 | 6 | type Federation, |
7 | 7 | generateCryptoKeyPair, |
8 | 8 | MemoryKvStore, |
| 9 | + type RequestContext, |
9 | 10 | } from "@fedify/fedify"; |
10 | 11 | import { |
11 | 12 | Accept, |
@@ -141,6 +142,11 @@ export async function runInbox( |
141 | 142 | const federationDocumentLoader = await getDocumentLoader(); |
142 | 143 | const authorizedFetchEnabled = command.authorizedFetch ?? false; |
143 | 144 |
|
| 145 | + const authorize = async (ctx: RequestContext<ContextData>) => { |
| 146 | + if (!authorizedFetchEnabled) return true; |
| 147 | + return await ctx.getSignedKey() != null; |
| 148 | + }; |
| 149 | + |
144 | 150 | const federation = createFederation<ContextData>({ |
145 | 151 | kv: new MemoryKvStore(), |
146 | 152 | documentLoaderFactory: () => federationDocumentLoader, |
@@ -187,10 +193,7 @@ export async function runInbox( |
187 | 193 | } |
188 | 194 | return actorKeyPairs; |
189 | 195 | }) |
190 | | - .authorize(async (ctx, _identifier) => { |
191 | | - if (!authorizedFetchEnabled) return true; |
192 | | - return await ctx.getSignedKey() != null; |
193 | | - }); |
| 196 | + .authorize(authorize); |
194 | 197 |
|
195 | 198 | // Set up inbox listeners |
196 | 199 | federation |
@@ -251,29 +254,20 @@ export async function runInbox( |
251 | 254 | if (identifier !== "i") return null; |
252 | 255 | return Object.keys(followers).length; |
253 | 256 | }) |
254 | | - .authorize(async (ctx, _identifier) => { |
255 | | - if (!authorizedFetchEnabled) return true; |
256 | | - return await ctx.getSignedKey() != null; |
257 | | - }); |
| 257 | + .authorize(authorize); |
258 | 258 |
|
259 | 259 | federation |
260 | 260 | .setFollowingDispatcher( |
261 | 261 | "/{identifier}/following", |
262 | 262 | (_ctx, _identifier) => null, |
263 | 263 | ) |
264 | 264 | .setCounter((_ctx, _identifier) => 0) |
265 | | - .authorize(async (ctx, _identifier) => { |
266 | | - if (!authorizedFetchEnabled) return true; |
267 | | - return await ctx.getSignedKey() != null; |
268 | | - }); |
| 265 | + .authorize(authorize); |
269 | 266 |
|
270 | 267 | federation |
271 | 268 | .setOutboxDispatcher("/{identifier}/outbox", (_ctx, _identifier) => null) |
272 | 269 | .setCounter((_ctx, _identifier) => 0) |
273 | | - .authorize(async (ctx, _identifier) => { |
274 | | - if (!authorizedFetchEnabled) return true; |
275 | | - return await ctx.getSignedKey() != null; |
276 | | - }); |
| 270 | + .authorize(authorize); |
277 | 271 |
|
278 | 272 | federation.setNodeInfoDispatcher("/nodeinfo/2.1", (_ctx) => { |
279 | 273 | return { |
|
0 commit comments