From 8f286e1fbe4d645c24d6760b1932d5812838b2e1 Mon Sep 17 00:00:00 2001 From: jubiman Date: Mon, 9 Sep 2024 23:02:01 +0200 Subject: [PATCH 1/4] Fix line feed at the end of state returned from MAL and undefined symbol 'line' in linux's clipboard paste handler --- common/modules/settings.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/modules/settings.js b/common/modules/settings.js index 2c6caee..da82485 100644 --- a/common/modules/settings.js +++ b/common/modules/settings.js @@ -55,13 +55,13 @@ window.addEventListener('paste', ({ clipboardData }) => { clipboardData.items[0].getAsString(text => { if (text.includes("access_token=")) { // is an AniList token let token = text.split('access_token=')?.[1]?.split('&token_type')?.[0] - if (token) { + if (token) {state if (token.endsWith('/')) token = token.slice(0, -1) handleToken(token) } } else if (text.includes("code=") && text.includes("&state")) { // is a MyAnimeList authorization - let code = line.split('code=')[1].split('&state')[0] - let state = line.split('&state=')[1] + let code = text.split('code=')[1].split('&state')[0] + let state = text.split('&state=')[1] if (code && state) { if (code.endsWith('/')) code = code.slice(0, -1) if (state.endsWith('/')) state = state.slice(0, -1) @@ -98,6 +98,8 @@ async function handleMalToken (code, state) { debug(`Failed to get the state and code from MyAnimeList.`) return } + // remove linefeed characters from the state + state = state.replace(/(\r\n|\n|\r)/gm, '') const response = await fetch('https://myanimelist.net/v1/oauth2/token', { method: 'POST', headers: { From 0277b171e0f27e1effd9dafebabb10f3c53aca63 Mon Sep 17 00:00:00 2001 From: jubiman Date: Mon, 9 Sep 2024 23:03:42 +0200 Subject: [PATCH 2/4] fix trailing 'state' on line 58 I don't know how it got there --- common/modules/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/modules/settings.js b/common/modules/settings.js index da82485..8ac8145 100644 --- a/common/modules/settings.js +++ b/common/modules/settings.js @@ -55,7 +55,7 @@ window.addEventListener('paste', ({ clipboardData }) => { clipboardData.items[0].getAsString(text => { if (text.includes("access_token=")) { // is an AniList token let token = text.split('access_token=')?.[1]?.split('&token_type')?.[0] - if (token) {state + if (token) { if (token.endsWith('/')) token = token.slice(0, -1) handleToken(token) } From f165ba84691dad0614c9caf6f5d59a7e0ec022ab Mon Sep 17 00:00:00 2001 From: jubiman Date: Mon, 9 Sep 2024 23:05:40 +0200 Subject: [PATCH 3/4] Replace the line that removes the linefeed to somewhere that makes more sense --- common/modules/settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/modules/settings.js b/common/modules/settings.js index 8ac8145..70bb3e1 100644 --- a/common/modules/settings.js +++ b/common/modules/settings.js @@ -66,6 +66,8 @@ window.addEventListener('paste', ({ clipboardData }) => { if (code.endsWith('/')) code = code.slice(0, -1) if (state.endsWith('/')) state = state.slice(0, -1) if (state.includes('%')) state = decodeURIComponent(state) + // remove linefeed characters from the state + state = state.replace(/(\r\n|\n|\r)/gm, '') handleMalToken(code, state) } } @@ -98,8 +100,6 @@ async function handleMalToken (code, state) { debug(`Failed to get the state and code from MyAnimeList.`) return } - // remove linefeed characters from the state - state = state.replace(/(\r\n|\n|\r)/gm, '') const response = await fetch('https://myanimelist.net/v1/oauth2/token', { method: 'POST', headers: { From 1ff02a60c45e7074dc5014ef3da0cf6ff52ae9e0 Mon Sep 17 00:00:00 2001 From: Jason Watanabe Date: Mon, 9 Sep 2024 16:15:16 -0700 Subject: [PATCH 4/4] fix: code linefeed --- common/modules/settings.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/modules/settings.js b/common/modules/settings.js index 70bb3e1..e55a986 100644 --- a/common/modules/settings.js +++ b/common/modules/settings.js @@ -4,7 +4,7 @@ import IPC from '@/modules/ipc.js' import { toast } from 'svelte-sonner' import Debug from 'debug' -const debug = Debug('ui:anilist') +const debug = Debug('ui:settings') export let profiles = writable(JSON.parse(localStorage.getItem('profiles')) || []) /** @type {{viewer: import('./al').Query<{Viewer: import('./al').Viewer}>, token: string} | null} */ @@ -67,6 +67,7 @@ window.addEventListener('paste', ({ clipboardData }) => { if (state.endsWith('/')) state = state.slice(0, -1) if (state.includes('%')) state = decodeURIComponent(state) // remove linefeed characters from the state + code = code.replace(/(\r\n|\n|\r)/gm, '') state = state.replace(/(\r\n|\n|\r)/gm, '') handleMalToken(code, state) }