Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
req.url += (req.url.indexOf('?') == -1 ? '?' : '&') + Object.keys(api.body).map(field => `${field}=${api.body[field]}`).join('&');
}
}
req.url += (req.url.indexOf('?') > -1 ? '&' : '?') + `t=${new Date().valueOf()}`;
if (ctx) {
// ๆฌๅฐ่ฐ็จ๏ผๅนถ้็ฉฟcookie
// ๅฐ่ฏไฝฟ็จrequestๅบๅนถpipeๅฎๆด็request๏ผไฝๆฏๅบ็ฐ้ฎ้ข
req.url = `http://127.0.0.1:${app.config.port}${req.url}`;
if (ctx.req) {
var cookie = ctx.req.headers.cookie;
if (cookie) {
req.headers.Cookie = cookie;
}
}
}
var result = await axios_1.default(req);
api.result = result.data;
return api;
}
exports.fetch = fetch;
var _this = this;
// ensure the user isn't passing in request-style options
opts = this.configure(opts);
try {
options_1.validate(opts);
}
catch (e) {
if (callback) {
return callback(e);
}
else {
throw e;
}
}
if (callback) {
axios_1.default(opts)
.then(function (r) {
callback(null, r);
})
.catch(function (e) {
callback(_this.processError(e));
});
}
else {
return axios_1.default(opts).catch(function (e) {
throw _this.processError(e);
});
}
};
/**
request.auth = this.headers.auth;
}
if ((typeof request.data) === 'string') {
request.headers = Object.assign(request.headers, { 'Content-Type': 'application/x-www-form-urlencoded' });
}
if (this.config.onRequest) {
await this.config.onRequest(request);
}
this.debugSection('Request', JSON.stringify(request));
let response;
try {
response = await axios(request);
} catch (err) {
if (!err.response) throw err;
this.debugSection('Response', `Response error. Status code: ${err.response.status}`);
response = err.response;
}
this.debugSection('Response', JSON.stringify(response.data));
return response;
}
RestClient.prototype._request = function (params, isAllResponse) {
if (isAllResponse === void 0) { isAllResponse = false; }
return axios_1.default(params)
.then(function (response) { return isAllResponse ? response : response.data; })
.catch(function (error) {
logger.debug(error);
throw error;
});
};
RestClient.prototype._parseUrl = function (url) {
getOne: (endpoint, nsfw, callback) => {
Axios({
method: "get",
url: `/api/${nsfw ? "nsfw" : "sfw"}/${endpoint}`,
}).then((response) => {
callback(response.data)
})
},
generateImage: (endpoint, nsfw, text, callback) => {
secret_key: credentials.secretAccessKey,
access_key: credentials.accessKeyId,
session_token: credentials.sessionToken,
};
var endpointInfo = {
region: endpoint_region,
service: endpoint_service,
};
var signerServiceInfo = Object.assign(endpointInfo, signerServiceInfoParams);
var signed_params = Signer_1.default.sign(otherParams, creds, signerServiceInfo);
if (signed_params.data) {
signed_params.body = signed_params.data;
}
logger.debug('Signed Request: ', signed_params);
delete signed_params.headers['host'];
return axios_1.default(signed_params)
.then(function (response) { return isAllResponse ? response : response.data; })
.catch(function (error) {
logger.debug(error);
throw error;
});
};
RestClient.prototype._request = function (params, isAllResponse) {
function getPromiseAxiosResponse(config) {
return axios_1.default(config);
}
function requestToTask(req) {
public soapRequest(url: string, headers: any, xml: any, timeout = 0x7fffffff): Promise {
const config: axios.AxiosRequestConfig = {
method: 'post',
url,
headers,
data: xml,
timeout,
maxContentLength: Infinity,
proxy: false,
};
const promise: Promise = axios
.default(config)
.then(response => {
if (response.status !== 200) {
throw new Error(`Unexpected response code ${response.status}, ${response.data}`);
}
return response;
})
.then(response => {
return this.parseResponse(response);
});
return promise;
}