Skip to content

Commit 8b9b43a

Browse files
rainerstudiosclaude
andcommitted
Update Steam inventory endpoint to match frontend specification
Changes to lib/steam-inventory.js: - Changed field names to match frontend spec (assetid instead of asset_id) - Added wear abbreviations (FN, MW, FT, WW, BS) - Added wear_full field for full wear name - Separated icon_url (path only) from image_url (full CDN URL) - Added float_value, pattern_index, defindex, paintindex placeholders - Extracted defindex from inspect link parameters - Added both full and abbreviated wear formats Changes to index.js: - Updated inventory sync endpoint to use assetid field Response format now includes: - assetid, classid, instanceid (core IDs) - name, market_name, market_hash_name (display names) - icon_url (CDN path), image_url (full URL) - tradable, marketable, commodity (trading flags) - is_stattrak, is_souvenir (item attributes) - wear (FN/MW/FT/WW/BS), wear_full (Factory New, etc) - float_value, pattern_index, defindex, paintindex (inspection data) - rarity, weapon_type, category, quality (item metadata) - inspect_link (for float inspection) Endpoint: GET /api/steam/inventory/:steamId Authentication: Required (Better Auth session token) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3bcd1e3 commit 8b9b43a

2 files changed

Lines changed: 66 additions & 17 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4092,7 +4092,7 @@ app.post('/api/steam/inventory/sync', requireAuth, async (req, res) => {
40924092

40934093
// Filter items to sync (either all or selected)
40944094
const itemsToSync = selected_items.length > 0
4095-
? inventoryResult.items.filter(item => selected_items.includes(item.asset_id))
4095+
? inventoryResult.items.filter(item => selected_items.includes(item.assetid))
40964096
: inventoryResult.items;
40974097

40984098
// Add each item to portfolio

lib/steam-inventory.js

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ function parseInventoryItems(data) {
7676
const items = [];
7777
const descriptionMap = new Map();
7878

79+
// Wear abbreviation mapping
80+
const wearMap = {
81+
'Factory New': 'FN',
82+
'Minimal Wear': 'MW',
83+
'Field-Tested': 'FT',
84+
'Well-Worn': 'WW',
85+
'Battle-Scarred': 'BS'
86+
};
87+
7988
// Create a map of descriptions for fast lookup
8089
for (const desc of data.descriptions) {
8190
const key = `${desc.classid}_${desc.instanceid}`;
@@ -89,36 +98,73 @@ function parseInventoryItems(data) {
8998

9099
if (!description) continue;
91100

92-
// Extract item details
101+
// Extract wear from market name
102+
const wearMatch = description.market_name?.match(/\((Factory New|Minimal Wear|Field-Tested|Well-Worn|Battle-Scarred)\)/);
103+
const wearFull = wearMatch ? wearMatch[1] : null;
104+
const wear = wearFull ? wearMap[wearFull] : null;
105+
106+
// Extract item details matching frontend specification
93107
const item = {
94-
asset_id: asset.assetid,
95-
name: description.market_name || description.name,
96-
name_color: description.name_color,
108+
// Core identification
109+
assetid: asset.assetid,
110+
classid: asset.classid,
111+
instanceid: asset.instanceid,
112+
113+
// Display names
114+
name: description.name,
115+
market_name: description.market_name,
116+
market_hash_name: description.market_hash_name,
117+
118+
// Item properties
97119
type: description.type,
120+
icon_url: description.icon_url, // Just the path, frontend can add CDN prefix
121+
icon_url_large: description.icon_url_large,
122+
name_color: description.name_color,
123+
124+
// Trading properties
125+
tradable: description.tradable === 1,
126+
marketable: description.marketable === 1,
127+
commodity: description.commodity === 1,
128+
129+
// Item attributes
130+
is_stattrak: description.market_name?.includes('StatTrak™') || false,
131+
is_souvenir: description.market_name?.includes('Souvenir') || false,
132+
wear: wear,
133+
wear_full: wearFull,
134+
135+
// Tags and metadata
98136
rarity: extractTag(description.tags, 'Rarity'),
99137
rarity_color: extractTagColor(description.tags, 'Rarity'),
100138
exterior: extractTag(description.tags, 'Exterior'),
101139
weapon_type: extractTag(description.tags, 'Type'),
102140
category: extractTag(description.tags, 'Category'),
103141
quality: extractTag(description.tags, 'Quality'),
142+
143+
// Full CDN URLs (for convenience)
104144
image_url: `https://community.cloudflare.steamstatic.com/economy/image/${description.icon_url}`,
105145
image_large: description.icon_url_large ? `https://community.cloudflare.steamstatic.com/economy/image/${description.icon_url_large}` : null,
106-
marketable: description.marketable === 1,
107-
tradable: description.tradable === 1,
108-
commodity: description.commodity === 1,
109-
market_hash_name: description.market_hash_name,
146+
147+
// Float value placeholders (will be null unless fetched)
148+
float_value: null,
149+
pattern_index: null,
150+
defindex: null,
151+
paintindex: null,
152+
153+
// Item descriptions
110154
descriptions: description.descriptions || []
111155
};
112156

113-
// Check if StatTrak
114-
item.is_stattrak = item.name.includes('StatTrak™');
115-
item.is_souvenir = item.name.includes('Souvenir');
116-
117-
// Extract float value from inspect link if available
157+
// Extract inspect link if available
118158
const inspectLink = extractInspectLink(description.actions);
119159
if (inspectLink) {
120160
item.inspect_link = inspectLink;
121-
item.inspect_params = parseInspectLink(inspectLink);
161+
const params = parseInspectLink(inspectLink);
162+
item.inspect_params = params;
163+
164+
// Extract defindex from inspect link if available
165+
if (params.d) {
166+
item.defindex = parseInt(params.d);
167+
}
122168
}
123169

124170
items.push(item);
@@ -196,10 +242,13 @@ async function getInventoryValue(steamId, postgres) {
196242
valuedItems++;
197243

198244
itemValues.push({
199-
name: item.name,
245+
assetid: item.assetid,
246+
name: item.market_name || item.name,
200247
market_hash_name: item.market_hash_name,
201248
price: price,
202-
image: item.image_url
249+
image: item.image_url,
250+
wear: item.wear,
251+
is_stattrak: item.is_stattrak
203252
});
204253
}
205254
}

0 commit comments

Comments
 (0)