fix: loading speeds
This commit is contained in:
24
src/lib.ts
24
src/lib.ts
@@ -113,14 +113,24 @@ const getLatestManifestFromAo = async (): Promise<string | null> => {
|
||||
};
|
||||
|
||||
export const loadManifest = async (): Promise<ManifestPost[]> => {
|
||||
const manifestTxId = (await getLatestManifestFromAo()) ?? MANIFEST_TX_ID;
|
||||
const response = await fetch(arweaveUrl(manifestTxId));
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load manifest (${response.status})`);
|
||||
}
|
||||
const loadByTxId = async (manifestTxId: string): Promise<ManifestPost[]> => {
|
||||
const response = await fetch(arweaveUrl(manifestTxId));
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load manifest (${response.status})`);
|
||||
}
|
||||
const payload: unknown = await response.json();
|
||||
return parseManifest(payload);
|
||||
};
|
||||
|
||||
const payload: unknown = await response.json();
|
||||
return parseManifest(payload);
|
||||
try {
|
||||
return await loadByTxId(MANIFEST_TX_ID);
|
||||
} catch (manifestError) {
|
||||
const latestManifestTxId = await getLatestManifestFromAo();
|
||||
if (!latestManifestTxId || latestManifestTxId === MANIFEST_TX_ID) {
|
||||
throw manifestError;
|
||||
}
|
||||
return loadByTxId(latestManifestTxId);
|
||||
}
|
||||
};
|
||||
|
||||
const isObject = (value: unknown): value is Record<string, unknown> =>
|
||||
|
||||
Reference in New Issue
Block a user