Skip to content

Commit

Permalink
Add support for poe 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thisismydesign committed Jan 4, 2025
1 parent f3a8062 commit d7f0c9f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/main/get-websocket-uri/get-websocket-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 11 in app/main/get-websocket-uri/get-websocket-uri.js

View workflow job for this annotation

GitHub Actions / lint

Unnecessary 'else' after 'return'
return `${baseUrls.poe2WsUri}/${league}/${id}`;
}
};

export default getWebSocketUri;
1 change: 1 addition & 0 deletions app/shared/resources/BaseUrls/BaseUrls.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 1 addition & 2 deletions app/shared/resources/RegExes/RegExes.js
Original file line number Diff line number Diff line change
@@ -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]+)/;
39 changes: 39 additions & 0 deletions app/shared/resources/RegExes/RegExes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { poeTradeUrl } from "./RegExes";

describe("poeTradeUrl", () => {
const expectedMatch =["trade", "Standard", "NK6Ec5"];

Check failure on line 4 in app/shared/resources/RegExes/RegExes.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `·`

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";

Check failure on line 21 in app/shared/resources/RegExes/RegExes.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·····`
const expectedMatch = ["trade", "Hardcore%20Blight", "NK6Ec5"];

Check failure on line 22 in app/shared/resources/RegExes/RegExes.test.js

View workflow job for this annotation

GitHub Actions / lint

'expectedMatch' is already declared in the upper scope

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";

Check failure on line 31 in app/shared/resources/RegExes/RegExes.test.js

View workflow job for this annotation

GitHub Actions / lint

Insert `⏎·····`
const expectedMatch = ["trade2", "Standard", "NK6Ec5"];

Check failure on line 32 in app/shared/resources/RegExes/RegExes.test.js

View workflow job for this annotation

GitHub Actions / lint

'expectedMatch' is already declared in the upper scope

it("returns the correct league and id match", () => {
const [, game, league, id] = url.match(poeTradeUrl);
expect([game, league, id]).toEqual(expectedMatch);
});
});
});

0 comments on commit d7f0c9f

Please sign in to comment.