2015-09-07 12:00:19 +08:00
module . exports = CEconItem ;
2016-12-13 14:53:30 +08:00
function CEconItem ( item , description , contextID ) {
2021-07-29 14:55:56 +08:00
for ( let thing in item ) {
this [ thing ] = item [ thing ] ;
2015-09-07 12:00:19 +08:00
}
2021-07-29 14:55:56 +08:00
let isCurrency = ! ! ( this . is _currency || this . currency ) || typeof this . currencyid !== 'undefined' ; // I don't want to put this on the object yet; it's nice to have the ids at the top of printed output
2016-12-13 13:45:23 +08:00
if ( isCurrency ) {
this . currencyid = this . id = ( this . id || this . currencyid ) ;
} else {
this . assetid = this . id = ( this . id || this . assetid ) ;
}
2015-09-07 12:00:19 +08:00
this . instanceid = this . instanceid || '0' ;
this . amount = parseInt ( this . amount , 10 ) ;
2015-09-10 00:04:28 +08:00
this . contextid = this . contextid || contextID . toString ( ) ;
2015-09-07 12:00:19 +08:00
// Merge the description
2016-12-13 14:53:30 +08:00
if ( description ) {
// Is this a listing of descriptions?
if ( description [ this . classid + '_' + this . instanceid ] ) {
description = description [ this . classid + '_' + this . instanceid ] ;
}
2021-07-29 14:55:56 +08:00
for ( let thing in description ) {
this [ thing ] = description [ thing ] ;
2015-09-07 12:00:19 +08:00
}
}
2016-12-13 13:45:23 +08:00
this . is _currency = isCurrency ;
2015-09-07 12:00:19 +08:00
this . tradable = ! ! this . tradable ;
this . marketable = ! ! this . marketable ;
this . commodity = ! ! this . commodity ;
this . market _tradable _restriction = ( this . market _tradable _restriction ? parseInt ( this . market _tradable _restriction , 10 ) : 0 ) ;
this . market _marketable _restriction = ( this . market _marketable _restriction ? parseInt ( this . market _marketable _restriction , 10 ) : 0 ) ;
2015-12-22 03:22:07 +08:00
this . fraudwarnings = this . fraudwarnings || [ ] ;
this . descriptions = this . descriptions || [ ] ;
2016-12-13 13:45:23 +08:00
if ( this . owner && JSON . stringify ( this . owner ) == '{}' ) {
2015-12-22 03:22:07 +08:00
this . owner = null ;
}
2016-12-13 14:53:30 +08:00
// Restore old property names of tags
if ( this . tags ) {
2021-07-29 15:20:14 +08:00
this . tags = this . tags . map ( ( tag ) => ( {
internal _name : tag . internal _name ,
name : tag . localized _tag _name || tag . name ,
category : tag . category ,
color : tag . color || '' ,
category _name : tag . localized _category _name || tag . category _name
} ) ) ;
2016-12-13 14:53:30 +08:00
}
2016-12-15 13:53:26 +08:00
// Restore market_fee_app, if applicable
2021-07-29 14:55:56 +08:00
let match ;
if ( this . appid == 753 && this . contextid == 6 && this . market _hash _name && ( match = this . market _hash _name . match ( /^(\d+)-/ ) ) ) {
2016-12-15 13:53:26 +08:00
this . market _fee _app = parseInt ( match [ 1 ] , 10 ) ;
}
2019-09-21 16:27:39 +08:00
// Restore cache_expiration, if we can (for CS:GO items)
if ( this . appid == 730 && this . contextid == 2 && this . owner _descriptions ) {
let description = this . owner _descriptions . find ( d => d . value && d . value . indexOf ( 'Tradable After ' ) == 0 ) ;
if ( description ) {
let date = new Date ( description . value . substring ( 15 ) . replace ( /[,()]/g , '' ) ) ;
if ( date ) {
this . cache _expiration = date . toISOString ( ) ;
}
}
}
// If we have item_expiration, also set cache_expiration to the same value
if ( this . item _expiration ) {
this . cache _expiration = this . item _expiration ;
}
2021-07-29 14:55:56 +08:00
if ( this . actions === '' ) {
2016-12-13 14:53:30 +08:00
this . actions = [ ] ;
}
2020-07-01 12:52:15 +08:00
// One wouldn't think that we need this if statement, but apparently v8 has a weird bug/quirk where deleting a
// property results in greatly increased memory usage. Because that makes sense.
2020-07-01 10:24:04 +08:00
if ( this . currency ) {
delete this . currency ;
}
2015-09-07 12:00:19 +08:00
}
CEconItem . prototype . getImageURL = function ( ) {
2021-07-29 14:55:56 +08:00
return 'https://steamcommunity-a.akamaihd.net/economy/image/' + this . icon _url + '/' ;
2015-09-07 12:00:19 +08:00
} ;
CEconItem . prototype . getLargeImageURL = function ( ) {
2021-07-29 14:55:56 +08:00
if ( ! this . icon _url _large ) {
2015-09-07 12:00:19 +08:00
return this . getImageURL ( ) ;
}
2021-07-29 14:55:56 +08:00
return 'https://steamcommunity-a.akamaihd.net/economy/image/' + this . icon _url _large + '/' ;
2015-09-07 12:00:19 +08:00
} ;
CEconItem . prototype . getTag = function ( category ) {
2016-12-13 14:53:30 +08:00
if ( ! this . tags ) {
2015-09-07 12:00:19 +08:00
return null ;
}
2021-07-29 14:55:56 +08:00
for ( let i = 0 ; i < this . tags . length ; i ++ ) {
2016-12-13 14:53:30 +08:00
if ( this . tags [ i ] . category == category ) {
2015-09-07 12:00:19 +08:00
return this . tags [ i ] ;
}
}
return null ;
} ;