chore: 支持dynadot,会覆盖原有的dns解析,京东云也有问题,没有测试通过,这两个目前都有缺陷

This commit is contained in:
xiaojunnuo
2024-09-25 02:31:45 +08:00
parent f9a3ac2cb1
commit 86e291c5a3
13 changed files with 292 additions and 527 deletions
+66 -88
View File
@@ -1,126 +1,106 @@
var JDCloud = require('./core')
var JDCloud = require("./core");
let util = JDCloud.util
let util = JDCloud.util;
JDCloud.JCRequest = class JCRequest {
constructor (
service,
path,
httpMethod,
pathParams,
queryParams,
headerParams,
formParams,
postBody,
contentTypes,
accepts,
returnType
) {
this.service = service
constructor(service, path, httpMethod, pathParams, queryParams, headerParams, formParams, postBody, contentTypes, accepts, returnType) {
this.service = service;
var endpoint = service.config.endpoint
pathParams.regionId = pathParams.regionId || service.config.regionId
this.regionId = pathParams.regionId
var endpoint = service.config.endpoint;
pathParams.regionId = pathParams.regionId || service.config.regionId;
this.regionId = pathParams.regionId;
this.path = this.buildPath(path, pathParams)
this.path = util.uriEscapePath(this.path)
this.path = this.buildPath(path, pathParams);
this.path = util.uriEscapePath(this.path);
var queryString = this.buildQuery(queryParams)
var queryString = this.buildQuery(queryParams);
var url = this.path
var url = this.path;
if (queryString) {
url = this.path + '?' + queryString
url = this.path + "?" + queryString;
}
var contentType = this.jsonPreferredMime(contentTypes) || 'application/json'
headerParams['content-type'] = contentType
var requestHeaders = this.buildHeaders(headerParams)
var contentType = this.jsonPreferredMime(contentTypes) || "application/json";
headerParams["content-type"] = contentType;
var requestHeaders = this.buildHeaders(headerParams);
var requestInit = {
method: httpMethod || 'GET',
headers: requestHeaders
}
method: httpMethod || "GET",
headers: requestHeaders,
};
if (contentType === 'application/x-www-form-urlencoded') {
} else if (contentType === 'multipart/form-data') {
if (contentType === "application/x-www-form-urlencoded") {
} else if (contentType === "multipart/form-data") {
} else if (postBody) {
requestInit.body = JSON.stringify(postBody)
requestInit.body = JSON.stringify(postBody);
}
var fetchUrl = endpoint.protocol + '://' + endpoint.host + url
JDCloud.config.logger(
`make request where url is :${fetchUrl} \nwith fetch config:${JSON.stringify(
requestInit
)}`
)
this.request = new JDCloud.fetch.Request(fetchUrl, requestInit)
var fetchUrl = endpoint.protocol + "://" + endpoint.host + url;
JDCloud.config.logger(`make request where url is :${fetchUrl} \nwith fetch config:${JSON.stringify(requestInit)}`);
this.request = new JDCloud.fetch.Request(fetchUrl, requestInit);
this.request.bodyCache = requestInit.body;
}
buildPath (path, pathParams) {
var uri = (this.service.config.basePath || '') + path
buildPath(path, pathParams) {
var uri = (this.service.config.basePath || "") + path;
uri = uri.replace(/\{([\w-]+)\}/g, (fullMatch, key) => {
var value
var value;
if (pathParams.hasOwnProperty(key)) {
value = pathParams[key]
value = pathParams[key];
} else {
value = fullMatch
value = fullMatch;
}
return value
})
return uri
return value;
});
return uri;
}
buildQuery (queryParams) {
var queryParamsWithoutEmptyItem = {}
var keys = Object.keys(queryParams)
buildQuery(queryParams) {
var queryParamsWithoutEmptyItem = {};
var keys = Object.keys(queryParams);
for (let key of keys) {
if (queryParams[key] !== undefined) {
queryParamsWithoutEmptyItem[key] = queryParams[key]
queryParamsWithoutEmptyItem[key] = queryParams[key];
}
}
return JDCloud.util.querystring.stringify(queryParamsWithoutEmptyItem)
return JDCloud.util.querystring.stringify(queryParamsWithoutEmptyItem);
}
search () {
var query = this.request.url.split('?', 2)[1]
search() {
var query = this.request.url.split("?", 2)[1];
if (query) {
query = JDCloud.util.querystring.parse(query)
return JDCloud.util.queryParamsToString(query)
query = JDCloud.util.querystring.parse(query);
return JDCloud.util.queryParamsToString(query);
}
return ''
return "";
}
digitizationArray (key, obj) {
var result = key
digitizationArray(key, obj) {
var result = key;
if (Array.isArray(obj)) {
JDCloud.util.arrayEach(obj, (arrayValue, index) => {
result += this.digitizationArray(`.${index + 1}`, arrayValue)
})
} else if (typeof obj === 'object' && obj != null) {
result += this.digitizationArray(`.${index + 1}`, arrayValue);
});
} else if (typeof obj === "object" && obj != null) {
JDCloud.util.each(obj, (key, ObjValue) => {
result += `.name=${key}&${result}.values` + this.digitizationArray()
result +=
key +
'.name=' +
ObjValue +
'&' +
this.digitizationArray(key + '.values', ObjValue)
})
result += `.name=${key}&${result}.values` + this.digitizationArray();
result += key + ".name=" + ObjValue + "&" + this.digitizationArray(key + ".values", ObjValue);
});
} else {
result += key + '=' + encodeURI(obj)
result += key + "=" + encodeURI(obj);
}
return result
return result;
}
buildHeaders (headerParams) {
buildHeaders(headerParams) {
var headers = new JDCloud.fetch.Headers({
accept: 'application/json'
})
accept: "application/json",
});
util.each.call(this, headerParams, function (key) {
if (headerParams[key] !== undefined && headerParams[key] != null) {
headers.append(key, headerParams[key])
headers.append(key, headerParams[key]);
}
})
return headers
});
return headers;
}
/**
@@ -134,10 +114,8 @@ JDCloud.JCRequest = class JCRequest {
* @param {String} contentType The MIME content type to check.
* @returns {Boolean} <code>true</code> if <code>contentType</code> represents JSON, otherwise <code>false</code>.
*/
isJsonMime (contentType) {
return Boolean(
contentType != null && contentType.match(/^application\/json(;.*)?$/i)
)
isJsonMime(contentType) {
return Boolean(contentType != null && contentType.match(/^application\/json(;.*)?$/i));
}
/**
@@ -145,15 +123,15 @@ JDCloud.JCRequest = class JCRequest {
* @param {Array.<String>} contentTypes
* @returns {String} The chosen content type, preferring JSON.
*/
jsonPreferredMime (contentTypes) {
jsonPreferredMime(contentTypes) {
for (var i = 0; i < contentTypes.length; i++) {
if (this.isJsonMime(contentTypes[i])) {
return contentTypes[i]
return contentTypes[i];
}
}
return contentTypes[0]
return contentTypes[0];
}
}
};
module.exports = JDCloud.JCRequest
module.exports = JDCloud.JCRequest;