Create your Link in Bio for Bluesky

URLにDIDが使えるようにする (#23)

authored by mkizka.dev and committed by GitHub 7368bcff b0b78101

Changed files
+34 -5
app
routes
server
service
userService
+1 -5
app/routes/$handle.tsx
··· 15 15 }; 16 16 17 17 export async function loader({ request, params }: Route.LoaderArgs) { 18 - const maybeHandle = params.handle; 19 - if (!maybeHandle || !maybeHandle.includes(".")) { 20 - return notFound(); 21 - } 22 18 // この順で処理した場合ボードを持たない(=このサービスのユーザーでない)ユーザーの 23 19 // データも作られてしまうが、一旦このままにしておく 24 20 const user = await userService.findOrFetchUser({ 25 - handleOrDid: maybeHandle, 21 + handleOrDid: params.handle, 26 22 }); 27 23 if (!user) { 28 24 return notFound();
+18
app/server/service/userService/user.spec.ts
··· 154 154 // assert 155 155 expect(actual).toBeNull(); 156 156 }); 157 + test("入力が明らかにドメインでなければnullを返す", async () => { 158 + // arrange 159 + // act 160 + const actual = await userService.findOrFetchUser({ 161 + handleOrDid: "invalid", 162 + }); 163 + // assert 164 + expect(actual).toBeNull(); 165 + }); 166 + test("入力がDIDとして不正であればnullを返す", async () => { 167 + // arrange 168 + // act 169 + const actual = await userService.findOrFetchUser({ 170 + handleOrDid: "did:plc:invalid", 171 + }); 172 + // assert 173 + expect(actual).toBeNull(); 174 + }); 157 175 }); 158 176 });
+4
app/server/service/userService/user.ts
··· 1 1 import type { AppBskyActorDefs } from "@atproto/api"; 2 + import { isDid } from "@atproto/did"; 2 3 import type { Prisma, User } from "@prisma/client"; 3 4 4 5 import { LinkatAgent } from "~/libs/agent"; ··· 72 73 tx?: Prisma.TransactionClient; 73 74 handleOrDid: string; 74 75 }) => { 76 + if (!handleOrDid.includes(".") && !isDid(handleOrDid)) { 77 + return null; 78 + } 75 79 const user = await findUser({ tx, handleOrDid }); 76 80 if (user && !shouldRefetch(user)) { 77 81 return user;
+1
package.json
··· 27 27 }, 28 28 "dependencies": { 29 29 "@atproto/api": "0.13.18", 30 + "@atproto/did": "0.1.3", 30 31 "@atproto/identity": "0.4.3", 31 32 "@atproto/jwk-jose": "0.1.2", 32 33 "@atproto/lexicon": "0.4.3",
+10
pnpm-lock.yaml
··· 11 11 '@atproto/api': 12 12 specifier: 0.13.18 13 13 version: 0.13.18 14 + '@atproto/did': 15 + specifier: 0.1.3 16 + version: 0.1.3 14 17 '@atproto/identity': 15 18 specifier: 0.4.3 16 19 version: 0.4.3 ··· 309 312 310 313 '@atproto/did@0.1.2': 311 314 resolution: {integrity: sha512-gmY1SyAuqfmsFbIXkUIScfnULqn39FoUNz4oE0fUuMu9in6PEyoxlmD2lAo7Q3KMy3X/hvTn2u5f8W/2KuDg1w==} 315 + 316 + '@atproto/did@0.1.3': 317 + resolution: {integrity: sha512-ULD8Gw/KRRwLFZ2Z2L4DjmdOMrg8IYYlcjdSc+GQ2/QJSVnD2zaJJVTLd3vls121wGt/583rNaiZTT2DpBze4w==} 312 318 313 319 '@atproto/identity@0.4.3': 314 320 resolution: {integrity: sha512-DLXMWh57dHvIeBl+IvC+q20z0IdDZT1awOn84vDyxacL9DfhbiTy/zCUPFEzHyvfrilNG1tDA4zQzURubdFqNg==} ··· 5280 5286 uint8arrays: 3.0.0 5281 5287 5282 5288 '@atproto/did@0.1.2': 5289 + dependencies: 5290 + zod: 3.23.8 5291 + 5292 + '@atproto/did@0.1.3': 5283 5293 dependencies: 5284 5294 zod: 3.23.8 5285 5295