fix: paths
This commit is contained in:
@@ -228,8 +228,83 @@ async function resolveBlogManifestTxId() {
|
||||
return match?.[1] || "";
|
||||
}
|
||||
|
||||
const asObject = (value) => (typeof value === "object" && value !== null ? value : null);
|
||||
const asString = (value) => (typeof value === "string" && value.length > 0 ? value : null);
|
||||
|
||||
async function resolveAoConfig() {
|
||||
const source = await fs.readFile(sourceConfigPath, "utf8");
|
||||
const aoUrlMatch = source.match(/AO_URL\s*=\s*"([^"]+)"/);
|
||||
const aoProcessIdMatch = source.match(/AO_PROCESS_ID\s*=\s*"([^"]+)"/);
|
||||
return {
|
||||
aoUrl: aoUrlMatch?.[1] || "",
|
||||
aoProcessId: aoProcessIdMatch?.[1] || ""
|
||||
};
|
||||
}
|
||||
|
||||
async function getLatestManifestFromAo() {
|
||||
const { aoUrl, aoProcessId } = await resolveAoConfig();
|
||||
if (!aoUrl || !aoProcessId) return "";
|
||||
|
||||
try {
|
||||
const pushResponse = await fetch(`${aoUrl}/${aoProcessId}~process@1.0/push`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"signing-format": "ans104",
|
||||
"accept-bundle": "true",
|
||||
"require-codec": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
Type: "Message",
|
||||
"Data-Protocol": "ao",
|
||||
Variant: "ao.N.1",
|
||||
Action: "Get",
|
||||
target: aoProcessId,
|
||||
data: "1984"
|
||||
})
|
||||
});
|
||||
if (!pushResponse.ok) return "";
|
||||
|
||||
const pushPayload = await pushResponse.json();
|
||||
const slot = asString(asObject(pushPayload)?.slot);
|
||||
if (!slot) return "";
|
||||
|
||||
const computeResponse = await fetch(`${aoUrl}/${aoProcessId}~process@1.0/compute=${slot}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
"signing-format": "ans104",
|
||||
"accept-bundle": "true",
|
||||
"require-codec": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
target: aoProcessId,
|
||||
data: "1984"
|
||||
})
|
||||
});
|
||||
if (!computeResponse.ok) return "";
|
||||
|
||||
const computePayload = await computeResponse.json();
|
||||
const body = asObject(asObject(asObject(computePayload)?.results)?.json)?.body;
|
||||
const parsedBody = typeof body === "string" ? asObject(JSON.parse(body)) : asObject(body);
|
||||
const messages = Array.isArray(parsedBody?.Messages) ? parsedBody.Messages : [];
|
||||
|
||||
for (const message of messages) {
|
||||
const tags = Array.isArray(asObject(message)?.Tags) ? asObject(message)?.Tags : [];
|
||||
for (const tag of tags) {
|
||||
const tagObject = asObject(tag);
|
||||
const name = asString(tagObject?.name) ?? asString(tagObject?.Name);
|
||||
const value = asString(tagObject?.value) ?? asString(tagObject?.Value);
|
||||
if (name === "LatestManifestId" && value) return value;
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
async function resolvePostSlugs(gateway) {
|
||||
const blogManifestTxId = await resolveBlogManifestTxId();
|
||||
const blogManifestTxId = (await getLatestManifestFromAo()) || (await resolveBlogManifestTxId());
|
||||
if (!blogManifestTxId) return [];
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user