summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/post.go5
-rw-r--r--system/db/content.go5
-rw-r--r--system/external/server.go48
3 files changed, 57 insertions, 1 deletions
diff --git a/content/post.go b/content/post.go
index dcdfeff..eb46de7 100644
--- a/content/post.go
+++ b/content/post.go
@@ -88,3 +88,8 @@ func (p *Post) SetSlug(slug string) { p.Slug = slug }
// Editor partially implements editor.Editable
func (p *Post) Editor() *editor.Editor { return &p.editor }
+
+// Accepts accepts or recjects external requests to submit Review submissions
+func (p *Post) Accepts() bool {
+ return false
+}
diff --git a/system/db/content.go b/system/db/content.go
index 9ab1f89..c50706d 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -107,7 +107,10 @@ func insert(ns string, data url.Values) (int, error) {
return 0, err
}
- go SortContent(ns)
+ // since sorting can be expensive, limit sort to non-externally created posts
+ if !strings.Contains(ns, "_external") {
+ go SortContent(ns)
+ }
return effectedID, nil
}
diff --git a/system/external/server.go b/system/external/server.go
new file mode 100644
index 0000000..1efb23f
--- /dev/null
+++ b/system/external/server.go
@@ -0,0 +1,48 @@
+package external
+
+import (
+ "net/http"
+
+ "github.com/bosssauce/ponzu/content"
+ "github.com/bosssauce/ponzu/system/db"
+)
+
+// Externalable accepts or rejects external POST requests to /external/posts?type=Review
+type Externalable interface {
+ Accept() bool
+}
+
+func init() {
+ http.HandleFunc("/api/external/posts", externalPostsHandler)
+}
+
+func externalPostsHandler(res http.ResponseWriter, req *http.Request) {
+ if req.Method != http.MethodPost {
+ res.WriteHeader(http.StatusMethodNotAllowed)
+ return
+ }
+
+ t := req.URL.Query().Get("type")
+ if t == "" {
+ res.WriteHeader(http.StatusBadRequest)
+ return
+ }
+
+ p, found := content.Types[t]
+ if !found {
+ res.WriteHeader(http.StatusNotFound)
+ return
+ }
+
+ post := p()
+
+ ext, ok := post.(Externalable)
+ if !ok {
+ res.WriteHeader(http.StatusNotFound)
+ return
+ }
+
+ if ext.Accept() {
+ db.SetContent(t+"_external"+":-1", req.Form)
+ }
+}