Update deps, migrate to 'got' library
This commit is contained in:
@@ -8,8 +8,8 @@ import { ICapResponse } from './interfaces/ICapResponse';
|
||||
import { HTTPAssets } from '../enums/HTTPAssets';
|
||||
|
||||
import * as LLSD from '@caspertech/llsd';
|
||||
import * as request from 'request';
|
||||
import * as url from 'url';
|
||||
import got from 'got';
|
||||
|
||||
export class Caps
|
||||
{
|
||||
@@ -144,7 +144,7 @@ export class Caps
|
||||
req.push('ViewerStats');
|
||||
|
||||
this.active = true;
|
||||
this.request(seedURL, LLSD.LLSD.formatXML(req), 'application/llsd+xml').then((resp: ICapResponse) =>
|
||||
this.requestPost(seedURL, LLSD.LLSD.formatXML(req), 'application/llsd+xml').then((resp: ICapResponse) =>
|
||||
{
|
||||
this.capabilities = LLSD.LLSD.parseXML(resp.body);
|
||||
this.gotSeedCap = true;
|
||||
@@ -164,140 +164,73 @@ export class Caps
|
||||
});
|
||||
}
|
||||
|
||||
async downloadAsset(uuid: UUID, type: HTTPAssets): Promise<Buffer>
|
||||
public async downloadAsset(uuid: UUID, type: HTTPAssets): Promise<Buffer>
|
||||
{
|
||||
return new Promise<Buffer>((resolve, reject) =>
|
||||
if (type === HTTPAssets.ASSET_LSL_TEXT || type === HTTPAssets.ASSET_NOTECARD)
|
||||
{
|
||||
if (type === HTTPAssets.ASSET_LSL_TEXT || type === HTTPAssets.ASSET_NOTECARD)
|
||||
{
|
||||
throw new Error('Invalid Syntax');
|
||||
}
|
||||
this.getCapability('ViewerAsset').then((capURL) =>
|
||||
{
|
||||
const assetURL = capURL + '/?' + type + '_id=' + uuid.toString();
|
||||
request({
|
||||
'uri': assetURL,
|
||||
'rejectUnauthorized': false,
|
||||
'method': 'GET',
|
||||
'encoding': null
|
||||
}, (err, res, body) =>
|
||||
{
|
||||
if (res.statusCode < 200 && res.statusCode > 299)
|
||||
{
|
||||
reject(new Error(body));
|
||||
}
|
||||
else if (err)
|
||||
{
|
||||
reject(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve(body);
|
||||
}
|
||||
});
|
||||
}).catch((err) =>
|
||||
{
|
||||
reject(err);
|
||||
});
|
||||
throw new Error('Invalid Syntax');
|
||||
}
|
||||
const capURL = await this.getCapability('ViewerAsset');
|
||||
const assetURL = capURL + '/?' + type + '_id=' + uuid.toString();
|
||||
|
||||
const response = await got.get(assetURL, {
|
||||
rejectUnauthorized: false,
|
||||
method: 'GET',
|
||||
responseType: 'buffer'
|
||||
});
|
||||
|
||||
if (response.statusCode < 200 || response.statusCode > 299)
|
||||
{
|
||||
throw new Error(response.body.toString('utf-8'));
|
||||
}
|
||||
|
||||
return response.body;
|
||||
}
|
||||
|
||||
request(capURL: string, data: string | Buffer, contentType: string): Promise<ICapResponse>
|
||||
public async requestPost(capURL: string, data: string | Buffer, contentType: string)
|
||||
{
|
||||
return new Promise<ICapResponse>((resolve, reject) =>
|
||||
{
|
||||
request({
|
||||
'headers': {
|
||||
'Content-Length': data.length,
|
||||
'Content-Type': contentType
|
||||
},
|
||||
'uri': capURL,
|
||||
'body': data,
|
||||
'rejectUnauthorized': false,
|
||||
'method': 'POST'
|
||||
}, (err, res, body) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve({ status: res.statusCode, body: body });
|
||||
}
|
||||
});
|
||||
const response = await got.post(capURL, {
|
||||
headers: {
|
||||
'Content-Length': String(Buffer.byteLength(data)),
|
||||
'Content-Type': contentType
|
||||
},
|
||||
body: data,
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
return { status: response.statusCode, body: response.body };
|
||||
}
|
||||
|
||||
requestPut(capURL: string, data: string | Buffer, contentType: string): Promise<ICapResponse>
|
||||
public async requestPut(capURL: string, data: string | Buffer, contentType: string): Promise<ICapResponse>
|
||||
{
|
||||
return new Promise<ICapResponse>((resolve, reject) =>
|
||||
{
|
||||
request({
|
||||
'headers': {
|
||||
'Content-Length': data.length,
|
||||
'Content-Type': contentType
|
||||
},
|
||||
'uri': capURL,
|
||||
'body': data,
|
||||
'rejectUnauthorized': false,
|
||||
'method': 'PUT'
|
||||
}, (err, res, body) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve({ status: res.statusCode, body: body });
|
||||
}
|
||||
});
|
||||
const response = await got.put(capURL, {
|
||||
headers: {
|
||||
'Content-Length': String(Buffer.byteLength(data)),
|
||||
'Content-Type': contentType
|
||||
},
|
||||
body: data,
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
return { status: response.statusCode, body: response.body };
|
||||
}
|
||||
|
||||
requestGet(requestURL: string): Promise<ICapResponse>
|
||||
public async requestGet(requestURL: string): Promise<ICapResponse>
|
||||
{
|
||||
return new Promise<ICapResponse>((resolve, reject) =>
|
||||
{
|
||||
request({
|
||||
'uri': requestURL,
|
||||
'rejectUnauthorized': false,
|
||||
'method': 'GET'
|
||||
}, (err, res, body) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve({ status: res.statusCode, body: body });
|
||||
}
|
||||
});
|
||||
const response = await got.get(requestURL, {
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
return { status: response.statusCode, body: response.body };
|
||||
}
|
||||
|
||||
requestDelete(requestURL: string): Promise<ICapResponse>
|
||||
public async requestDelete(requestURL: string): Promise<ICapResponse>
|
||||
{
|
||||
return new Promise<ICapResponse>((resolve, reject) =>
|
||||
{
|
||||
request({
|
||||
'uri': requestURL,
|
||||
'rejectUnauthorized': false,
|
||||
'method': 'DELETE'
|
||||
}, (err, res, body) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve({ status: res.statusCode, body: body });
|
||||
}
|
||||
});
|
||||
const response = await got.delete(requestURL, {
|
||||
rejectUnauthorized: false
|
||||
});
|
||||
|
||||
return { status: response.statusCode, body: response.body };
|
||||
}
|
||||
|
||||
waitForSeedCapability(): Promise<void>
|
||||
@@ -348,11 +281,11 @@ export class Caps
|
||||
});
|
||||
}
|
||||
|
||||
capsRequestUpload(capURL: string, data: Buffer): Promise<any>
|
||||
public capsRequestUpload(capURL: string, data: Buffer): Promise<any>
|
||||
{
|
||||
return new Promise<any>((resolve, reject) =>
|
||||
{
|
||||
this.request(capURL, data, 'application/octet-stream').then((resp: ICapResponse) =>
|
||||
this.requestPost(capURL, data, 'application/octet-stream').then((resp: ICapResponse) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -415,12 +348,12 @@ export class Caps
|
||||
});
|
||||
}
|
||||
|
||||
capsPerformXMLPost(capURL: string, data: any): Promise<any>
|
||||
public capsPerformXMLPost(capURL: string, data: any): Promise<any>
|
||||
{
|
||||
return new Promise<any>(async(resolve, reject) =>
|
||||
{
|
||||
const xml = LLSD.LLSD.formatXML(data);
|
||||
this.request(capURL, xml, 'application/llsd+xml').then(async(resp: ICapResponse) =>
|
||||
this.requestPost(capURL, xml, 'application/llsd+xml').then(async(resp: ICapResponse) =>
|
||||
{
|
||||
let result: any = null;
|
||||
try
|
||||
|
||||
@@ -20,7 +20,7 @@ import { InventoryLibrary } from '../enums/InventoryLibrary';
|
||||
import { LandStatsEvent } from '../events/LandStatsEvent';
|
||||
|
||||
import * as LLSD from '@caspertech/llsd';
|
||||
import * as request from 'request';
|
||||
import got, { CancelableRequest, Response } from 'got';
|
||||
import * as Long from 'long';
|
||||
|
||||
export class EventQueueClient
|
||||
@@ -28,7 +28,7 @@ export class EventQueueClient
|
||||
caps: Caps;
|
||||
ack?: number;
|
||||
done = false;
|
||||
currentRequest: request.Request | null = null;
|
||||
private currentRequest?: CancelableRequest<Response<string>> = undefined;
|
||||
private clientEvents: ClientEvents;
|
||||
private agent: Agent;
|
||||
|
||||
@@ -47,9 +47,10 @@ export class EventQueueClient
|
||||
{
|
||||
// We must ACK any outstanding events
|
||||
this.done = true;
|
||||
if (this.currentRequest !== null)
|
||||
if (this.currentRequest)
|
||||
{
|
||||
this.currentRequest.abort();
|
||||
this.currentRequest.cancel();
|
||||
delete this.currentRequest;
|
||||
}
|
||||
const req = {
|
||||
'ack': this.ack,
|
||||
@@ -556,33 +557,33 @@ export class EventQueueClient
|
||||
}
|
||||
});
|
||||
}
|
||||
request(url: string, data: string, contentType: string): Promise<string>
|
||||
public async request(url: string, data: string, contentType: string): Promise<string>
|
||||
{
|
||||
return new Promise<string>((resolve, reject) =>
|
||||
let req: CancelableRequest<Response<string>> | undefined = undefined;
|
||||
try
|
||||
{
|
||||
this.currentRequest = request({
|
||||
'headers': {
|
||||
'Content-Length': data.length,
|
||||
req = got.post(url, {
|
||||
headers: {
|
||||
'Content-Length': Buffer.byteLength(data).toString(),
|
||||
'Content-Type': contentType
|
||||
},
|
||||
'uri': url,
|
||||
'body': data,
|
||||
'rejectUnauthorized': false,
|
||||
'method': 'POST',
|
||||
'timeout': 1800000 // Super long timeout
|
||||
}, (err, _res, body) =>
|
||||
{
|
||||
this.currentRequest = null;
|
||||
if (err)
|
||||
{
|
||||
reject(err);
|
||||
}
|
||||
else
|
||||
{
|
||||
resolve(body);
|
||||
}
|
||||
body: data,
|
||||
rejectUnauthorized: false,
|
||||
timeout: 1800000 // Super long timeout
|
||||
});
|
||||
});
|
||||
|
||||
this.currentRequest = req;
|
||||
|
||||
const response = await this.currentRequest;
|
||||
return response.body;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (this.currentRequest === req)
|
||||
{
|
||||
delete this.currentRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
capsPostXML(capability: string, data: any, attempt: number = 0): Promise<any>
|
||||
|
||||
670
package-lock.json
generated
670
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@caspertech/node-metaverse",
|
||||
"version": "0.6.18",
|
||||
"version": "0.6.19",
|
||||
"description": "A node.js interface for Second Life.",
|
||||
"main": "dist/lib/index.js",
|
||||
"types": "dist/lib/index.d.ts",
|
||||
@@ -26,7 +26,9 @@
|
||||
"@angular-eslint/eslint-plugin": "^12.7.0",
|
||||
"@types/micromatch": "^4.0.4",
|
||||
"@types/node": "^16.18.60",
|
||||
"@types/tiny-async-pool": "^2.0.2",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@types/xml2js": "^0.4.14",
|
||||
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
||||
"@typescript-eslint/eslint-plugin-tslint": "^4.33.0",
|
||||
"@typescript-eslint/parser": "^4.33.0",
|
||||
@@ -41,30 +43,28 @@
|
||||
"@caspertech/llsd": "^1.0.5",
|
||||
"@types/long": "^4.0.2",
|
||||
"@types/mocha": "^9.1.1",
|
||||
"@types/request": "^2.48.11",
|
||||
"@types/tiny-async-pool": "^1.0.3",
|
||||
"@types/validator": "^13.11.5",
|
||||
"@types/xml": "^1.0.10",
|
||||
"@types/xml2js": "^0.4.13",
|
||||
"@types/xmlrpc": "^1.3.9",
|
||||
"chalk": "^4.1.2",
|
||||
"flatted": "^3.2.9",
|
||||
"fs-extra": "^10.1.0",
|
||||
"glob": "^7.2.3",
|
||||
"got": "^11.8.6",
|
||||
"ipaddr.js": "^2.1.0",
|
||||
"logform": "^2.6.0",
|
||||
"long": "^4.0.0",
|
||||
"micromatch": "^4.0.5",
|
||||
"moment": "^2.29.4",
|
||||
"qs": "^6.5.3",
|
||||
"rbush-3d": "0.0.4",
|
||||
"request": "^2.88.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"tiny-async-pool": "^1.3.0",
|
||||
"tiny-async-pool": "^2.1.0",
|
||||
"uuid": "^8.3.2",
|
||||
"validator": "^13.11.0",
|
||||
"winston": "^3.11.0",
|
||||
"xml": "^1.0.1",
|
||||
"xml2js": "^0.4.23",
|
||||
"xml2js": "^0.5.0",
|
||||
"xmlbuilder": "^15.1.1",
|
||||
"xmlrpc": "github:CasperTech/node-xmlrpc"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user