mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-24 13:55:04 +02:00
Switch to node-fetch
This commit is contained in:
@@ -8,6 +8,7 @@ import * as Bluebird from 'bluebird';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as yargs from 'yargs';
|
import * as yargs from 'yargs';
|
||||||
import { hideBin } from 'yargs/helpers';
|
import { hideBin } from 'yargs/helpers';
|
||||||
|
import { noop } from 'lodash';
|
||||||
|
|
||||||
const argv = (yargs as any)(hideBin(process.argv))
|
const argv = (yargs as any)(hideBin(process.argv))
|
||||||
.option('beta', {
|
.option('beta', {
|
||||||
@@ -29,4 +30,18 @@ const argv = (yargs as any)(hideBin(process.argv))
|
|||||||
(global as any).TESTS = false;
|
(global as any).TESTS = false;
|
||||||
(global as any).performance = Date;
|
(global as any).performance = Date;
|
||||||
|
|
||||||
|
function PerformanceDate(...args: any[]) {
|
||||||
|
//@ts-ignore
|
||||||
|
return new Date(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
PerformanceDate.now = Date.now;
|
||||||
|
PerformanceDate.parse = Date.parse;
|
||||||
|
PerformanceDate.UTC = Date.UTC;
|
||||||
|
|
||||||
|
PerformanceDate.markResourceTiming = noop;
|
||||||
|
|
||||||
|
(global as any).performance = PerformanceDate;
|
||||||
|
|
||||||
|
|
||||||
Bluebird.promisifyAll(fs);
|
Bluebird.promisifyAll(fs);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import * as request from 'request-promise';
|
|
||||||
import { noop, flatMap, uniq } from 'lodash';
|
import { noop, flatMap, uniq } from 'lodash';
|
||||||
import {
|
import {
|
||||||
InternalGameServerState, ServerStatus, InternalLoginApi, InternalLoginServerState, InternalApi, HidingStats
|
InternalGameServerState, ServerStatus, InternalLoginApi, InternalLoginServerState, InternalApi, HidingStats
|
||||||
@@ -82,13 +81,24 @@ export function getServer(id: string) {
|
|||||||
export function createApi<T extends {}>(host: string, url: string, apiToken: string): T {
|
export function createApi<T extends {}>(host: string, url: string, apiToken: string): T {
|
||||||
return new Proxy<T>({} as any, {
|
return new Proxy<T>({} as any, {
|
||||||
get: (_, key) =>
|
get: (_, key) =>
|
||||||
(...args: any[]) =>
|
async (...args: any[]) => {
|
||||||
Promise.resolve<T>(request(`http://${host}/${url}/api`, {
|
const response = await fetch(`http://${host}/${url}/api`, {
|
||||||
json: true,
|
method: 'POST',
|
||||||
headers: { 'api-token': apiToken },
|
headers: {
|
||||||
method: 'post',
|
'Content-Type': 'application/json',
|
||||||
body: { method: key, args },
|
'api-token': apiToken,
|
||||||
})),
|
},
|
||||||
|
body: JSON.stringify({ method: key, args }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(
|
||||||
|
`API call failed — ${response.status} ${response.statusText} on method "${String(key)}"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json() as Promise<T>;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-2
@@ -5,7 +5,7 @@ import * as mongoose from 'mongoose';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { deleteAsync } from 'del';
|
import { deleteAsync } from 'del';
|
||||||
import { once, mapValues } from 'lodash';
|
import { once, mapValues, noop } from 'lodash';
|
||||||
import { spawnSync } from 'child_process';
|
import { spawnSync } from 'child_process';
|
||||||
import { createStubInstance, SinonStubbedInstance, stub } from 'sinon';
|
import { createStubInstance, SinonStubbedInstance, stub } from 'sinon';
|
||||||
import '../server/canvasUtilsNode';
|
import '../server/canvasUtilsNode';
|
||||||
@@ -22,7 +22,18 @@ require('chai').use(require('chai-as-promised'));
|
|||||||
(mongoose as any).modelSchemas = {};
|
(mongoose as any).modelSchemas = {};
|
||||||
(global as any).TESTS = true;
|
(global as any).TESTS = true;
|
||||||
(global as any).TOOLS = true;
|
(global as any).TOOLS = true;
|
||||||
(global as any).performance = Date;
|
function PerformanceDate(...args: any[]) {
|
||||||
|
//@ts-ignore
|
||||||
|
return new Date(...args);
|
||||||
|
}
|
||||||
|
|
||||||
|
PerformanceDate.now = Date.now;
|
||||||
|
PerformanceDate.parse = Date.parse;
|
||||||
|
PerformanceDate.UTC = Date.UTC;
|
||||||
|
|
||||||
|
PerformanceDate.markResourceTiming = noop;
|
||||||
|
|
||||||
|
(global as any).performance = PerformanceDate;
|
||||||
|
|
||||||
setPaletteManager(mockPaletteManager);
|
setPaletteManager(mockPaletteManager);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user