From 9f28b570d569b8fe818fcf5285eea52bdf82e28b Mon Sep 17 00:00:00 2001 From: ThaUnknown <6506529+ThaUnknown@users.noreply.github.com> Date: Mon, 21 Jul 2025 20:53:25 +0200 Subject: [PATCH] fix: support MAL on android --- package.json | 2 +- src/lib/modules/auth/mal.ts | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 827a11c..4a68f87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "6.4.74", + "version": "6.4.75", "license": "BUSL-1.1", "private": true, "packageManager": "pnpm@9.15.5", diff --git a/src/lib/modules/auth/mal.ts b/src/lib/modules/auth/mal.ts index 97d78ad..f867ef5 100644 --- a/src/lib/modules/auth/mal.ts +++ b/src/lib/modules/auth/mal.ts @@ -6,6 +6,7 @@ import { toast } from 'svelte-sonner' import { client, type Media } from '../anilist' import { mappings, mappingsByMalId } from '../anizip' import native from '../native' +import { SUPPORTS } from '../settings' import type { Entry, FullMediaList, UserFrag } from '../anilist/queries' import type { ResultOf, VariablesOf } from 'gql.tada' @@ -153,8 +154,7 @@ export default new class MALSync { }) } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - async _request (url: string | URL, method: string, body?: any): Promise { + async _request (url: string | URL, method: string, body?: URLSearchParams): Promise { const auth = get(this.auth) try { if (auth) { @@ -172,6 +172,15 @@ export default new class MALSync { if (auth) { headers.Authorization = `Bearer ${auth.access_token}` } + // if android append body to the URL + if (SUPPORTS.isAndroid && body) { + if (url instanceof URL) { + url.search = body.toString() + } else { + url += '?' + body.toString() + } + body = undefined + } const res = await fetch(url, { method, @@ -208,8 +217,9 @@ export default new class MALSync { return await this._request(url, 'GET') } - async _post (url: string, body?: Record | URLSearchParams): Promise { - return await this._request(url, 'POST', body) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + async _post (url: string, body?: Record): Promise { + return await this._request(url, 'POST', new URLSearchParams(body)) } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -252,13 +262,13 @@ export default new class MALSync { const data = await this._post( ENDPOINTS.API_OAUTH, - new URLSearchParams({ + { client_id: clientID, grant_type: 'authorization_code', code, code_verifier: challenge, redirect_uri: redirect - }) + } ) if ('access_token' in data) {