Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: trim query strings of lichess game URL #302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

star0202
Copy link

This PR trims the query strings of the lichess game URL so that PGN URLs can also be imported instead of regular URLs.
image
(General URL: blue square, PGN URL: red square)

@franciscoBSalgueiro
Copy link
Owner

It still doesn't work with those links because the gameID is not in the 4th position

@star0202
Copy link
Author

Modified to retrieve the last path of URL

@franciscoBSalgueiro
Copy link
Owner

The link can also have /white or /black at the end depending on the orientation. The best solution is probably with some regex.

@@ -119,7 +119,7 @@ export default function ImportModal({
if (link.includes("chess.com")) {
pgn = await getChesscomGame(link);
} else if (link.includes("lichess")) {
const gameId = link.split("/")[3];
const gameId = link.split("?")[0].split("/").pop() || "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a cleaner way to do this:

Suggested change
const gameId = link.split("?")[0].split("/").pop() || "";
const excludedPathParts = ['game', 'export', 'white', 'black'];
const gameId = new URL(link).pathname.split('/').find(x => x && !excludedPathParts.includes(x))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants