Strubbl / wallabago

Go wrapper for the Wallabag API
GNU General Public License v3.0
11 stars 5 forks source link

annotations crash GetEntries #11

Closed anarcat closed 6 years ago

anarcat commented 6 years ago

I get this running wallabako now:

2018/03/20 16:53:30 failed to list entries in wallabag: json: cannot unmarshal string into Go struct field Range.startOffset of type int

The problem is that Wallabag 2.3.2 sends this in the annotation struct:

        "annotations": [
          {
            "user": "anarcat",
            "annotator_schema_version": "v1.0",
            "id": 7,
            "text": "wtf",
            "created_at": "2018-03-19T10:02:45-0400",
            "updated_at": "2018-03-19T10:02:45-0400",
            "quote": "“We can now create machines that can change what people think and what people do, and the machines can do that autonomously.”",
            "ranges": [
              {
                "start": "/div[2]/div[1]/p[10]",
                "startOffset": "112",
                "end": "/div[2]/div[1]/p[10]",
                "endOffset": "238"
              }
            ]
[...]

notice how start/end aren't actual integers anymore? not sure how to deal with such insanity, but I've done this to workaround the problem for now:

diff --git a/annotations.go b/annotations.go
index 76c94b0..2962f83 100644
--- a/annotations.go
+++ b/annotations.go
@@ -27,9 +27,9 @@ type Annotation struct {
 // Range represents the text borders of an annotation
 type Range struct {
    End         string `json:"end"`
-   EndOffset   int    `json:"endOffset"`
+   EndOffset   string `json:"endOffset"`
    Start       string `json:"start"`
-   StartOffset int    `json:"startOffset"`
+   StartOffset string `json:"startOffset"`
 }

 // GetAnnotations queries the API for all annotations of an article according to /api/annotations/ID

quick and dirty, but it works, probably because I don't use those anywhere...

Strubbl commented 6 years ago

I already saw this insanity, too. Which version of wallabago are you using? The latest code looks like this: https://github.com/Strubbl/wallabago/blob/master/annotations.go#L26

anarcat commented 6 years ago

nevermind, this seems to have been fixed in ad7fb12000c216018b3bb4d1cfebad87a61f4433

anarcat commented 6 years ago

i just gotta send you an extra kudos here for fixing a bug before I even have time to realize it exists at all. :) congrats!