summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/ponzu/ponzu.json4
-rw-r--r--system/api/external.go39
2 files changed, 41 insertions, 2 deletions
diff --git a/cmd/ponzu/ponzu.json b/cmd/ponzu/ponzu.json
index af54315..c9946cd 100644
--- a/cmd/ponzu/ponzu.json
+++ b/cmd/ponzu/ponzu.json
@@ -1,3 +1,3 @@
{
- "version": "0.8.1"
-} \ No newline at end of file
+ "version": "0.8.2"
+}
diff --git a/system/api/external.go b/system/api/external.go
index 168575a..78f6578 100644
--- a/system/api/external.go
+++ b/system/api/external.go
@@ -2,6 +2,7 @@ package api
import (
"context"
+ "encoding/json"
"fmt"
"log"
"net/http"
@@ -162,6 +163,7 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
id, err := db.SetContent(t+spec+":-1", req.PostForm)
if err != nil {
log.Println("[External] error calling SetContent:", err)
+ res.WriteHeader(http.StatusInternalServerError)
return
}
@@ -175,4 +177,41 @@ func externalContentHandler(res http.ResponseWriter, req *http.Request) {
return
}
+ // create JSON response to send data back to client
+ var data map[string]interface{}
+ if spec != "" {
+ spec = strings.TrimPrefix(spec, "__")
+ data = map[string]interface{}{
+ "status": spec,
+ "type": t,
+ }
+ } else {
+ spec = "public"
+ data = map[string]interface{}{
+ "id": id,
+ "status": spec,
+ "type": t,
+ }
+ }
+
+ resp := map[string]interface{}{
+ "data": []map[string]interface{}{
+ data,
+ },
+ }
+
+ j, err := json.Marshal(resp)
+ if err != nil {
+ log.Println("[External] error marshalling response to JSON:", err)
+ res.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+
+ res.Header().Set("Content-Type", "application/json")
+ _, err = res.Write(j)
+ if err != nil {
+ log.Println("[External] error writing response:", err)
+ return
+ }
+
}