fix: paths p2

This commit is contained in:
fn
2026-03-27 16:36:35 +00:00
parent eec814c5a3
commit db782e9142
3 changed files with 6 additions and 153 deletions

View File

@@ -228,83 +228,8 @@ 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 getLatestManifestFromAo()) || (await resolveBlogManifestTxId());
const blogManifestTxId = await resolveBlogManifestTxId();
if (!blogManifestTxId) return [];
try {
@@ -399,6 +324,7 @@ async function main() {
manifest: "arweave/paths",
version: "0.2.0",
index: { path: "index.html" },
fallback: { id: indexTxId },
paths: pathMap
};