Graphical PDS migrator for AT Protocol

Update data.ts

Changed files
+42 -4
routes
api
migrate
+42 -4
routes/api/migrate/data.ts
···
const migratedBlobs: string[] = [];
const failedBlobs: Array<{ cid: string; error: string }> = [];
const migrationLogs: string[] = [];
do {
try {
···
}
);
for (const cid of listedBlobs.data.cids) {
try {
const blobRes = await withRetry(
···
await handleBlobUpload(newAgent, blobRes, cid);
migratedBlobs.push(cid);
-
const log = `Successfully migrated blob: ${cid}`;
-
console.log(log);
-
migrationLogs.push(log);
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
console.error(`Failed to migrate blob ${cid}:`, error);
···
});
migrationLogs.push(`Failed to migrate blob ${cid}: ${errorMsg}`);
}
}
blobCursor = listedBlobs.data.cursor;
} catch (error) {
···
}
);
-
const completionMessage = `Data migration completed: ${migratedBlobs.length} blobs migrated${failedBlobs.length > 0 ? `, ${failedBlobs.length} failed` : ''}`;
console.log(completionMessage);
migrationLogs.push(completionMessage);
···
const migratedBlobs: string[] = [];
const failedBlobs: Array<{ cid: string; error: string }> = [];
const migrationLogs: string[] = [];
+
let totalBlobs = 0;
+
let pageCount = 0;
+
+
// First count total blobs
+
console.log("Starting blob count...");
+
do {
+
const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
+
did: accountDid,
+
cursor: blobCursor,
+
});
+
const newBlobs = listedBlobs.data.cids.length;
+
totalBlobs += newBlobs;
+
pageCount++;
+
console.log(`Blob count page ${pageCount}: found ${newBlobs} blobs, total so far: ${totalBlobs}`);
+
migrationLogs.push(`Blob count page ${pageCount}: found ${newBlobs} blobs, total so far: ${totalBlobs}`);
+
+
if (!listedBlobs.data.cursor) {
+
console.log("No more cursor, finished counting blobs");
+
break;
+
}
+
blobCursor = listedBlobs.data.cursor;
+
} while (blobCursor);
+
+
// Reset cursor for actual migration
+
blobCursor = undefined;
+
let processedBlobs = 0;
+
pageCount = 0;
do {
try {
···
}
);
+
pageCount++;
+
console.log(`Processing blob page ${pageCount}: ${listedBlobs.data.cids.length} blobs`);
+
migrationLogs.push(`Processing blob page ${pageCount}: ${listedBlobs.data.cids.length} blobs`);
+
for (const cid of listedBlobs.data.cids) {
try {
const blobRes = await withRetry(
···
await handleBlobUpload(newAgent, blobRes, cid);
migratedBlobs.push(cid);
+
processedBlobs++;
+
const progressLog = `Migrating blob ${processedBlobs} of ${totalBlobs}: ${cid}`;
+
console.log(progressLog);
+
migrationLogs.push(progressLog);
} catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
console.error(`Failed to migrate blob ${cid}:`, error);
···
});
migrationLogs.push(`Failed to migrate blob ${cid}: ${errorMsg}`);
}
+
}
+
+
if (!listedBlobs.data.cursor) {
+
console.log("No more cursor, finished processing blobs");
+
migrationLogs.push("No more cursor, finished processing blobs");
+
break;
}
blobCursor = listedBlobs.data.cursor;
} catch (error) {
···
}
);
+
const completionMessage = `Data migration completed: ${migratedBlobs.length} blobs migrated${failedBlobs.length > 0 ? `, ${failedBlobs.length} failed` : ''} (${pageCount} pages processed)`;
console.log(completionMessage);
migrationLogs.push(completionMessage);