feat: retrieve images
This commit is contained in:
@@ -1,27 +1,33 @@
|
||||
const correspondanceCache = new Map<string, string>()
|
||||
type Author = { alias: string; endpoint: string }
|
||||
|
||||
export const getUniqueAka = async (did: string) => {
|
||||
const correspondanceCache = new Map<string, Author>()
|
||||
|
||||
export const getUniqueAka = async (did: string): Promise<Author> => {
|
||||
console.log(correspondanceCache)
|
||||
if (correspondanceCache.has(did)) {
|
||||
return correspondanceCache.get(did) as string
|
||||
return correspondanceCache.get(did) as Author
|
||||
}
|
||||
|
||||
const response = await fetch(`https://plc.directory/${did}`)
|
||||
const {
|
||||
alsoKnownAs: [aka],
|
||||
service: [{ serviceEndpoint }],
|
||||
} = await response.json()
|
||||
|
||||
const alias = aka.replace("at://", "")
|
||||
const author = { alias, endpoint: serviceEndpoint }
|
||||
|
||||
correspondanceCache.set(did, alias)
|
||||
correspondanceCache.set(did, author)
|
||||
console.log(correspondanceCache)
|
||||
|
||||
return alias
|
||||
return author
|
||||
}
|
||||
|
||||
export const getAka = async (dids: Set<string>) => {
|
||||
const correspondance = await Promise.all(
|
||||
[...dids].map(async (did) => {
|
||||
if (correspondanceCache.has(did)) {
|
||||
return [did, correspondanceCache.get(did)!] as [string, string]
|
||||
return [did, correspondanceCache.get(did)?.alias] as [string, string]
|
||||
}
|
||||
|
||||
const response = await fetch(`https://plc.directory/${did}`)
|
||||
|
||||
Reference in New Issue
Block a user