From 802109cf31fc91111b7d6130a28d8be16ff38cd7 Mon Sep 17 00:00:00 2001 From: "Kevin C. Coram" Date: Sat, 4 Jan 2020 21:15:06 -0500 Subject: [PATCH] Better support for Quill's "favorite" request Quill doesn't send a `content` parameter along with the `like-of` data when performing a "favorite" request. --- entry.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/entry.go b/entry.go index 0db8772..d42c433 100644 --- a/entry.go +++ b/entry.go @@ -75,13 +75,23 @@ func parseRequestBody(r *http.Request) (string, error) { return string(bodyBytes), nil } +func validEntry(values map[string][]string) bool { + if _, ok := values["content"]; ok { + return true + } else if _, ok := values["like-of"]; ok { + return true + } + return false; +} + func createEntryFromValueMap(values map[string][]string) (*Entry, error) { if h, ok := values["h"]; ok && (len(h) != 1 || h[0] != "entry") { return nil, errors.New("only entry type is supported so far") } - if _, ok := values["content"]; ok { - entry := &Entry{ - content: values["content"][0], + if validEntry(values) { + entry := &Entry{} + if content, ok := values["content"]; ok { + entry.content = content[0] } if name, ok := values["name"]; ok { entry.title = name[0]