Description
Supported Script Types: Interface Scripts • Client Entity Scripts • Avatar Scripts • Server Entity Scripts • Assignment Client Scripts
TheAssets
API provides facilities for interacting with the domain's asset server and the client cache.
Assets are stored in the asset server in files with SHA256 names. These files are mapped to user-friendly URLs of the
format: atp:/path/filename
. The assets may optionally be baked, in which case a request for the original
unbaked version of the asset is automatically redirected to the baked version. The asset data may optionally be stored as
compressed.
The client cache can be accessed directly, using "atp:"
or "cache:"
URLs. Interface, avatar,
and assignment client scripts can write to the cache. All script types can read from the cache.
Methods
Name | Return Value | Summary |
---|---|---|
canWriteCacheValue
|
boolean |
Checks whether the script can write to the cache. |
compressData
|
None |
Compresses data in memory using gzip. |
decompressData
|
None |
Decompresses data in memory using gunzip. |
deleteAsset
|
None |
Deletes content from the asset server. Not implemented: This method is not implemented yet. |
downloadData
|
None |
Downloads content from the asset server, from a SHA256-named file. |
extractAssetHash
|
string |
Gets the SHA256 hexadecimal hash portion of an asset server URL. |
getAsset
|
None |
Downloads content from the asset server. |
getATPUrl
|
string |
Gets the normalized ATP URL for a path or hash: ensures that it has |
getCacheStatus
|
None |
Gets the current cache status. |
getMapping
|
None |
Gets the hash for a path within the asset server. The hash is for the unbaked or baked version of the asset, according to the asset server setting for the particular path. |
hashData
|
ArrayBuffer |
Calculates the SHA256 hash of given data. |
hashDataHex
|
string |
Calculates the SHA256 hash of given data, in hexadecimal format. |
initializeCache
|
boolean |
Initializes the cache if it isn't already initialized. |
isValidFilePath
|
boolean |
Checks whether a string is a valid path and filename. Note: A valid path and filename must start with a |
isValidHash
|
boolean |
Checks whether a string is a valid SHA256 hexadecimal hash, i.e., 64 hexadecimal characters. |
isValidPath
|
boolean |
Checks whether a string is a valid path. Note: A valid path must start with a |
loadFromCache
|
None |
Retrieves data from the cache directly, without downloading it. |
putAsset
|
None |
Uploads content to the asset server and sets a path-to-hash mapping. |
queryCacheMeta
|
None |
Gets information about the status of an asset in the cache. |
resolveAsset
|
None |
Resolves and returns information on a hash or a path in the asset server. |
saveToCache
|
None |
Saves asset data to the cache directly, without downloading it from a URL. Note: Can only be used in Interface, avatar, and assignment client scripts. |
saveToCache
|
None |
Saves asset data to the cache directly, without downloading it from a URL. Note: Can only be used in Interface, avatar, and assignment client scripts. |
setBakingEnabled
|
None |
Sets whether or not to bake an asset in the asset server. |
setMapping
|
None |
Sets a path-to-hash mapping within the asset server. |
uploadData
|
None |
Uploads content to the asset server, storing it in a SHA256-named file. Note: The asset server destroys any unmapped SHA256-named file at server restart. Use Assets.setMapping to set a path-to-hash mapping for the new file. |
Type Definitions
CacheItemMetaData Type: object |
||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Information on an asset in the cache. Value returned by Assets.queryCacheMeta and included in the data returned by Assets.loadFromCache. Properties
|
CallbackDetails Type: object |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Details of a callback function. Properties
|
CompressOptions Type: object |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Content and compression options for Assets.compressData. Properties
|
CompressResult Type: object |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Result value returned by Assets.compressData. Properties
|
DecompressOptions Type: object |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Content and decompression options for Assets.decompressData. Properties
|
DecompressResult Type: object |
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Result value returned by Assets.decompressData. Properties
|
DownloadDataError Type: object |
||||||
---|---|---|---|---|---|---|
The success or failure of an Assets.downloadData call. Properties
|
GetCacheStatusResult Type: object |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Cache status value returned by Assets.getCacheStatus. Properties
|
GetOptions Type: object |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Source and download options for Assets.getAsset. Properties
|
GetResult Type: object |
||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Result value returned by Assets.getAsset. Properties
|
LoadFromCacheOptions Type: object |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Source and retrieval options for Assets.loadFromCache. Properties
|
LoadFromCacheResult Type: object |
||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Data and information returned by Assets.loadFromCache. Properties
|
PutOptions Type: object |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Content and upload options for Assets.putAsset. Properties
|
PutResult Type: object |
||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Result value returned by Assets.putAsset. Properties
|
QueryCacheMetaOptions Type: object |
||||||
---|---|---|---|---|---|---|
Source for Assets.queryCacheMeta. Properties
|
ResolveOptions Type: object |
||||||
---|---|---|---|---|---|---|
Source options for Assets.resolveAsset. Properties
|
ResolveResult Type: object |
||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Result value returned by Assets.resolveAsset. Note: If resolving a hash, a file of that hash need not be present on the asset server for the hash to resolve. Properties
|
ResponseType Type: string |
||||||||
---|---|---|---|---|---|---|---|---|
Types of response that Assets.decompressData, Assets.getAsset, or Assets.loadFromCache may provide.
|
SaveToCacheHeaders Type: object |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Last-modified and expiry times for a cache item. Properties
|
SaveToCacheOptions Type: object |
||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
The data to save to the cache and cache options for Assets.saveToCache. Properties
|
SaveToCacheResult Type: object |
||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Information on saving asset data to the cache with Assets.saveToCache. Properties
|
compressDataCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.compressData call is complete. Parameters
|
decompressDataCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.decompressData call is complete. Parameters
|
deleteAssetCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.deleteAsset call is complete. Not implemented: This type is not implemented yet. Parameters
|
downloadDataCallback( data, error )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.downloadData call is complete. Parameters
|
getAssetCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.getAsset call is complete. Parameters
|
getCacheStatusCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when a Assets.getCacheStatus call is complete. Parameters
|
getMappingCallback( error, hash )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.getMapping call is complete. Parameters
|
loadFromCacheCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.loadFromCache call is complete. Parameters
|
putAssetCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.putAsset call is complete. Parameters
|
queryCacheMetaCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when Assets.queryCacheMeta is complete. Parameters
|
resolveAssetCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.resolveAsset call is complete. Parameters
|
saveToCacheCallback( error, result )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.saveToCache call is complete. Parameters
|
setBakingEnabledCallback( error )
Type: function |
||||||
---|---|---|---|---|---|---|
Called when an Assets.setBakingEnabled call is complete. Parameters
|
setMappingCallback( error )
Type: function |
||||||
---|---|---|---|---|---|---|
Called when an Assets.setMapping call is complete. Parameters
|
uploadDataCallback( url, hash )
Type: function |
|||||||||
---|---|---|---|---|---|---|---|---|---|
Called when an Assets.uploadData call is complete. Parameters
|
Method Details
(static) canWriteCacheValue( url ) → {boolean}
Returns: true if the script is an Interface, avatar, or assignment client script,
false if the script is a client entity or server entity script.
|
||||||
---|---|---|---|---|---|---|
Checks whether the script can write to the cache. Parameters
Example
|
(static) compressData( source, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Compresses data in memory using gzip. Parameters
|
(static) decompressData( source, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Decompresses data in memory using gunzip. Parameters
|
(static) deleteAsset( options, scope, callback ) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Deletes content from the asset server. Not implemented: This method is not implemented yet. Parameters
|
(static) downloadData( url, callback ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Downloads content from the asset server, from a SHA256-named file. Parameters
Example
|
(static) extractAssetHash( url ) → {string}
Returns: The SHA256 hexadecimal hash portion of the URL if present and valid, "" otherwise.
|
||||||
---|---|---|---|---|---|---|
Gets the SHA256 hexadecimal hash portion of an asset server URL. Parameters
|
(static) getAsset( source, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Downloads content from the asset server. Parameters
Example
|
(static) getATPUrl( url ) → {string}
Returns: The normalized ATP URL. |
||||||
---|---|---|---|---|---|---|
Gets the normalized ATP URL for a path or hash: ensures that it has Parameters
|
(static) getCacheStatus( scopeOrCallback, callbackopt ) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Gets the current cache status. Parameters
Example
|
(static) getMapping( path, callback ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Gets the hash for a path within the asset server. The hash is for the unbaked or baked version of the asset, according to the asset server setting for the particular path. Parameters
Example
|
(static) hashData( data ) → {ArrayBuffer}
Returns: The SHA256 hash of the data .
|
||||||
---|---|---|---|---|---|---|
Calculates the SHA256 hash of given data. Parameters
|
(static) hashDataHex( data ) → {string}
Returns: The SHA256 hash of the data , in hexadecimal format.
|
||||||
---|---|---|---|---|---|---|
Calculates the SHA256 hash of given data, in hexadecimal format. Parameters
Example
|
(static) initializeCache( ) → {boolean}
Returns: true if the cache is initialized, false if it isn't.
|
---|
Initializes the cache if it isn't already initialized. |
(static) isValidFilePath( path ) → {boolean}
Returns: true if the path is a valid file path, false if it isn't.
|
||||||
---|---|---|---|---|---|---|
Checks whether a string is a valid path and filename. Note: A valid path and filename must start with a Parameters
|
(static) isValidHash( hash ) → {boolean}
Returns: true if the hash is a valid SHA256 hexadecimal string, false if it isn't.
|
||||||
---|---|---|---|---|---|---|
Checks whether a string is a valid SHA256 hexadecimal hash, i.e., 64 hexadecimal characters. Parameters
|
(static) isValidPath( path ) → {boolean}
Returns: true if the path is a valid path, false if it isn't.
|
||||||
---|---|---|---|---|---|---|
Checks whether a string is a valid path. Note: A valid path must start with a Parameters
|
(static) loadFromCache( options, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Retrieves data from the cache directly, without downloading it. Parameters
Example
|
(static) putAsset( options, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Uploads content to the asset server and sets a path-to-hash mapping. Parameters
Example
|
(static) queryCacheMeta( path, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Gets information about the status of an asset in the cache. Parameters
Example
|
(static) resolveAsset( source, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Resolves and returns information on a hash or a path in the asset server. Parameters
Example
|
(static) saveToCache( options, scopeOrCallback, callbackopt ) | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Saves asset data to the cache directly, without downloading it from a URL. Note: Can only be used in Interface, avatar, and assignment client scripts. Parameters
Example
|
(static) saveToCache( url, data, headers, scopeOrCallback, callbackopt ) | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Saves asset data to the cache directly, without downloading it from a URL. Note: Can only be used in Interface, avatar, and assignment client scripts. Parameters
|
(static) setBakingEnabled( path, enabled, callback ) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Sets whether or not to bake an asset in the asset server. Parameters
|
(static) setMapping( path, hash, callback ) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Sets a path-to-hash mapping within the asset server. Parameters
|
(static) uploadData( data, callback ) | |||||||||
---|---|---|---|---|---|---|---|---|---|
Uploads content to the asset server, storing it in a SHA256-named file. Note: The asset server destroys any unmapped SHA256-named file at server restart. Use Assets.setMapping to set a path-to-hash mapping for the new file. Parameters
Example
|