MCPcopy Create free account
hub / github.com/MathMan05/Fermi / checkURLs

Function checkURLs

src/webpage/utils/utils.ts:525–615  ·  view source on GitHub ↗

* this function checks if a string is an instance, it'll either return the API urls or null

(wellknown: string, urls: InstanceUrls)

Source from the content-addressed store, hash-verified

523 options.addHTMLArea(span);
524 const t = setInterval(() => {
525 if (!document.contains(span)) {
526 clearInterval(t);
527 no.onClick();
528 }
529 }, 100);
530 menu.show();
531 });
532 }
533 return undefined;
534}
535export async function getApiUrlsV1(str: string): Promise<InstanceUrls | null> {
536 function appendApi(str: string) {
537 return str.includes("api") ? str : str.endsWith("/") ? str + "api" : str + "/api";
538 }
539 if (!URL.canParse(str)) {
540 if (stringURLMap.size === 0) {
541 await new Promise<void>((res) => {
542 let intervalID = setInterval(() => {
543 if (stringURLMap.size !== 0) {
544 clearInterval(intervalID);
545 res();
546 }
547 }, 100);
548 });
549 }
550 const val = stringURLMap.get(str);
551 if (val) {
552 str = val;
553 } else {
554 const val = stringURLsMap.get(str);
555 if (val) {
556 const response = await fetch(val.api + (val.api.endsWith("/") ? "" : "/") + "ping");
557 if (response.ok) {
558 if (val.login) {
559 return val as InstanceUrls;
560 } else {
561 val.login = val.api;
562 return val as InstanceUrls;
563 }
564 }
565 } else if (!str.match(/^https?:\/\//gm)) {
566 str = "https://" + str;
567 }
568 }
569 }
570 str = trimTrailingSlashes(str);
571 let api: string;
572 try {
573 const info = await fetch(`${str}/.well-known/spacebar`).then((x) => x.json());
574 api = trimTrailingSlashes(info.api);
575 } catch {
576 api = str;
577 }
578 if (!URL.canParse(api)) {
579 return null;
580 }
581 const url = new URL(api);
582 let urls: undefined | InstanceUrls;

Callers 2

getApiUrlsV2Function · 0.85
getApiUrlsV1Function · 0.85

Calls 9

hideMethod · 0.95
showMethod · 0.95
isLoopbackFunction · 0.90
resFunction · 0.85
toStringMethod · 0.80
addMDTextMethod · 0.45
addOptionsMethod · 0.45
addButtonInputMethod · 0.45
addHTMLAreaMethod · 0.45

Tested by

no test coverage detected