Built redirector service into Misuzu.
This commit is contained in:
parent
a83cfdc595
commit
f2233c5390
18 changed files with 612 additions and 2 deletions
25
assets/redir-bsky.js/main.js
Normal file
25
assets/redir-bsky.js/main.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
(async () => {
|
||||
const status = document.querySelector('.js-status');
|
||||
status.textContent = 'Looking up DID...';
|
||||
|
||||
let did = null;
|
||||
|
||||
try {
|
||||
const response = await fetch(`${location.protocol}//${BSKY_HANDLE}/.well-known/atproto-did`);
|
||||
did = await response.text();
|
||||
} catch(ex) {
|
||||
status.style.color = 'red';
|
||||
status.textContent = `Could not find DID! ${ex}`;
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof did !== 'string' || !did.startsWith('did:')) {
|
||||
status.style.color = 'red';
|
||||
status.textContent = 'Look up result was not a valid DID.';
|
||||
return;
|
||||
}
|
||||
|
||||
const url = BSKY_FORMAT.replace('%s', did);
|
||||
status.textContent = `Redirecting to ${url}...`;
|
||||
location.replace(url);
|
||||
})();
|
39
assets/redir-fedi.js/main.js
Normal file
39
assets/redir-fedi.js/main.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
(async () => {
|
||||
const status = document.querySelector('.js-status');
|
||||
status.textContent = 'Looking up Fediverse profile...';
|
||||
|
||||
let url = null;
|
||||
try {
|
||||
const response = await fetch(`${location.protocol}//${FEDI_INSTANCE}/.well-known/webfinger?format=json&resource=acct:${FEDI_USERNAME}@${FEDI_INSTANCE}`);
|
||||
const webfinger = await response.json();
|
||||
|
||||
if(typeof webfinger === 'object') {
|
||||
if(Array.isArray(webfinger.links))
|
||||
for(const link of webfinger.links)
|
||||
if(typeof link === 'object' && link.rel === 'http://webfinger.net/rel/profile-page' && typeof link.href === 'string') {
|
||||
url = link.href;
|
||||
break;
|
||||
}
|
||||
|
||||
if(typeof url !== 'string' && Array.isArray(webfinger.aliases))
|
||||
for(const alias of webfinger.aliases)
|
||||
if(typeof alias === 'string') {
|
||||
url = alias;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(ex) {
|
||||
status.style.color = 'red';
|
||||
status.textContent = `Could not complete Webfinger lookup! ${ex}`;
|
||||
return;
|
||||
}
|
||||
|
||||
if(typeof url !== 'string' || (!url.startsWith('https://') && !url.startsWith('http://'))) {
|
||||
status.style.color = 'red';
|
||||
status.textContent = 'Could not find an acceptable profile URL.';
|
||||
return;
|
||||
}
|
||||
|
||||
status.textContent = `Redirecting to ${url}...`;
|
||||
location.replace(url);
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue