Something went wrong. Try again.
I needed to delete all my bad `alt` text in my grain social photos, here's the script I used.
Something went wrong. Try again.
1.7 kB · 54 lines · Created 9mo ago
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import type {} from "@atcute/atproto";import type {} from "@atcute/bluesky";import { Client, CredentialManager, ok } from "@atcute/client";
/* ------------------------------------------------------------------ *//* 1. Log in *//* ------------------------------------------------------------------ */const manager = new CredentialManager({ service: "https://bsky.social" });await manager.login({ identifier: "handle.invalid", // ← your handle or email password: "xD", // ← app-password recommended});const rpc = new Client({ handler: manager });
/* ------------------------------------------------------------------ *//* 2. Remove lowercase `alt` from every social.grain.photo record *//* ------------------------------------------------------------------ */const collection = "social.grain.photo";const repo = "did:plc:tas6hj2xjrqben5653v5kohk";
let cursor: string | undefined;do { const res = await ok( rpc.get("com.atproto.repo.listRecords", { params: { repo, collection, cursor, limit: 100 }, }) );
for (const rec of res.records) { const uri = rec.uri as string; const record = rec.value as any;
if (!("alt" in record)) continue; // ← lowercase check
const { alt, ...cleaned } = record; // ← lowercase delete
await ok( rpc.post("com.atproto.repo.putRecord", { input: { collection, repo, rkey: uri.split("/").pop()!, record: cleaned, }, }) );
console.log(`✔ removed \`alt\` from ${uri}`); }
cursor = res.cursor;} while (cursor);
console.log("All done 🎉");