From 8d9d682ba6db6e34d3f68f6d38f1bba3f190db32 Mon Sep 17 00:00:00 2001 From: wangxingzhen Date: Sat, 19 Oct 2024 21:45:42 +0800 Subject: [PATCH] Save all fields for keychains and adjust the order of the keychains field.Remove the logic: && item.defindex !== 1355. --- lib/postgres.js | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/postgres.js b/lib/postgres.js index 9bd82f6..4f16e05 100644 --- a/lib/postgres.js +++ b/lib/postgres.js @@ -210,10 +210,9 @@ class Postgres { buf.writeFloatBE(item.floatvalue, 0); item.paintwear = buf.readInt32BE(0); - if (item.floatvalue <= 0 && item.defindex !== 507 && item.defindex !== 1355) { - // Only insert weapons and keychains, naive check - // Special case for the 0 float Karambit and keychains. - // The keychains has a unique pattern + if (item.floatvalue <= 0 && item.defindex !== 507) { + // Only insert weapons, naive check + // Special case for the 0 float Karambit continue; } @@ -253,11 +252,17 @@ class Postgres { const keychains = item.keychains.length > 0 ? item.keychains.map((s) => { const res = {s: s.slot, i: s.sticker_id}; - if (s.pattern) { - res.pattern = s.pattern; + if (s.wear) { + res.w = s.wear; + } + if (s.scale) { + res.scale = s.scale; + } + if (s.rotation) { + res.r = s.rotation; } - if (s.name) { - res.name = s.name; + if (s.tint_id) { + res.tint_id = s.tint_id; } if (s.offset_x) { res.x = s.offset_x; @@ -268,6 +273,9 @@ class Postgres { if (s.offset_z) { res.z = s.offset_z; } + if (s.pattern) { + res.pattern = s.pattern; + } return res; }) : null; @@ -288,7 +296,7 @@ class Postgres { } values.push([ms, item.a, item.d, item.paintseed, item.paintwear, item.defindex, item.paintindex, isStattrak, - isSouvenir, props, JSON.stringify(stickers), item.rarity, price, JSON.stringify(keychains)]); + isSouvenir, props, JSON.stringify(stickers), JSON.stringify(keychains), item.rarity, price]); } if (values.length === 0) { @@ -308,13 +316,13 @@ class Postgres { const values = []; let i = 1; - // Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, now(), $12, NULL, $13) + // Builds binding pattern such as ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11::jsonb, $12::jsonb, now(), $13, NULL, $14) for (let c = 0; c < itemCount; c++) { - values.push(`($${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}::jsonb, now(), $${i++}, NULL, $${i++}, $${i++}::jsonb)`); + values.push(`($${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}, $${i++}::jsonb, $${i++}::jsonb, now(), $${i++}, NULL, $${i++})`); } - return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, updated, rarity, floatid, price, keychains) - VALUES ${values.join(', ')} ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, updated=now(), keychains=excluded.keychains`; + return `INSERT INTO items (ms, a, d, paintseed, paintwear, defindex, paintindex, stattrak, souvenir, props, stickers, keychains, updated, rarity, floatid, price) + VALUES ${values.join(', ')} ON CONFLICT(defindex, paintindex, paintwear, paintseed) DO UPDATE SET ms=excluded.ms, a=excluded.a, d=excluded.d, stickers=excluded.stickers, keychains=excluded.keychains, updated=now()`; } updateItemPrice(assetId, price) { @@ -385,11 +393,14 @@ class Postgres { return { sticker_id: s.i, slot: s.s, - pattern: s.pattern, - name: s.name, + wear: s.w, + scale: s.scale, + rotation: s.r, + tint_id: s.tint_id, offset_x: s.x, offset_y: s.y, offset_z: s.z, + pattern: s.pattern, } });