···
40
-
this.oldAccountStatus = null;
41
-
this.newAccountStatus = null;
this.createNewAccount = true;
this.migrateBlobs = true;
···
safeStatusUpdate(statusUpdateHandler, 'Checking that the new PDS is an actual PDS (if the url is wrong this takes a while to error out)');
const newAgent = new AtpAgent({service: newPdsUrl});
const newHostDesc = await newAgent.com.atproto.server.describeServer();
93
-
const newHostWebDid = newHostDesc.data.did;
91
+
if (this.createNewAccount) {
92
+
const newHostWebDid = newHostDesc.data.did;
95
-
safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS');
94
+
safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS');
97
-
const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
99
-
lxm: 'com.atproto.server.createAccount',
101
-
const serviceJwt = createAuthResp.data.token;
96
+
const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
98
+
lxm: 'com.atproto.server.createAccount',
100
+
const serviceJwt = createAuthResp.data.token;
103
-
const createNewAccount = await newAgent.com.atproto.server.createAccount({
107
-
password: password,
108
-
inviteCode: inviteCode,
111
-
headers: {authorization: `Bearer ${serviceJwt}`},
112
-
encoding: 'application/json',
102
+
const createNewAccount = await newAgent.com.atproto.server.createAccount({
106
+
password: password,
107
+
inviteCode: inviteCode,
110
+
headers: {authorization: `Bearer ${serviceJwt}`},
111
+
encoding: 'application/json',
115
-
if (createNewAccount.data.did !== usersDid.toString()) {
116
-
throw new Error('Did not create the new account with the same did as the old account');
114
+
if (createNewAccount.data.did !== usersDid.toString()) {
115
+
throw new Error('Did not create the new account with the same did as the old account');
safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account');
···
126
-
safeStatusUpdate(statusUpdateHandler, 'Migrating your repo');
127
-
const repoRes = await oldAgent.com.atproto.sync.getRepo({did: usersDid});
128
-
await newAgent.com.atproto.repo.importRepo(repoRes.data, {
129
-
encoding: 'application/vnd.ipld.car',
125
+
if (this.migrateRepo) {
126
+
safeStatusUpdate(statusUpdateHandler, 'Migrating your repo');
127
+
const repoRes = await oldAgent.com.atproto.sync.getRepo({did: usersDid});
128
+
await newAgent.com.atproto.repo.importRepo(repoRes.data, {
129
+
encoding: 'application/vnd.ipld.car',
let newAccountStatus = await newAgent.com.atproto.server.checkAccountStatus();
133
-
safeStatusUpdate(statusUpdateHandler, 'Migrating your blobs');
135
-
let blobCursor = undefined;
136
-
let uploadedBlobs = 0;
138
-
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
140
-
const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
142
-
cursor: blobCursor,
135
+
if (this.migrateBlobs) {
136
+
safeStatusUpdate(statusUpdateHandler, 'Migrating your blobs');
146
-
for (const cid of listedBlobs.data.cids) {
148
-
//TODO may move the status update here but would have it only update like every 10
149
-
const blobRes = await oldAgent.com.atproto.sync.getBlob({
153
-
await newAgent.com.atproto.repo.uploadBlob(blobRes.data, {
154
-
encoding: blobRes.headers['content-type'],
157
-
if (uploadedBlobs % 10 === 0) {
158
-
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
161
-
//TODO silently logging for now will do a missing blobs later
162
-
console.error(error);
165
-
blobCursor = listedBlobs.data.cursor;
166
-
} while (blobCursor);
168
-
newAccountStatus = await newAgent.com.atproto.server.checkAccountStatus();
169
-
if (newAccountStatus.data.expectedBlobs !== uploadedBlobs) {
170
-
let totalMissingBlobs = newAccountStatus.data.expectedBlobs - uploadedBlobs;
171
-
safeStatusUpdate(statusUpdateHandler, 'Looks like there are some missing blobs. Going to try and upload them now.');
172
-
//Probably should be shared between main blob uploader, but eh
173
-
let missingBlobCursor = undefined;
174
-
let missingUploadedBlobs = 0;
138
+
let blobCursor = undefined;
139
+
let uploadedBlobs = 0;
176
-
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${missingUploadedBlobs}/${totalMissingBlobs}`);
141
+
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
178
-
const missingBlobs = await oldAgent.com.atproto.repo.listMissingBlobs({
143
+
const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
180
-
cursor: missingBlobCursor,
145
+
cursor: blobCursor,
184
-
for (const cid of missingBlobs.data.cids) {
149
+
for (const cid of listedBlobs.data.cids) {
186
-
//TODO may move the status update here but would have it only update like every 10
const blobRes = await oldAgent.com.atproto.sync.getBlob({
await newAgent.com.atproto.repo.uploadBlob(blobRes.data, {
encoding: blobRes.headers['content-type'],
if (uploadedBlobs % 10 === 0) {
194
-
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${uploadedBlobs}`);
160
+
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
198
-
//TODO silently logging for now will do a missing blobs later
200
-
this.missingBlobs.push(cid);
203
-
missingBlobCursor = missingBlobs.data.cursor;
204
-
} while (missingBlobCursor);
166
+
blobCursor = listedBlobs.data.cursor;
167
+
} while (blobCursor);
208
-
const prefs = await oldAgent.app.bsky.actor.getPreferences();
209
-
await newAgent.app.bsky.actor.putPreferences(prefs.data);
210
-
this.oldAgent = oldAgent;
211
-
this.newAgent = newAgent;
212
-
await oldAgent.com.atproto.identity.requestPlcOperationSignature();
213
-
safeStatusUpdate(statusUpdateHandler, 'Please check your email for a PLC token');
170
+
if (this.migrateMissingBlobs) {
171
+
newAccountStatus = await newAgent.com.atproto.server.checkAccountStatus();
172
+
if (newAccountStatus.data.expectedBlobs !== newAccountStatus.data.importedBlobs) {
173
+
let totalMissingBlobs = newAccountStatus.data.expectedBlobs - newAccountStatus.data.importedBlobs;
174
+
safeStatusUpdate(statusUpdateHandler, 'Looks like there are some missing blobs. Going to try and upload them now.');
175
+
//Probably should be shared between main blob uploader, but eh
176
+
let missingBlobCursor = undefined;
177
+
let missingUploadedBlobs = 0;
179
+
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${missingUploadedBlobs}/${totalMissingBlobs}`);
181
+
const missingBlobs = await newAgent.com.atproto.repo.listMissingBlobs({
182
+
cursor: missingBlobCursor,
186
+
for (const recordBlob of missingBlobs.data.blobs) {
188
+
//TODO may move the status update here but would have it only update like every 10
189
+
const blobRes = await oldAgent.com.atproto.sync.getBlob({
191
+
cid: recordBlob.cid,
193
+
await newAgent.com.atproto.repo.uploadBlob(blobRes.data, {
194
+
encoding: blobRes.headers['content-type'],
196
+
if (missingUploadedBlobs % 10 === 0) {
197
+
safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${missingUploadedBlobs}/${totalMissingBlobs}`);
199
+
missingUploadedBlobs++;
201
+
//TODO silently logging for now will do a missing blobs later
202
+
console.error(error);
203
+
this.missingBlobs.push(cid);
206
+
missingBlobCursor = missingBlobs.data.cursor;
207
+
} while (missingBlobCursor);
211
+
if (this.migratePrefs) {
212
+
const prefs = await oldAgent.app.bsky.actor.getPreferences();
213
+
await newAgent.app.bsky.actor.putPreferences(prefs.data);
214
+
this.oldAgent = oldAgent;
215
+
this.newAgent = newAgent;
218
+
if (this.migratePlcRecord) {
219
+
await oldAgent.com.atproto.identity.requestPlcOperationSignature();
220
+
safeStatusUpdate(statusUpdateHandler, 'Please check your email for a PLC token');
async signPlcOperation(token) {