···25})
2627/**
000000000000000028 * Cleans the handle of @ and some other unicode characters that used to show up when copied from the profile
29 * @param handle {string}
30 * @returns {string}
···42 * @returns {Promise<{usersDid: string, pds: string}>}
43 */
44async function handleAndPDSResolver(handle) {
000000045 let usersDid = null
46 if (handle.startsWith('did:')) {
47 usersDid = handle
···25})
2627/**
28+ * Fetches a minidoc from slingshot
29+ *
30+ * @param identifier {string}
31+ * @returns {Promise<{did: string, handle: string, pds: string}>}
32+ */
33+async function getMiniDoc(identifier) {
34+ const result = await fetch(
35+ `https://slingshot.microcosm.blue/xrpc/blue.microcosm.identity.resolveMiniDoc?identifier=${identifier}`,
36+ )
37+ if (!result.ok) {
38+ throw new Error(`Failed to fetch minidoc: ${result.status} ${result.statusText}`)
39+ }
40+ return await result.json()
41+}
42+43+/**
44 * Cleans the handle of @ and some other unicode characters that used to show up when copied from the profile
45 * @param handle {string}
46 * @returns {string}
···58 * @returns {Promise<{usersDid: string, pds: string}>}
59 */
60async function handleAndPDSResolver(handle) {
61+ try {
62+ const { did, handle: _, pds } = await getMiniDoc(handle)
63+ return { usersDid: did, pds }
64+ } catch (error) {
65+ console.error('Failed to load mini doc, trying other routes', error)
66+ }
67+68 let usersDid = null
69 if (handle.startsWith('did:')) {
70 usersDid = handle
-5
packages/moover/lib/lexicons/blue.ts
···1-/*
2- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3- */
4-5-export * as microcosm from './blue/microcosm.js'
···00000
-5
packages/moover/lib/lexicons/blue/microcosm.ts
···1-/*
2- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3- */
4-5-export * as identity from './microcosm/identity.js'
···1-/*
2- * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
3- */
4-5-export * from './resolveMiniDoc.defs.js'
6-export * as $defs from './resolveMiniDoc.defs.js'
···000000
+17-15
packages/moover/lib/pdsmoover.js
···1-import { docResolver, cleanHandle, handleResolver } from './atprotoUtils.js'
2import { AtpAgent } from '@atproto/api'
34function safeStatusUpdate(statusUpdateHandler, status) {
···79 } else {
80 //Resolves the did and finds the did document for the old PDS
81 safeStatusUpdate(statusUpdateHandler, 'Resolving old PDS')
82- usersDid = await handleResolver.resolve(oldHandle)
83- const didDoc = await docResolver.resolve(usersDid)
84- safeStatusUpdate(
85- statusUpdateHandler,
86- 'Resolving did document and finding your current PDS URL',
87- )
008889- let oldPds
90- try {
91- oldPds = didDoc.service.filter(s => s.type === 'AtprotoPersonalDataServer')[0]
92- .serviceEndpoint
93- } catch (error) {
94- console.error(error)
95- throw new Error('Could not find a PDS in the DID document.')
96- }
9798 oldAgent = new AtpAgent({
99 service: oldPds,
···1+import { docResolver, cleanHandle, handleResolver, handleAndPDSResolver } from './atprotoUtils.js'
2import { AtpAgent } from '@atproto/api'
34function safeStatusUpdate(statusUpdateHandler, status) {
···79 } else {
80 //Resolves the did and finds the did document for the old PDS
81 safeStatusUpdate(statusUpdateHandler, 'Resolving old PDS')
82+ let { usersDid: didFromLookUp, pds: oldPds } = await handleAndPDSResolver(oldHandle)
83+ usersDid = didFromLookUp
84+ // usersDid = await handleResolver.resolve(oldHandle)
85+ // const didDoc = await docResolver.resolve(usersDid)
86+ // safeStatusUpdate(
87+ // statusUpdateHandler,
88+ // 'Resolving did document and finding your current PDS URL',
89+ // )
9091+ // let oldPds
92+ // try {
93+ // oldPds = didDoc.service.filter(s => s.type === 'AtprotoPersonalDataServer')[0]
94+ // .serviceEndpoint
95+ // } catch (error) {
96+ // console.error(error)
97+ // throw new Error('Could not find a PDS in the DID document.')
98+ // }
99100 oldAgent = new AtpAgent({
101 service: oldPds,