mirror of
https://github.com/exchanges-lab/view.git
synced 2026-08-07 22:24:42 +08:00
Upload files.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { logMessage } from './helpers';
|
||||
export class Requester {
|
||||
constructor(headers) {
|
||||
if (headers) {
|
||||
this._headers = headers;
|
||||
}
|
||||
}
|
||||
sendRequest(datafeedUrl, urlPath, params) {
|
||||
if (params !== undefined) {
|
||||
const paramKeys = Object.keys(params);
|
||||
if (paramKeys.length !== 0) {
|
||||
urlPath += '?';
|
||||
}
|
||||
urlPath += paramKeys.map((key) => {
|
||||
return `${encodeURIComponent(key)}=${encodeURIComponent(params[key].toString())}`;
|
||||
}).join('&');
|
||||
}
|
||||
logMessage('New request: ' + urlPath);
|
||||
// Send user cookies if the URL is on the same origin as the calling script.
|
||||
const options = { credentials: 'same-origin' };
|
||||
if (this._headers !== undefined) {
|
||||
options.headers = this._headers;
|
||||
}
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
return fetch(`${datafeedUrl}/${urlPath}`, options)
|
||||
.then((response) => response.text())
|
||||
.then((responseTest) => JSON.parse(responseTest));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user