Choose the right transfer method for assets

This commit is contained in:
Casper Warden
2023-11-17 10:32:39 +00:00
parent b481ad59bb
commit a31d0deb4e
4 changed files with 52 additions and 25 deletions

View File

@@ -53,14 +53,13 @@ export class ObjectResolver
{
this.objectsInQueue[id] = {
object: objs[id],
skipInventory: options.skipInventory === true,
log: options.outputLog === true
options
};
this.queue.push(id);
}
else if (this.objectsInQueue[id].skipInventory && !options.skipInventory)
else if (this.objectsInQueue[id].options.skipInventory && !options.skipInventory)
{
this.objectsInQueue[id].skipInventory = true
this.objectsInQueue[id].options.skipInventory = false;
}
};
@@ -324,12 +323,12 @@ export class ObjectResolver
{
return;
}
if (!job.skipInventory)
if (!job.options.skipInventory && (job.options.includeTempObjects || ((job.object.Flags ?? 0) & PrimFlags.TemporaryOnRez) === 0))
{
const o = job.object;
if ((o.resolveAttempts === undefined || o.resolveAttempts < 3) && o.FullID !== undefined && o.name !== undefined && o.Flags !== undefined && !(o.Flags & PrimFlags.InventoryEmpty) && (!o.inventory || o.inventory.length === 0))
{
if (job.log)
if (job.options.outputLog)
{
// console.log('Processing inventory for ' + job.object.ID);
}
@@ -358,7 +357,7 @@ export class ObjectResolver
}
else
{
if (job.log)
if (job.options.outputLog)
{
// console.log('Skipping inventory for ' + job.object.ID);
}
@@ -461,7 +460,7 @@ export class ObjectResolver
await Promise.all(promises);
for (const job of jobs)
{
if (job.log)
if (job.options.outputLog)
{
// console.log('Signalling resolve OK for ' + job.object.ID);
}

View File

@@ -21,6 +21,7 @@ import { BulkUpdateInventoryEvent } from '../../events/BulkUpdateInventoryEvent'
import { FilterResponse } from '../../enums/FilterResponse';
import { LLLindenText } from '../LLLindenText';
import { Subscription } from 'rxjs';
import { Logger } from '../Logger';
export class AssetCommands extends CommandsBase
{
@@ -30,26 +31,53 @@ export class AssetCommands extends CommandsBase
{
uuid = new UUID(uuid);
}
try
{
const result = await this.currentRegion.caps.downloadAsset(uuid, type);
if (result.toString('utf-8').trim() === 'Not found!')
switch (type)
{
throw new Error('Asset not found');
case HTTPAssets.ASSET_TEXTURE:
case HTTPAssets.ASSET_SOUND:
case HTTPAssets.ASSET_ANIMATION:
case HTTPAssets.ASSET_GESTURE:
case HTTPAssets.ASSET_LANDMARK:
case HTTPAssets.ASSET_CLOTHING:
case HTTPAssets.ASSET_MATERIAL:
case HTTPAssets.ASSET_BODYPART:
case HTTPAssets.ASSET_MESH:
return this.currentRegion.caps.downloadAsset(uuid, type);
case HTTPAssets.ASSET_CALLINGCARD:
case HTTPAssets.ASSET_SCRIPT:
case HTTPAssets.ASSET_OBJECT:
case HTTPAssets.ASSET_NOTECARD:
case HTTPAssets.ASSET_CATEGORY:
case HTTPAssets.ASSET_LSL_TEXT:
case HTTPAssets.ASSET_LSL_BYTECODE:
case HTTPAssets.ASSET_SIMSTATE:
case HTTPAssets.ASSET_LINK:
case HTTPAssets.ASSET_LINK_FOLDER:
case HTTPAssets.ASSET_WIDGET:
case HTTPAssets.ASSET_PERSON:
case HTTPAssets.ASSET_SETTINGS:
{
const transferParams = Buffer.allocUnsafe(20);
uuid.writeToBuffer(transferParams, 0);
transferParams.writeInt32LE(Utils.HTTPAssetTypeToAssetType(type), 16);
return this.transfer(TransferChannelType.Asset, TransferSourceType.Asset, false, transferParams);
}
}
else if (result.toString('utf-8').trim() === 'Incorrect Syntax')
{
throw new Error('Invalid Syntax');
}
return result;
}
catch (error)
catch (e: unknown)
{
// Fall back to old asset transfer
const transferParams = Buffer.allocUnsafe(20);
uuid.writeToBuffer(transferParams, 0);
transferParams.writeInt32LE(parseInt(type, 10), 16);
return this.transfer(TransferChannelType.Asset, TransferSourceType.Asset, false, transferParams);
if (e instanceof Error)
{
Logger.Error('Failed to download ' + type + ' asset ' + uuid.toString() + ' - ' + e.message)
}
else
{
Logger.Error('Failed to download ' + type + ' asset ' + uuid.toString() + ' - ' + String(e));
}
throw e;
}
}

View File

@@ -1,8 +1,8 @@
import { GameObject } from '../..';
import { GetObjectsOptions } from '../commands/RegionCommands';
export interface IResolveJob
{
object: GameObject,
skipInventory: boolean,
log: boolean
options: GetObjectsOptions,
}

View File

@@ -1,6 +1,6 @@
{
"name": "@caspertech/node-metaverse",
"version": "0.6.15",
"version": "0.6.16",
"description": "A node.js interface for Second Life.",
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",