KamWithK / AnkiconnectAndroid

Unofficial Ankiconnect for Android (i.e. for Yomichan)
GNU General Public License v3.0
98 stars 14 forks source link

Notes Info API isn't implemented causing MalformedJsonException when updating card image through mokuro files #50

Open precondition opened 6 months ago

precondition commented 6 months ago

When using the HTML files provided by Mokuro (not to be confused with the separate Mokuro Reader app) and enabling Anki integration in the advanced settings, I can successfully create new cards by pressing the green button in the Yomibaba/Yomitan pop-up but I can't add a picture to the card.

Screenshot of the advanced settings ![image](https://github.com/KamWithK/AnkiconnectAndroid/assets/57645186/39def33c-f9b0-4446-9fe1-1aa71fc10a60)

Looking at the dev console of the Kiwi Browser mobile app that I use, I can see the following stack trace when I press "Complete":

Uncaught (in promise)
com.google.gson.stream.MalformedJsonException:
Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 14 path $com.google.gson.stream.MalformedJsonException:
Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 14 path $
    at
com.google.gson.JsonParser.parseReader(JsonParser.java:66)
    at
com.google.gson.JsonParser.parseString(JsonParser.java:47)
    at
com.kamwithk.ankiconnectandroid.routing.AnkiAPIRouting.findRouteHandleError(AnkiAPIRouting.java:101)
    at
com.kamwithk.ankiconnectandroid.routing.APIHandler.chooseAPI(APIHandler.java:33)
    at
com.kamwithk.ankiconnectandroid.routing.RouteHandler.get(RouteHandler.java:70)
    at
fi.iki.elonen.router.RouterNanoHTTPD$DefaultStreamHandler.post(RouterNanoHTTPD.java:100)
    at
fi.iki.elonen.router.RouterNanoHTTPD$UriResource.process(RouterNanoHTTPD.java:386)
    at
fi.iki.elonen.router.RouterNanoHTTPD$UriRouter.process(RouterNanoHTTPD.java:596)
    at
fi.iki.elonen.router.RouterNanoHTTPD$UriRouter.process(RouterNanoHTTPD.java:596)
    at
[...]

    at java.lang.Thread.run(Thread.java:764)
Caused by:
com.google.gson.stream.MalfromedJsonException:
Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 14 path $
    at
com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1597)
    at
com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1404)
    at
com.google.gson.stream.JsonReader.doPeek(JsonReader.java:542)
    at
[...]

(I didn't find a way to copy the contents of the error from the Kiwi browser console so this was transcribed by hand on the basis of the screenshots in the spoiler)

Screenshots of error ![image](https://github.com/KamWithK/AnkiconnectAndroid/assets/57645186/6fd14e33-661f-4d1b-bd37-d2bf0cd56005) ![image](https://github.com/KamWithK/AnkiconnectAndroid/assets/57645186/252d9561-2ee3-4f0b-9346-7ec1d832e4ef)

I made sure to open AnkiDroid, start the Ankiconnect (v1.12) service and added https://mokuro.moe to the CORS host in the settings. I also disabled battery optimizations on the Ankiconnect app and the Kiwi Browser app.

I tested doing the exact same steps on desktop (open the same web page, highlight the same word, create the card, add an image via mokuro) and it worked fine so it is not as if the mokuro file is serving bad JSON data that Ankiconnect can't do anything about, since it seems like the desktop version of Ankiconnect has no issue with the commands received from mokuro.

Twinov commented 6 months ago

You should go to the Network tab in the browser dev tools and click on the request, then look at the json and make sure it's correctly formatted or post it here.

precondition commented 6 months ago

I'm seeing this payload in the POST request:

{
action: "notesInfo", 
version: 6, 
params: {
notes: [<ID obtained from response of previous `findNotes` query>]}
}

Judging from the existence of #46, I'm guessing that Ankiconnect does not support the notesInfo action and this might be the source of my issue?

Twinov commented 6 months ago

Yeah that's correct, notesInfo isn't implemented yet.