Normalize cPanel success results (#187)
This commit is contained in:
@@ -11,6 +11,7 @@ import { collectDistInventory } from "./package-dist.mjs";
|
||||
const SAFE_COMPONENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
||||
const SAFE_HOST = /^(?:[A-Za-z0-9.-]+|\[[0-9A-Fa-f:]+\])(?::[0-9]{1,5})?$/;
|
||||
const SHA256 = /^[a-f0-9]{64}$/i;
|
||||
const succeeded = (value) => value === 1 || value === "1" || value === true;
|
||||
const REQUIRED_ENV = [
|
||||
"PRODUCTION_FTP_HOST",
|
||||
"PRODUCTION_FTP_USER",
|
||||
@@ -569,7 +570,7 @@ export class CpanelFilemanClient {
|
||||
const payload = await this.request(endpoint, `Fileman ${functionName}`);
|
||||
const result = payload?.cpanelresult;
|
||||
const failedItem = result?.data?.find?.((item) => item?.result === 0 || item?.result === false);
|
||||
if (result?.event?.result !== 1 || failedItem) {
|
||||
if (!succeeded(result?.event?.result) || failedItem) {
|
||||
throw new DeploymentError(`cPanel Fileman ${functionName} failed: ${this.redact(responseMessage(payload))}`);
|
||||
}
|
||||
if (Array.isArray(result?.data)) {
|
||||
@@ -599,7 +600,7 @@ export class CpanelFilemanClient {
|
||||
endpoint.searchParams.set("show_hidden", "1");
|
||||
endpoint.searchParams.set("types", "dir|file|link");
|
||||
const payload = await this.request(endpoint, "Fileman list_files");
|
||||
if (payload?.result?.status !== 1) {
|
||||
if (!succeeded(payload?.result?.status)) {
|
||||
throw new DeploymentError(`cPanel Fileman list_files failed: ${this.redact(responseMessage(payload))}`);
|
||||
}
|
||||
if (!Array.isArray(payload.result.data)) {
|
||||
|
||||
@@ -4,6 +4,10 @@ import { DeploymentError, deriveCpanelRoot, normalizeRemoteRoot } from "./cpanel
|
||||
|
||||
const SAFE_COMPONENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
||||
|
||||
function succeeded(value) {
|
||||
return value === 1 || value === "1" || value === true;
|
||||
}
|
||||
|
||||
function required(env, name) {
|
||||
const value = env[name];
|
||||
const hasControlCharacter =
|
||||
@@ -136,7 +140,7 @@ export class CpanelAccountClient {
|
||||
const payload = await this.request(url);
|
||||
const result = payload?.cpanelresult;
|
||||
const failed = result?.data?.find?.((item) => item?.result === 0 || item?.result === false);
|
||||
if (result?.event?.result !== 1 || failed) {
|
||||
if (!succeeded(result?.event?.result) || failed) {
|
||||
throw new DeploymentError(`cPanel Fileman ${functionName} failed: ${this.redact(responseError(payload))}`);
|
||||
}
|
||||
return [...(result?.data || []), ...(result?.files || []), ...(result?.dirs || [])];
|
||||
@@ -152,7 +156,7 @@ export class CpanelAccountClient {
|
||||
url.searchParams.set("show_hidden", "1");
|
||||
url.searchParams.set("types", "dir|file|link");
|
||||
const payload = await this.request(url);
|
||||
if (payload?.result?.status !== 1) {
|
||||
if (!succeeded(payload?.result?.status)) {
|
||||
throw new DeploymentError(`cPanel Fileman list_files failed: ${this.redact(responseError(payload))}`);
|
||||
}
|
||||
if (!Array.isArray(payload.result.data)) {
|
||||
@@ -165,7 +169,7 @@ export class CpanelAccountClient {
|
||||
const url = new URL("execute/DomainInfo/domains_data", this.config.apiUrl);
|
||||
url.searchParams.set("format", "list");
|
||||
const payload = await this.request(url);
|
||||
if (payload?.result?.status !== 1) {
|
||||
if (!succeeded(payload?.result?.status)) {
|
||||
throw new DeploymentError(`cPanel DomainInfo failed: ${responseError(payload)}`);
|
||||
}
|
||||
if (!Array.isArray(payload.result.data)) {
|
||||
|
||||
Reference in New Issue
Block a user