Graphical PDS migrator for AT Protocol

accountdid

Changed files
+33 -14
routes
api
migrate
+29 -12
routes/api/migrate/data/blobs.ts
···
const newAgent = await getSessionAgent(ctx.req, res, true);
console.log("Blob migration: Got new agent:", !!newAgent);
-
if (!oldAgent || !newAgent || !oldAgent.did) {
-
return new Response(JSON.stringify({
-
success: false,
-
message: "Not authenticated"
-
}), {
-
status: 401,
-
headers: { "Content-Type": "application/json" }
-
});
+
if (!oldAgent) {
+
return new Response(
+
JSON.stringify({
+
success: false,
+
message: "Unauthorized",
+
}),
+
{
+
status: 401,
+
headers: { "Content-Type": "application/json" },
+
},
+
);
+
}
+
if (!newAgent) {
+
return new Response(
+
JSON.stringify({
+
success: false,
+
message: "Migration session not found or invalid",
+
}),
+
{
+
status: 400,
+
headers: { "Content-Type": "application/json" },
+
},
+
);
}
// Migrate blobs
···
// First count total blobs
console.log(`[${new Date().toISOString()}] Starting blob count...`);
migrationLogs.push(`[${new Date().toISOString()}] Starting blob count...`);
+
+
const session = await oldAgent.com.atproto.server.getSession();
+
const accountDid = session.data.did;
do {
const pageStartTime = Date.now();
console.log(`[${new Date().toISOString()}] Counting blobs on page ${pageCount + 1}...`);
migrationLogs.push(`[${new Date().toISOString()}] Counting blobs on page ${pageCount + 1}...`);
-
const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
-
did: oldAgent.did,
+
did: accountDid,
cursor: blobCursor,
});
···
migrationLogs.push(`[${new Date().toISOString()}] Fetching blob list page ${pageCount + 1}...`);
const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
-
did: oldAgent.did,
+
did: accountDid,
cursor: blobCursor,
});
···
migrationLogs.push(`[${new Date().toISOString()}] Starting migration for blob ${cid} (${processedBlobs + 1} of ${totalBlobs})...`);
const blobRes = await oldAgent.com.atproto.sync.getBlob({
-
did: oldAgent.did,
+
did: accountDid,
cid,
});
+4 -2
routes/api/migrate/data/repo.ts
···
const newAgent = await getSessionAgent(ctx.req, res, true);
console.log("Repo migration: Got new agent:", !!newAgent);
-
if (!oldAgent || !newAgent || !oldAgent.did) {
+
if (!oldAgent || !newAgent) {
return new Response(JSON.stringify({
success: false,
message: "Not authenticated"
···
});
}
+
const session = await oldAgent.com.atproto.server.getSession();
+
const accountDid = session.data.did;
// Migrate repo data
const migrationLogs: string[] = [];
const startTime = Date.now();
···
const fetchStartTime = Date.now();
const repoData = await oldAgent.com.atproto.sync.getRepo({
-
did: oldAgent.did,
+
did: accountDid,
});
const fetchTime = Date.now() - fetchStartTime;