mirror of https://github.com/perkeep/perkeep.git
search: add LimitReader around JSON decoding. add some TODOs
Change-Id: I98069ef0aeb8c96cdc997c138222e0344981ead8
This commit is contained in:
parent
4d620d2c60
commit
4c70e14310
|
@ -20,6 +20,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -33,13 +34,7 @@ import (
|
|||
|
||||
type SortType int
|
||||
|
||||
// TODO: extend/merge/delete this type? probably dups in this package.
|
||||
type BlobMeta struct {
|
||||
Ref blob.Ref
|
||||
Size int
|
||||
MIMEType string
|
||||
}
|
||||
|
||||
// TODO: add MarshalJSON and UnmarshalJSON to SortType
|
||||
const (
|
||||
UnspecifiedSort SortType = iota
|
||||
LastModifiedDesc
|
||||
|
@ -48,6 +43,13 @@ const (
|
|||
CreatedAsc
|
||||
)
|
||||
|
||||
// TODO: extend/merge/delete this type? probably dups in this package.
|
||||
type BlobMeta struct {
|
||||
Ref blob.Ref
|
||||
Size int
|
||||
MIMEType string
|
||||
}
|
||||
|
||||
type SearchQuery struct {
|
||||
Constraint *Constraint `json:"constraint"`
|
||||
Limit int `json:"limit"` // optional. default is automatic.
|
||||
|
@ -55,7 +57,7 @@ type SearchQuery struct {
|
|||
}
|
||||
|
||||
func (q *SearchQuery) fromHTTP(req *http.Request) error {
|
||||
dec := json.NewDecoder(req.Body)
|
||||
dec := json.NewDecoder(io.LimitReader(req.Body, 1<<20))
|
||||
if err := dec.Decode(q); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue