diff --git a/app/main/get-websocket-uri/get-websocket-uri.js b/app/main/get-websocket-uri/get-websocket-uri.js index 28f506d8..c945a6b9 100644 --- a/app/main/get-websocket-uri/get-websocket-uri.js +++ b/app/main/get-websocket-uri/get-websocket-uri.js @@ -4,9 +4,13 @@ import * as regExes from "../../shared/resources/RegExes/RegExes"; const getWebSocketUri = url => { const matchDetails = url.match(regExes.poeTradeUrl); - const [, league, id] = matchDetails; + const [, game, league, id] = matchDetails; - return `${baseUrls.poeWsUri}/${league}/${id}`; + if (game === "trade") { + return `${baseUrls.poeWsUri}/${league}/${id}`; + } else { + return `${baseUrls.poe2WsUri}/${league}/${id}`; + } }; export default getWebSocketUri; diff --git a/app/shared/resources/BaseUrls/BaseUrls.js b/app/shared/resources/BaseUrls/BaseUrls.js index eef681da..abc9cd57 100644 --- a/app/shared/resources/BaseUrls/BaseUrls.js +++ b/app/shared/resources/BaseUrls/BaseUrls.js @@ -1,6 +1,7 @@ export const poeFetchAPI = "https://www.pathofexile.com/api/trade/fetch"; export const poeWsUri = "wss://www.pathofexile.com/api/trade/live"; +export const poe2WsUri = "wss://www.pathofexile.com/api/trade2/live/poe2"; export const sessionIdWiki = "https://github.com/Stickymaddness/Procurement/wiki/SessionID"; diff --git a/app/shared/resources/RegExes/RegExes.js b/app/shared/resources/RegExes/RegExes.js index df1e1e62..d2448560 100644 --- a/app/shared/resources/RegExes/RegExes.js +++ b/app/shared/resources/RegExes/RegExes.js @@ -1,2 +1 @@ -// https://regex101.com/r/RNsEkt/4 -export const poeTradeUrl = /^(?:https?:\/\/)?(?:www\.)?(?:\\w+\.)?(?:pathofexile\.com|poe\.game\.daum\.net)\/trade\/search\/((?:[a-zA-Z]|%[A-Z0-9]{2})+?)\/([a-zA-Z0-9]+?)(?:\/|\/live|\/live\/)?$/; +export const poeTradeUrl = /\/([a-zA-Z0-9]+)\/search\/(?:poe2\/)?([a-zA-Z0-9%]+)\/([a-zA-Z0-9]+)/; diff --git a/app/shared/resources/RegExes/RegExes.test.js b/app/shared/resources/RegExes/RegExes.test.js new file mode 100644 index 00000000..f5c350fa --- /dev/null +++ b/app/shared/resources/RegExes/RegExes.test.js @@ -0,0 +1,39 @@ +import { poeTradeUrl } from "./RegExes"; + +describe("poeTradeUrl", () => { + const expectedMatch =["trade", "Standard", "NK6Ec5"]; + + const urls = [ + "https://www.pathofexile.com/trade/search/Standard/NK6Ec5/live/", + "https://www.pathofexile.com/trade/search/Standard/NK6Ec5/live", + "https://www.pathofexile.com/trade/search/Standard/NK6Ec5/", + "https://www.pathofexile.com/trade/search/Standard/NK6Ec5", + ]; + + it("returns the correct league and id match", () => { + urls.forEach(url => { + const [, game, league, id] = url.match(poeTradeUrl); + expect([game, league, id]).toEqual(expectedMatch); + }); + }); + + describe("when league has a space", () => { + const url = "https://www.pathofexile.com/trade/search/Hardcore%20Blight/NK6Ec5"; + const expectedMatch = ["trade", "Hardcore%20Blight", "NK6Ec5"]; + + it("returns the correct league and id match", () => { + const [, game, league, id] = url.match(poeTradeUrl); + expect([game, league, id]).toEqual(expectedMatch); + }); + }); + + describe("poe2", () => { + const url = "https://www.pathofexile.com/trade2/search/poe2/Standard/NK6Ec5"; + const expectedMatch = ["trade2", "Standard", "NK6Ec5"]; + + it("returns the correct league and id match", () => { + const [, game, league, id] = url.match(poeTradeUrl); + expect([game, league, id]).toEqual(expectedMatch); + }); + }); +});