From 1b44035e4501f21cf48207aa61067061456dd680 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 18 May 2021 17:11:16 +0100 Subject: [PATCH] filefabric: fix listing after change of from field from "int" to int. --- backend/filefabric/api/types.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/filefabric/api/types.go b/backend/filefabric/api/types.go index e3b80e6c0..9ba415326 100644 --- a/backend/filefabric/api/types.go +++ b/backend/filefabric/api/types.go @@ -5,6 +5,7 @@ package api import ( "bytes" + "encoding/json" "fmt" "reflect" "strings" @@ -51,6 +52,23 @@ func (t Time) String() string { return time.Time(t).UTC().Format(timeFormatParameters) } +// Int represents an integer which can be represented in JSON as a +// quoted integer or an integer. +type Int int + +// MarshalJSON turns a Int into JSON +func (i *Int) MarshalJSON() (out []byte, err error) { + return json.Marshal((*int)(i)) +} + +// UnmarshalJSON turns JSON into a Int +func (i *Int) UnmarshalJSON(data []byte) error { + if len(data) >= 2 && data[0] == '"' && data[len(data)-1] == '"' { + data = data[1 : len(data)-1] + } + return json.Unmarshal(data, (*int)(i)) +} + // Status return returned in all status responses type Status struct { Code string `json:"status"` @@ -115,7 +133,7 @@ type GetFolderContentsResponse struct { Total int `json:"total,string"` Items []Item `json:"filelist"` Folder Item `json:"folder"` - From int `json:"from,string"` + From Int `json:"from"` //Count int `json:"count"` Pid string `json:"pid"` RefreshResult Status `json:"refreshresult"`