···
import { Agent } from '@atproto/api'
import { deleteSite } from '../lib/db'
import { logger } from '../lib/logger'
+
import { extractSubfsUris } from '../lib/wisp-utils'
export const siteRoutes = (client: NodeOAuthClient, cookieSecret: string) =>
···
// Create agent with OAuth session
const agent = new Agent((url, init) => auth.session.fetchHandler(url, init))
+
// First, fetch the site record to find any subfs references
+
let subfsUris: Array<{ uri: string; path: string }> = [];
+
const existingRecord = await agent.com.atproto.repo.getRecord({
+
collection: 'place.wisp.fs',
+
if (existingRecord.data.value && typeof existingRecord.data.value === 'object' && 'root' in existingRecord.data.value) {
+
const manifest = existingRecord.data.value as any;
+
subfsUris = extractSubfsUris(manifest.root);
+
if (subfsUris.length > 0) {
+
console.log(`Found ${subfsUris.length} subfs records to delete`);
+
logger.info(`[Site] Found ${subfsUris.length} subfs records associated with ${rkey}`);
+
// Record might not exist, continue with deletion
+
console.log('Could not fetch site record for subfs cleanup, continuing...');
+
// Delete the main record from AT Protocol
await agent.com.atproto.repo.deleteRecord({
···
logger.error(`[Site] Failed to delete site ${rkey} from PDS`, err)
throw new Error('Failed to delete site from AT Protocol')
+
// Delete associated subfs records
+
if (subfsUris.length > 0) {
+
console.log(`Deleting ${subfsUris.length} associated subfs records...`);
+
subfsUris.map(async ({ uri }) => {
+
// Parse URI: at://did/collection/rkey
+
const parts = uri.replace('at://', '').split('/');
+
const subRkey = parts[2];
+
await agent.com.atproto.repo.deleteRecord({
+
collection: 'place.wisp.subfs',
+
console.log(` 🗑️ Deleted subfs: ${uri}`);
+
logger.info(`[Site] Deleted subfs record: ${uri}`);
+
// Log but don't fail if subfs deletion fails
+
console.warn(`Failed to delete subfs ${uri}:`, err?.message);
+
logger.warn(`[Site] Failed to delete subfs ${uri}`, err);
+
logger.info(`[Site] Deleted ${subfsUris.length} subfs records for ${rkey}`);