···7171 if (!this.confirmation) {
7272 this.error = 'Please confirm that you understand the risks.'
7373 }
7474- // Pass the form data to migrate function for future implementation
7474+7575+ window.Migrator.createNewAccount = this.createNewAccount;
7676+ window.Migrator.migrateRepo = this.migrateRepo;
7777+ window.Migrator.migrateBlobs = this.migrateBlobs;
7878+ window.Migrator.migrateMissingBlobs = this.migrateMissingBlobs;
7979+ window.Migrator.migratePrefs = this.migratePrefs;
8080+ window.Migrator.migratePlcRecord = this.migratePlcRecord;
7581 this.updateStatusHandler('Starting migration...');
7682 this.showStatusMessage = true;
7783 await window.Migrator.migrate(
···8490 this.updateStatusHandler,
8591 this.twoFactorCode
8692 );
8787- this.askForPlcToken = true;
9393+ if (this.migratePlcRecord) {
9494+ this.askForPlcToken = true;
9595+ } else {
9696+ this.updateStatusHandler('Migration of your repo is complete! But the PLC operation was not done so your old account is still the valid one.');
9797+ }
8898 } catch (error) {
8999 console.error(error.error, error.message);
90100 if (error.error === 'AuthFactorTokenRequired') {
+93-86
src/pdsmoover.js
···3737 this.newAgent = null;
3838 this.missingBlobs = [];
3939 //State for reruns
4040- this.oldAccountStatus = null;
4141- this.newAccountStatus = null;
4240 this.createNewAccount = true;
4341 this.migrateRepo = true;
4442 this.migrateBlobs = true;
···9088 safeStatusUpdate(statusUpdateHandler, 'Checking that the new PDS is an actual PDS (if the url is wrong this takes a while to error out)');
9189 const newAgent = new AtpAgent({service: newPdsUrl});
9290 const newHostDesc = await newAgent.com.atproto.server.describeServer();
9393- const newHostWebDid = newHostDesc.data.did;
9191+ if (this.createNewAccount) {
9292+ const newHostWebDid = newHostDesc.data.did;
94939595- safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS');
9494+ safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS');
96959797- const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
9898- aud: newHostWebDid,
9999- lxm: 'com.atproto.server.createAccount',
100100- });
101101- const serviceJwt = createAuthResp.data.token;
9696+ const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
9797+ aud: newHostWebDid,
9898+ lxm: 'com.atproto.server.createAccount',
9999+ });
100100+ const serviceJwt = createAuthResp.data.token;
102101103103- const createNewAccount = await newAgent.com.atproto.server.createAccount({
104104- did: usersDid,
105105- handle: newHandle,
106106- email: newEmail,
107107- password: password,
108108- inviteCode: inviteCode,
109109- },
110110- {
111111- headers: {authorization: `Bearer ${serviceJwt}`},
112112- encoding: 'application/json',
113113- });
102102+ const createNewAccount = await newAgent.com.atproto.server.createAccount({
103103+ did: usersDid,
104104+ handle: newHandle,
105105+ email: newEmail,
106106+ password: password,
107107+ inviteCode: inviteCode,
108108+ },
109109+ {
110110+ headers: {authorization: `Bearer ${serviceJwt}`},
111111+ encoding: 'application/json',
112112+ });
114113115115- if (createNewAccount.data.did !== usersDid.toString()) {
116116- throw new Error('Did not create the new account with the same did as the old account');
114114+ if (createNewAccount.data.did !== usersDid.toString()) {
115115+ throw new Error('Did not create the new account with the same did as the old account');
116116+ }
117117 }
118118-119118 safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account');
120119121120 await newAgent.login({
···123122 password: password,
124123 });
125124126126- safeStatusUpdate(statusUpdateHandler, 'Migrating your repo');
127127- const repoRes = await oldAgent.com.atproto.sync.getRepo({did: usersDid});
128128- await newAgent.com.atproto.repo.importRepo(repoRes.data, {
129129- encoding: 'application/vnd.ipld.car',
130130- });
125125+ if (this.migrateRepo) {
126126+ safeStatusUpdate(statusUpdateHandler, 'Migrating your repo');
127127+ const repoRes = await oldAgent.com.atproto.sync.getRepo({did: usersDid});
128128+ await newAgent.com.atproto.repo.importRepo(repoRes.data, {
129129+ encoding: 'application/vnd.ipld.car',
130130+ });
131131+ }
131132132133 let newAccountStatus = await newAgent.com.atproto.server.checkAccountStatus();
133133- safeStatusUpdate(statusUpdateHandler, 'Migrating your blobs');
134134135135- let blobCursor = undefined;
136136- let uploadedBlobs = 0;
137137- do {
138138- safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
135135+ if (this.migrateBlobs) {
136136+ safeStatusUpdate(statusUpdateHandler, 'Migrating your blobs');
139137140140- const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
141141- did: usersDid,
142142- cursor: blobCursor,
143143- limit: 100,
144144- });
145145-146146- for (const cid of listedBlobs.data.cids) {
147147- try {
148148- //TODO may move the status update here but would have it only update like every 10
149149- const blobRes = await oldAgent.com.atproto.sync.getBlob({
150150- did: usersDid,
151151- cid,
152152- });
153153- await newAgent.com.atproto.repo.uploadBlob(blobRes.data, {
154154- encoding: blobRes.headers['content-type'],
155155- });
156156- uploadedBlobs++;
157157- if (uploadedBlobs % 10 === 0) {
158158- safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
159159- }
160160- } catch (error) {
161161- //TODO silently logging for now will do a missing blobs later
162162- console.error(error);
163163- }
164164- }
165165- blobCursor = listedBlobs.data.cursor;
166166- } while (blobCursor);
167167-168168- newAccountStatus = await newAgent.com.atproto.server.checkAccountStatus();
169169- if (newAccountStatus.data.expectedBlobs !== uploadedBlobs) {
170170- let totalMissingBlobs = newAccountStatus.data.expectedBlobs - uploadedBlobs;
171171- safeStatusUpdate(statusUpdateHandler, 'Looks like there are some missing blobs. Going to try and upload them now.');
172172- //Probably should be shared between main blob uploader, but eh
173173- let missingBlobCursor = undefined;
174174- let missingUploadedBlobs = 0;
138138+ let blobCursor = undefined;
139139+ let uploadedBlobs = 0;
175140 do {
176176- safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${missingUploadedBlobs}/${totalMissingBlobs}`);
141141+ safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
177142178178- const missingBlobs = await oldAgent.com.atproto.repo.listMissingBlobs({
143143+ const listedBlobs = await oldAgent.com.atproto.sync.listBlobs({
179144 did: usersDid,
180180- cursor: missingBlobCursor,
145145+ cursor: blobCursor,
181146 limit: 100,
182147 });
183148184184- for (const cid of missingBlobs.data.cids) {
149149+ for (const cid of listedBlobs.data.cids) {
185150 try {
186186- //TODO may move the status update here but would have it only update like every 10
187151 const blobRes = await oldAgent.com.atproto.sync.getBlob({
152152+ did: usersDid,
188153 cid,
189154 });
190155 await newAgent.com.atproto.repo.uploadBlob(blobRes.data, {
191156 encoding: blobRes.headers['content-type'],
192157 });
158158+ uploadedBlobs++;
193159 if (uploadedBlobs % 10 === 0) {
194194- safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${uploadedBlobs}`);
160160+ safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${uploadedBlobs}/${newAccountStatus.data.expectedBlobs}`);
195161 }
196196- uploadedBlobs++;
197162 } catch (error) {
198198- //TODO silently logging for now will do a missing blobs later
199163 console.error(error);
200200- this.missingBlobs.push(cid);
201164 }
202165 }
203203- missingBlobCursor = missingBlobs.data.cursor;
204204- } while (missingBlobCursor);
166166+ blobCursor = listedBlobs.data.cursor;
167167+ } while (blobCursor);
168168+ }
169169+170170+ if (this.migrateMissingBlobs) {
171171+ newAccountStatus = await newAgent.com.atproto.server.checkAccountStatus();
172172+ if (newAccountStatus.data.expectedBlobs !== newAccountStatus.data.importedBlobs) {
173173+ let totalMissingBlobs = newAccountStatus.data.expectedBlobs - newAccountStatus.data.importedBlobs;
174174+ safeStatusUpdate(statusUpdateHandler, 'Looks like there are some missing blobs. Going to try and upload them now.');
175175+ //Probably should be shared between main blob uploader, but eh
176176+ let missingBlobCursor = undefined;
177177+ let missingUploadedBlobs = 0;
178178+ do {
179179+ safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${missingUploadedBlobs}/${totalMissingBlobs}`);
180180+181181+ const missingBlobs = await newAgent.com.atproto.repo.listMissingBlobs({
182182+ cursor: missingBlobCursor,
183183+ limit: 100,
184184+ });
205185206206- }
186186+ for (const recordBlob of missingBlobs.data.blobs) {
187187+ try {
188188+ //TODO may move the status update here but would have it only update like every 10
189189+ const blobRes = await oldAgent.com.atproto.sync.getBlob({
190190+ did: usersDid,
191191+ cid: recordBlob.cid,
192192+ });
193193+ await newAgent.com.atproto.repo.uploadBlob(blobRes.data, {
194194+ encoding: blobRes.headers['content-type'],
195195+ });
196196+ if (missingUploadedBlobs % 10 === 0) {
197197+ safeStatusUpdate(statusUpdateHandler, `Migrating blobs: ${missingUploadedBlobs}/${totalMissingBlobs}`);
198198+ }
199199+ missingUploadedBlobs++;
200200+ } catch (error) {
201201+ //TODO silently logging for now will do a missing blobs later
202202+ console.error(error);
203203+ this.missingBlobs.push(cid);
204204+ }
205205+ }
206206+ missingBlobCursor = missingBlobs.data.cursor;
207207+ } while (missingBlobCursor);
207208208208- const prefs = await oldAgent.app.bsky.actor.getPreferences();
209209- await newAgent.app.bsky.actor.putPreferences(prefs.data);
210210- this.oldAgent = oldAgent;
211211- this.newAgent = newAgent;
212212- await oldAgent.com.atproto.identity.requestPlcOperationSignature();
213213- safeStatusUpdate(statusUpdateHandler, 'Please check your email for a PLC token');
209209+ }
210210+ }
211211+ if (this.migratePrefs) {
212212+ const prefs = await oldAgent.app.bsky.actor.getPreferences();
213213+ await newAgent.app.bsky.actor.putPreferences(prefs.data);
214214+ this.oldAgent = oldAgent;
215215+ this.newAgent = newAgent;
216216+ }
214217218218+ if (this.migratePlcRecord) {
219219+ await oldAgent.com.atproto.identity.requestPlcOperationSignature();
220220+ safeStatusUpdate(statusUpdateHandler, 'Please check your email for a PLC token');
221221+ }
215222 }
216223217224 async signPlcOperation(token) {