From 48924de86d29c6b847742f31e35d36b5b0ed74e8 Mon Sep 17 00:00:00 2001 From: Step7750 Date: Tue, 1 Aug 2023 20:50:42 -0600 Subject: [PATCH] Updates Various Endpoints to `csfloat.com` --- src/lib/bridge/handlers/fetch_inspect_info.ts | 2 +- .../bridge/handlers/fetch_pending_trades.ts | 26 ++++++++++++++++--- src/lib/bridge/handlers/fetch_stall.ts | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/lib/bridge/handlers/fetch_inspect_info.ts b/src/lib/bridge/handlers/fetch_inspect_info.ts index 986d7f35..63dc1699 100644 --- a/src/lib/bridge/handlers/fetch_inspect_info.ts +++ b/src/lib/bridge/handlers/fetch_inspect_info.ts @@ -52,7 +52,7 @@ export interface FetchInspectInfoResponse { export const FetchInspectInfo = new SimpleHandler( RequestType.FETCH_INSPECT_INFO, (req) => { - const apiUrl = `https://api.csgofloat.com/?url=${req.link}&minimal=true${ + const apiUrl = `https://api.csfloat.com/?url=${req.link}&minimal=true${ req.listPrice ? '&listPrice=' + req.listPrice : '' }`; return fetch(apiUrl).then((resp) => { diff --git a/src/lib/bridge/handlers/fetch_pending_trades.ts b/src/lib/bridge/handlers/fetch_pending_trades.ts index 0b80b953..61f966ef 100644 --- a/src/lib/bridge/handlers/fetch_pending_trades.ts +++ b/src/lib/bridge/handlers/fetch_pending_trades.ts @@ -12,10 +12,28 @@ export interface FetchPendingTradesResponse { export const FetchPendingTrades = new SimpleHandler( RequestType.FETCH_PENDING_TRADES, async (req) => { - return fetch(`https://csgofloat.com/api/v1/me/pending-trades`, { - credentials: 'include', - }).then((resp) => { + try { + const resp = await fetch(`https://csfloat.com/api/v1/me/pending-trades`, { + credentials: 'include', + }); + + if (resp.status !== 200) { + throw new Error('invalid status'); + } + return resp.json() as Promise; - }); + } catch (e) { + // Try the old CSGOFloat URL (in case they have an old session from there) + // Of note, this can be removed ~1 week after the migration. + const resp = await fetch(`https://csgofloat.com/api/v1/me/pending-trades`, { + credentials: 'include', + }); + + if (resp.status !== 200) { + throw new Error('invalid status'); + } + + return resp.json(); + } } ); diff --git a/src/lib/bridge/handlers/fetch_stall.ts b/src/lib/bridge/handlers/fetch_stall.ts index 984f14e1..17490c73 100644 --- a/src/lib/bridge/handlers/fetch_stall.ts +++ b/src/lib/bridge/handlers/fetch_stall.ts @@ -19,7 +19,7 @@ export interface FetchStallResponseError { export const FetchStall = new SimpleHandler( RequestType.FETCH_STALL, async (req) => { - return fetch(`https://csgofloat.com/api/v1/users/${req.steam_id64}/stall`).then((resp) => { + return fetch(`https://csfloat.com/api/v1/users/${req.steam_id64}/stall`).then((resp) => { return resp.json().then((json: FetchStallResponse | FetchStallResponseError) => { if (resp.ok) { return json;