"use strict"; const { sanitizeUploadFilename } = require("./upload-filename"); // adpanel:reinstall-port-wire - compatibility retries must not discard the // port the panel authorized and will persist after the daemon rebuild. const NODE_REQUEST_CRITICAL_FIELDS = new Set([ "name", "templateId", "docker", "hostPort", "operationId", "acceptUntil", "replaceRuntime", "image", "tag", "command", "adpanelStartup", "pterodactylStartup", "ports", "portProtocols", "volumes", "workdir", "workingDir", "env", "install", "installation", ]); // Panel-side normalization for the daemon's /v1/fs/rename. The daemon // sanitizes newName with its Go sanitizeUploadFilename, so this helper runs // the exact same JS mirror the upload endpoints use (utils/upload-filename.js) // and the name we echo is exactly the file the daemon creates. Returns "" for // unusable names ("", ".", "..", "/") so callers answer 400. function daemonRenameNewName(rawName) { return sanitizeUploadFilename(rawName) || ""; } // Daemons decode request bodies with DisallowUnknownFields, so a panel sending // a field an older binary does not know is answered 400 with Go's // `json: unknown field ""` decode error. Callers (unknown-field pruning // in index.js, the signed apply-version forward in server-asset-apply.js) // match on this shape to retry without the rejected field. Returns "" when the // response is not an unknown-field rejection. function unknownJsonFieldFromNodeResponse(res) { if (!res || res.status !== 400 || !res.json) return ""; const text = [res.json.error, res.json.detail, res.json.message] .map(v => String(v || "")) .filter(Boolean) .join(" "); const match = text.match(/json:\s*unknown field\s+"([^"]+)"/i); return match ? match[1] : ""; } module.exports = { NODE_REQUEST_CRITICAL_FIELDS, daemonRenameNewName, unknownJsonFieldFromNodeResponse };