+37
-5
scanner.js
+37
-5
scanner.js
···
6
'deer.social',
7
];
8
9
document.addEventListener("DOMContentLoaded", function() {
10
initScanner();
11
});
···
56
} else if (query.match(/^did\:\w+\:/)) {
57
doScan = scanAccount(query);
58
} else {
59
-
resultField.innerText = 'Enter a user handle or a post URL.';
60
foundLabels.innerHTML = '';
61
return;
62
}
···
78
}
79
})
80
.catch((error) => {
81
-
resultField.innerText = error;
82
})
83
.finally(() => {
84
-
this.search.disabled = false;
85
});
86
});
87
}
88
89
async function scanHandle(handle) {
90
let json = await appView.getRequest('com.atproto.identity.resolveHandle', { handle });
91
let userDID = json.did;
···
116
let url = new URL(string);
117
118
if (url.protocol != 'https:') {
119
-
throw 'URL must start with https://';
120
}
121
122
if (!acceptedHostnames.includes(url.host)) {
···
140
let json = await appView.getRequest('com.atproto.identity.resolveHandle', { handle: match[1] });
141
atURI = `at://${json.did}/app.bsky.feed.post/${match[2]}`;
142
} else {
143
-
throw 'Invalid URL';
144
}
145
}
146
}
···
6
'deer.social',
7
];
8
9
+
class URLError extends Error {}
10
+
11
document.addEventListener("DOMContentLoaded", function() {
12
initScanner();
13
});
···
58
} else if (query.match(/^did\:\w+\:/)) {
59
doScan = scanAccount(query);
60
} else {
61
+
resultField.innerText = '🤨 Enter a user handle or a post URL.';
62
foundLabels.innerHTML = '';
63
return;
64
}
···
80
}
81
})
82
.catch((error) => {
83
+
displayError(error);
84
})
85
.finally(() => {
86
+
this.search.disabled = false;
87
});
88
});
89
}
90
91
+
function displayError(error) {
92
+
if (error instanceof APIError) {
93
+
if (error.code == 400) {
94
+
if (error.json.error == 'AccountTakedown') {
95
+
resultField.innerText = '🚫 Account was taken down';
96
+
return;
97
+
} else if (error.json.error == 'InvalidRequest') {
98
+
if (error.json.message == 'Profile not found') {
99
+
resultField.innerText = '🚫 Account not found';
100
+
return;
101
+
} else if (error.json.message == 'Unable to resolve handle') {
102
+
resultField.innerText = '👾 Unable to resolve handle';
103
+
return;
104
+
}
105
+
} else if (error.json.error == 'AccountDeactivated') {
106
+
resultField.innerText = '😶🌫️ Account is deactivated';
107
+
return;
108
+
}
109
+
}
110
+
111
+
resultField.innerText = error;
112
+
return;
113
+
} else if (error instanceof URLError) {
114
+
resultField.innerText = `⚠️ ${error.message}`;
115
+
return;
116
+
}
117
+
118
+
resultField.innerText = `${error.constructor.name}: ${error.message}`;
119
+
}
120
+
121
async function scanHandle(handle) {
122
let json = await appView.getRequest('com.atproto.identity.resolveHandle', { handle });
123
let userDID = json.did;
···
148
let url = new URL(string);
149
150
if (url.protocol != 'https:') {
151
+
throw new URLError('URL must start with https://');
152
}
153
154
if (!acceptedHostnames.includes(url.host)) {
···
172
let json = await appView.getRequest('com.atproto.identity.resolveHandle', { handle: match[1] });
173
atURI = `at://${json.did}/app.bsky.feed.post/${match[2]}`;
174
} else {
175
+
throw new URLError('Unknown URL');
176
}
177
}
178
}