From eec814c5a3bb4c66439e0559c764d4d24c8eb772 Mon Sep 17 00:00:00 2001 From: xylophonez Date: Fri, 27 Mar 2026 16:01:25 +0000 Subject: [PATCH] fix: paths --- scripts/deploy.mjs | 77 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/scripts/deploy.mjs b/scripts/deploy.mjs index fea4853..b9290c5 100644 --- a/scripts/deploy.mjs +++ b/scripts/deploy.mjs @@ -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 {