Highly ambitious ATProtocol AppView service and sdks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix delete slice handler to only delete lexicons from slice, update domain validation, add slices.json config

+38 -23
+27 -15
frontend/src/features/slices/settings/handlers.tsx
··· 1 1 import type { Route } from "@std/http/unstable-route"; 2 2 import { withAuth } from "../../../routes/middleware.ts"; 3 3 import { createSessionClient, publicClient } from "../../../config.ts"; 4 - import { buildSliceUri } from "../../../utils/at-uri.ts"; 4 + import { buildSliceUri, getRkeyFromUri } from "../../../utils/at-uri.ts"; 5 5 import { renderHTML } from "../../../utils/render.tsx"; 6 6 import { hxRedirect } from "../../../utils/htmx.ts"; 7 7 import { ··· 10 10 } from "../../../routes/slice-middleware.ts"; 11 11 import { extractSliceParams } from "../../../utils/slice-params.ts"; 12 12 import { validateDomain } from "../../../utils/validation.ts"; 13 + import { getSliceClient } from "../../../utils/client.ts"; 13 14 import { SliceSettings } from "./templates/SliceSettings.tsx"; 14 15 15 16 async function handleSliceSettingsPage( ··· 77 78 78 79 const domainError = validateDomain(domain); 79 80 if (domainError) { 80 - const errorParam = domainError === "Domain is required" 81 - ? "domain_required" 82 - : domainError.includes("is not supported") 83 - ? "unsupported_domain" 84 - : "invalid_domain_format"; 81 + const errorParam = 82 + domainError === "Domain is required" 83 + ? "domain_required" 84 + : domainError.includes("is not supported") 85 + ? "unsupported_domain" 86 + : "invalid_domain_format"; 85 87 86 88 return hxRedirect( 87 - `/profile/${context.currentUser.handle}/slice/${sliceId}/settings?error=${errorParam}&message=${encodeURIComponent(domainError)}` 89 + `/profile/${ 90 + context.currentUser.handle 91 + }/slice/${sliceId}/settings?error=${errorParam}&message=${encodeURIComponent( 92 + domainError 93 + )}` 88 94 ); 89 95 } 90 96 ··· 187 193 188 194 // 2. Delete all lexicons for this slice 189 195 try { 190 - const lexicons = await sessionClient.network.slices.lexicon.getRecords({ 191 - limit: 100, 192 - }); 196 + const sliceClient = getSliceClient(context, sliceId); 197 + let cursor: string | undefined = undefined; 198 + 199 + do { 200 + const lexicons = await sliceClient.network.slices.lexicon.getRecords({ 201 + limit: 100, 202 + cursor, 203 + }); 193 204 194 - for (const lexicon of lexicons.records) { 195 - const rkey = lexicon.uri.split("/").pop(); 196 - if (rkey) { 197 - await sessionClient.network.slices.lexicon.deleteRecord(rkey); 205 + for (const lexicon of lexicons.records) { 206 + const rkey = getRkeyFromUri(lexicon.uri); 207 + await sliceClient.network.slices.lexicon.deleteRecord(rkey); 198 208 } 199 - } 209 + 210 + cursor = lexicons.cursor; 211 + } while (cursor); 200 212 } catch (_error) { 201 213 // Continue even if lexicon cleanup fails 202 214 }
+6 -8
frontend/src/utils/validation.ts
··· 1 - // List of domains that are not supported for slices 2 - const UNSUPPORTED_DOMAINS = [ 3 - "app.bsky", 4 - "com.atproto", 5 - ]; 1 + // List of domains that are not supported as primary domains (trying to prevent long running syncs for now) 2 + const UNSUPPORTED_DOMAINS = ["app.bsky"]; 6 3 7 4 export function validateDomain(domain: string): string | null { 8 5 const trimmedDomain = domain.trim(); ··· 16 13 } 17 14 18 15 // Domain must have at least two parts (e.g. social.grain) 19 - if (!trimmedDomain.includes('.')) { 16 + if (!trimmedDomain.includes(".")) { 20 17 return "Domain must have at least two parts (e.g. social.grain)"; 21 18 } 22 19 23 20 // Validate domain format 24 - const domainRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)+$/; 21 + const domainRegex = 22 + /^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)+$/; 25 23 if (!domainRegex.test(trimmedDomain)) { 26 24 return "Domain must be a valid format (e.g. social.grain)"; 27 25 } ··· 32 30 // Function to get the list of unsupported domains (for debugging/admin purposes) 33 31 export function getUnsupportedDomains(): readonly string[] { 34 32 return UNSUPPORTED_DOMAINS; 35 - } 33 + }
+5
slices.json
··· 1 + { 2 + "slice": "at://did:plc:bcgltzqazw5tb6k2g3ttenbj/network.slices.slice/3lymhd4jhrd2z", 3 + "lexiconPath": "./lexicons", 4 + "clientOutputPath": "./frontend/src/generated_client.ts" 5 + }