fix(swarm-loc-guard): correct content extraction and IndiekitError constructor call
Deploy Indiekit Server / deploy (push) Successful in 1m29s
Deploy Indiekit Server / deploy (push) Successful in 1m29s
- rawContent extraction now handles normalized {html,text} object (content is
already normalized by the time the guard runs, so String({...}) was '[object Object]')
- IndiekitError constructor is (message, options) not (status, message) — was
passing 422 as message causing error.message=422 (number) which crashed the
Nunjucks error template with 'Input data should be a String'
This commit is contained in:
@@ -29,11 +29,18 @@ const newSnippet = ` if (
|
|||||||
(hasCheckinProperty || hasSwarmSyndication)
|
(hasCheckinProperty || hasSwarmSyndication)
|
||||||
) {
|
) {
|
||||||
// Guard: only accept OwnYourSwarm posts that contain "Loc" in content. ${MARKER}
|
// Guard: only accept OwnYourSwarm posts that contain "Loc" in content. ${MARKER}
|
||||||
const rawContent = Array.isArray(properties.content)
|
// Extract raw text before normaliseProperties converts content to {html,text} object.
|
||||||
? properties.content.join(" ")
|
// After normalisation, String(properties.content) yields "[object Object]" — not useful.
|
||||||
: String(properties.content || "");
|
// We read .text/.html from the normalised object, then fall back to raw string.
|
||||||
|
const rawContent = (() => {
|
||||||
|
const c = properties.content;
|
||||||
|
if (!c) return "";
|
||||||
|
if (typeof c === "string") return c;
|
||||||
|
if (typeof c === "object") return String(c.text || c.html || "");
|
||||||
|
return String(c);
|
||||||
|
})();
|
||||||
if (hasSwarmSyndication && !rawContent.includes("Loc")) {
|
if (hasSwarmSyndication && !rawContent.includes("Loc")) {
|
||||||
throw new IndiekitError(422, "OwnYourSwarm post without 'Loc' in content rejected");
|
throw new IndiekitError("OwnYourSwarm post without 'Loc' in content rejected", { status: 422, code: "invalid_request" });
|
||||||
}
|
}
|
||||||
properties.visibility = "unlisted";
|
properties.visibility = "unlisted";
|
||||||
}`;
|
}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user