forked from cheeaun/phanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split off logic for bridgifySearchQuery into separate protocol-transl…
…ator module
- Loading branch information
ghobs91
committed
Apr 10, 2024
1 parent
7402935
commit 8f6b965
Showing
3 changed files
with
57 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export function bridgifySearchQuery(instance, query, params) { | ||
if (instance === "ditto.pub") { | ||
let convertedQuery = query; | ||
if (query.indexOf("@") === 0) { | ||
convertedQuery = query.replace("@", "") | ||
} | ||
(async () => { | ||
convertedQuery = query.replace("@", "_at_"); | ||
const matchedMostrHexPing = await fetch(`https://mostr.pub/.well-known/nostr.json?name=${convertedQuery}`, {method: "get"}); | ||
const matchedMostrHexPingResponse = await matchedMostrHexPing.json(); | ||
if (matchedMostrHexPingResponse && matchedMostrHexPingResponse["names"]) { | ||
const matchedMostrHex = matchedMostrHexPingResponse["names"][convertedQuery] | ||
const dittoProfileCall = await fetch(`https://ditto.pub/api/v1/accounts/${matchedMostrHex}`, {method: "get"}); | ||
const dittoProfileCallResponse = await dittoProfileCall.json(); | ||
location.hash = `/${instance}/a/${dittoProfileCallResponse.id}`; | ||
} | ||
})(); | ||
console.log(`instance === "ditto.pub"`) | ||
} else if (instance === "skybridge.fly.dev") { | ||
if (query.indexOf("@") === 0) { | ||
let replacedString = params.q.replace("@", ""); | ||
replacedString = replacedString.replace("@", "."); | ||
replacedString += ".ap.brid.gy"; | ||
params.q = replacedString | ||
return params.q; | ||
} else if (query.indexOf("@") > 0) { | ||
let replacedString = params.q.replace("@", "."); | ||
replacedString += ".ap.brid.gy"; | ||
params.q = replacedString | ||
return params.q; | ||
} | ||
} else { | ||
if (query.indexOf("/" === 0)) { | ||
let replacedString = params.q.replace("/", ""); | ||
params.q = replacedString; | ||
return params.q; | ||
} | ||
if (query.indexOf("@") === -1) { | ||
if (query.indexOf("bsky.social") > -1 || query.indexOf("bsky.team") > -1) { | ||
params.q += "@bsky.brid.gy"; | ||
return params.q; | ||
} else if (query.match(/^[0-9a-fA-F]{64}$/)) { | ||
params.q += "@mostr.pub"; | ||
return params.q; | ||
} | ||
} else if (query.indexOf("@twitter.com") > -1) { | ||
const replacedString = params.q.replace("twitter.com", "bird.makeup") | ||
params.q = replacedString; | ||
return params.q; | ||
} | ||
} | ||
} |