-
Notifications
You must be signed in to change notification settings - Fork 573
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import dotenv from 'dotenv' | ||
import AtpAgent from '@atproto/api' | ||
import { envToCfg, envToSecrets, readEnv } from '../config' | ||
import AppContext from '../context' | ||
import { getDb } from './db' | ||
import { transferPreferences } from './util' | ||
|
||
dotenv.config() | ||
|
||
export const runScript = async () => { | ||
const db = getDb() | ||
const env = readEnv() | ||
const cfg = envToCfg(env) | ||
const secrets = envToSecrets(env) | ||
const ctx = await AppContext.fromConfig(cfg, secrets) | ||
const pdsRes = await ctx.db.db.selectFrom('pds').selectAll().execute() | ||
const pdsInfos = pdsRes.map((row) => ({ | ||
id: row.id, | ||
did: row.did, | ||
url: `https://${row.host}`, | ||
agent: new AtpAgent({ service: `https://${row.host}` }), | ||
})) | ||
const failed = await db | ||
.selectFrom('failed_pref') | ||
.innerJoin('status', 'status.did', 'failed_pref.did') | ||
.selectAll() | ||
.execute() | ||
let count = 0 | ||
for (const pref of failed) { | ||
const pdsInfo = pdsInfos.find((info) => info.id === pref.pdsId) | ||
if (!pdsInfo) { | ||
throw new Error(`could not find pds with id: ${pref.pdsId}`) | ||
} | ||
try { | ||
await transferPreferences(ctx, pdsInfo, pref.did) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
count++ | ||
console.log(`${count}/${failed.length}`) | ||
} | ||
console.log('DONE WITH ALL') | ||
} | ||
|
||
runScript() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters