lib/model: Make /browse endpoint return sane objects (#7306)
This commit is contained in:
@@ -5,6 +5,7 @@ package protocol
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
@@ -394,3 +395,20 @@ func VectorHash(v Vector) []byte {
|
||||
}
|
||||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
func (x *FileInfoType) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(x.String())
|
||||
}
|
||||
|
||||
func (x *FileInfoType) UnmarshalJSON(data []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
n, ok := FileInfoType_value[s]
|
||||
if !ok {
|
||||
return errors.New("invalid value: " + s)
|
||||
}
|
||||
*x = FileInfoType(n)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user