mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
changed fetch publickeys to a queue
This commit is contained in:
parent
843ceac095
commit
b0c940b8e3
@ -1,6 +1,7 @@
|
|||||||
import { getBaseApi, getKeyPair } from "../background";
|
import { getBaseApi, getKeyPair } from "../background";
|
||||||
import { createSymmetricKeyAndNonce, decryptGroupData, encryptDataGroup, objectToBase64 } from "../qdn/encryption/group-encryption";
|
import { createSymmetricKeyAndNonce, decryptGroupData, encryptDataGroup, objectToBase64 } from "../qdn/encryption/group-encryption";
|
||||||
import { publishData } from "../qdn/publish/pubish";
|
import { publishData } from "../qdn/publish/pubish";
|
||||||
|
import { RequestQueueWithPromise } from "../utils/queue/queue";
|
||||||
|
|
||||||
const apiEndpoints = [
|
const apiEndpoints = [
|
||||||
"https://api.qortal.org",
|
"https://api.qortal.org",
|
||||||
@ -13,6 +14,8 @@ const apiEndpoints = [
|
|||||||
"https://apinode4.qortalnodes.live",
|
"https://apinode4.qortalnodes.live",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const requestQueueGetPublicKeys = new RequestQueueWithPromise(10);
|
||||||
|
|
||||||
async function findUsableApi() {
|
async function findUsableApi() {
|
||||||
for (const endpoint of apiEndpoints) {
|
for (const endpoint of apiEndpoints) {
|
||||||
try {
|
try {
|
||||||
@ -64,43 +67,50 @@ export async function getNameInfo() {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
const getPublicKeys = async (groupNumber: number) => {
|
const getPublicKeys = async (groupNumber: number) => {
|
||||||
const validApi = await getBaseApi()
|
const validApi = await getBaseApi();
|
||||||
const response = await fetch(`${validApi}/groups/members/${groupNumber}?limit=0`);
|
const response = await fetch(`${validApi}/groups/members/${groupNumber}?limit=0`);
|
||||||
const groupData = await response.json();
|
const groupData = await response.json();
|
||||||
|
|
||||||
let members: any = [];
|
if (groupData && Array.isArray(groupData.members)) {
|
||||||
if (groupData && Array.isArray(groupData?.members)) {
|
// Use the request queue for fetching public keys
|
||||||
for (const member of groupData.members) {
|
const memberPromises = groupData.members
|
||||||
if (member.member) {
|
.filter((member) => member.member)
|
||||||
const resAddress = await fetch(`${validApi}/addresses/${member.member}`);
|
.map((member) =>
|
||||||
const resData = await resAddress.json();
|
requestQueueGetPublicKeys.enqueue(async () => {
|
||||||
const publicKey = resData.publicKey;
|
const resAddress = await fetch(`${validApi}/addresses/${member.member}`);
|
||||||
members.push(publicKey)
|
const resData = await resAddress.json();
|
||||||
}
|
return resData.publicKey;
|
||||||
}
|
})
|
||||||
}
|
);
|
||||||
|
|
||||||
return members
|
const members = await Promise.all(memberPromises);
|
||||||
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getPublicKeysByAddress = async (admins) => {
|
return [];
|
||||||
const validApi = await getBaseApi()
|
};
|
||||||
|
|
||||||
|
export const getPublicKeysByAddress = async (admins: string[]) => {
|
||||||
|
const validApi = await getBaseApi();
|
||||||
|
|
||||||
let members: any = [];
|
if (Array.isArray(admins)) {
|
||||||
if (Array.isArray(admins)) {
|
// Use the request queue to limit concurrent fetches
|
||||||
for (const address of admins) {
|
const memberPromises = admins
|
||||||
if (address) {
|
.filter((address) => address) // Ensure the address is valid
|
||||||
const resAddress = await fetch(`${validApi}/addresses/${address}`);
|
.map((address) =>
|
||||||
const resData = await resAddress.json();
|
requestQueueGetPublicKeys.enqueue(async () => {
|
||||||
const publicKey = resData.publicKey;
|
const resAddress = await fetch(`${validApi}/addresses/${address}`);
|
||||||
members.push(publicKey)
|
const resData = await resAddress.json();
|
||||||
}
|
return resData.publicKey;
|
||||||
}
|
})
|
||||||
}
|
);
|
||||||
|
|
||||||
return members
|
const members = await Promise.all(memberPromises);
|
||||||
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return []; // Return empty array if admins is not an array
|
||||||
|
};
|
||||||
export const encryptAndPublishSymmetricKeyGroupChatForAdmins = async ({groupId, previousData, admins}: {
|
export const encryptAndPublishSymmetricKeyGroupChatForAdmins = async ({groupId, previousData, admins}: {
|
||||||
groupId: number,
|
groupId: number,
|
||||||
previousData: Object,
|
previousData: Object,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user