From e8945192276de251022bd4732178cd0143f41f78 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 01:53:15 -0700 Subject: code reorganizing --- system/api/handlers.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system/api') diff --git a/system/api/handlers.go b/system/api/handlers.go index 2ec82bb..a56a667 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -3,7 +3,6 @@ package api import ( "bytes" "encoding/json" - "fmt" "log" "net/http" "strconv" @@ -69,8 +68,6 @@ func postsHandler(res http.ResponseWriter, req *http.Request) { all = append(all, post) } - fmt.Println(len(posts)) - var start, end int switch count { case -1: @@ -203,6 +200,7 @@ func SendJSON(res http.ResponseWriter, j map[string]interface{}) { data, err = json.Marshal(j) if err != nil { + log.Println(err) data, _ = json.Marshal(map[string]interface{}{ "status": "fail", "message": err.Error(), -- cgit v1.2.3 From 699a1a5076d683d0e59b2edbe9e05b6886c0bc88 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 12:30:48 -0700 Subject: debugging and code reorg --- system/api/external.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ system/api/server.go | 2 ++ 2 files changed, 48 insertions(+) create mode 100644 system/api/external.go (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go new file mode 100644 index 0000000..19dc1d0 --- /dev/null +++ b/system/api/external.go @@ -0,0 +1,46 @@ +package api + +import ( + "log" + "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 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 { + log.Println("Attempt to submit content", t, "by", req.RemoteAddr) + res.WriteHeader(http.StatusNotFound) + return + } + + post := p() + + ext, ok := post.(Externalable) + if !ok { + res.WriteHeader(http.StatusInternalServerError) + return + } + + if ext.Accept() { + db.SetContent(t+"_external"+":-1", req.Form) + } +} diff --git a/system/api/server.go b/system/api/server.go index da73382..816bc21 100644 --- a/system/api/server.go +++ b/system/api/server.go @@ -9,4 +9,6 @@ func Run() { http.HandleFunc("/api/posts", CORS(postsHandler)) http.HandleFunc("/api/post", CORS(postHandler)) + + http.HandleFunc("/api/external/posts", CORS(externalPostsHandler)) } -- cgit v1.2.3 From db0c05fa1f0b270fc00c9bcb190a03a5389df061 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 12:35:57 -0700 Subject: debugging --- system/api/external.go | 1 + 1 file changed, 1 insertion(+) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 19dc1d0..111204e 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -14,6 +14,7 @@ type Externalable interface { } func externalPostsHandler(res http.ResponseWriter, req *http.Request) { + log.Println("External request") if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) return -- cgit v1.2.3 From c9dc7199aeedeff6bd9a923d2ebd59147abd3a94 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 12:41:48 -0700 Subject: debugging --- system/api/external.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 111204e..c437d33 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -26,6 +26,8 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { return } + log.Println("type:", t) + log.Println("of:", content.Types) p, found := content.Types[t] if !found { log.Println("Attempt to submit content", t, "by", req.RemoteAddr) -- cgit v1.2.3 From 54a245a5c4db84db527ae19af6f1f724a16d35d2 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 12:50:38 -0700 Subject: debugging --- system/api/external.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index c437d33..b34da93 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -44,6 +44,11 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { } if ext.Accept() { - db.SetContent(t+"_external"+":-1", req.Form) + _, err := db.SetContent(t+"_external"+":-1", req.Form) + if err != nil { + log.Println("[External]", err) + res.WriteHeader(http.StatusInternalServerError) + return + } } } -- cgit v1.2.3 From dfe66cc52d9088dbf56ff38c50d791da2eefed78 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 13:01:22 -0700 Subject: fixing Externalable interface implementation for Post type --- system/api/external.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index b34da93..abb52c9 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -10,7 +10,7 @@ import ( // Externalable accepts or rejects external POST requests to /external/posts?type=Review type Externalable interface { - Accept() bool + Accepts() bool } func externalPostsHandler(res http.ResponseWriter, req *http.Request) { @@ -43,7 +43,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { return } - if ext.Accept() { + if ext.Accepts() { _, err := db.SetContent(t+"_external"+":-1", req.Form) if err != nil { log.Println("[External]", err) -- cgit v1.2.3 From 4d0201d360620cf3d3af4eec2661b1ae6c914e1d Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Wed, 26 Oct 2016 13:31:39 -0700 Subject: forgot to parse form data on external post handler --- system/api/external.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index abb52c9..e6e75f0 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -14,23 +14,27 @@ type Externalable interface { } func externalPostsHandler(res http.ResponseWriter, req *http.Request) { - log.Println("External request") if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) return } + err := req.ParseMultipartForm(1024 * 1024 * 4) // maxMemory 4MB + if err != nil { + log.Println("[External]", err) + res.WriteHeader(http.StatusInternalServerError) + return + } + t := req.URL.Query().Get("type") if t == "" { res.WriteHeader(http.StatusBadRequest) return } - log.Println("type:", t) - log.Println("of:", content.Types) p, found := content.Types[t] if !found { - log.Println("Attempt to submit content", t, "by", req.RemoteAddr) + log.Println("[External] Attempt to submit content", t, "by", req.RemoteAddr) res.WriteHeader(http.StatusNotFound) return } @@ -39,6 +43,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { ext, ok := post.(Externalable) if !ok { + log.Println("[External]", err) res.WriteHeader(http.StatusInternalServerError) return } -- cgit v1.2.3 From 8ff77bc0aa766dcd33fd4458557444defa76d87b Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Fri, 28 Oct 2016 13:05:23 -0700 Subject: adding initial components for anayltics tracking API requests --- system/api/analytics/analytics.go | 97 +++++++++++++++++++++++++++++++++++++++ system/api/external.go | 11 +++-- system/api/handlers.go | 13 ++++-- 3 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 system/api/analytics/analytics.go (limited to 'system/api') diff --git a/system/api/analytics/analytics.go b/system/api/analytics/analytics.go new file mode 100644 index 0000000..c30ce26 --- /dev/null +++ b/system/api/analytics/analytics.go @@ -0,0 +1,97 @@ +// Package analytics provides the methods to run an analytics reporting system +// for API requests which may be useful to users for measuring access and +// possibly identifying bad actors abusing requests. +package analytics + +import ( + "log" + "net/http" + "strings" + "time" + + "github.com/boltdb/bolt" +) + +type apiRequest struct { + URL string `json:"url"` + Method string `json:"http_method"` + RemoteAddr string `json:"ip_address"` + Timestamp int64 `json:"timestamp"` + External bool `json:"external"` +} + +var ( + store *bolt.DB + recordChan chan apiRequest +) + +// Record queues an apiRequest for metrics +func Record(req *http.Request) { + external := strings.Contains(req.URL.Path, "/external/") + + r := apiRequest{ + URL: req.URL.String(), + Method: req.Method, + RemoteAddr: req.RemoteAddr, + Timestamp: time.Now().Unix() * 1000, + External: external, + } + + // put r on buffered recordChan to take advantage of batch insertion in DB + recordChan <- r + +} + +// Close exports the abillity to close our db file. Should be called with defer +// after call to Init() from the same place. +func Close() { + err := store.Close() + if err != nil { + log.Println(err) + } +} + +// Init creates a db connection, should run an initial prune of old data, and +// sets up the queue/batching channel +func Init() { + store, err := bolt.Open("analytics.db", 0666, nil) + if err != nil { + log.Fatalln(err) + } + + recordChan = make(chan apiRequest, 1024*128) + + go serve() + + err = store.Update(func(tx *bolt.Tx) error { + + return nil + }) +} + +func serve() { + // make timer to notify select to batch request insert from recordChan + // interval: 1 minute + apiRequestTimer := time.NewTicker(time.Minute * 1) + + // make timer to notify select to remove old analytics + // interval: 2 weeks + // TODO: enable analytics backup service to cloud + pruneDBTimer := time.NewTicker(time.Hour * 24 * 14) + + for { + select { + case <-apiRequestTimer.C: + var reqs []apiRequest + batchSize := len(recordChan) + + for i := 0; i < batchSize; i++ { + reqs = append(reqs, <-recordChan) + } + + case <-pruneDBTimer.C: + + default: + } + } +} diff --git a/system/api/external.go b/system/api/external.go index e6e75f0..0da7eac 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -10,6 +10,7 @@ import ( // Externalable accepts or rejects external POST requests to /external/posts?type=Review type Externalable interface { + // Accepts determines whether a type will allow external submissions Accepts() bool } @@ -21,7 +22,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { err := req.ParseMultipartForm(1024 * 1024 * 4) // maxMemory 4MB if err != nil { - log.Println("[External]", err) + log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) return } @@ -34,7 +35,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { p, found := content.Types[t] if !found { - log.Println("[External] Attempt to submit content", t, "by", req.RemoteAddr) + log.Println("[External] attempt to submit unknown type:", t, "from:", req.RemoteAddr) res.WriteHeader(http.StatusNotFound) return } @@ -43,15 +44,15 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { ext, ok := post.(Externalable) if !ok { - log.Println("[External]", err) - res.WriteHeader(http.StatusInternalServerError) + log.Println("[External] rejected non-externalable type:", t, "from:", req.RemoteAddr) + res.WriteHeader(http.StatusBadRequest) return } if ext.Accepts() { _, err := db.SetContent(t+"_external"+":-1", req.Form) if err != nil { - log.Println("[External]", err) + log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) return } diff --git a/system/api/handlers.go b/system/api/handlers.go index a56a667..8356683 100644 --- a/system/api/handlers.go +++ b/system/api/handlers.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/bosssauce/ponzu/content" + "github.com/bosssauce/ponzu/system/api/analytics" "github.com/bosssauce/ponzu/system/db" ) @@ -210,9 +211,6 @@ func SendJSON(res http.ResponseWriter, j map[string]interface{}) { sendData(res, data, 200) } -// ResponseFunc ... -type ResponseFunc func(http.ResponseWriter, *http.Request) - // CORS wraps a HandleFunc to response to OPTIONS requests properly func CORS(next http.HandlerFunc) http.HandlerFunc { return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { @@ -224,3 +222,12 @@ func CORS(next http.HandlerFunc) http.HandlerFunc { next.ServeHTTP(res, req) }) } + +// Record wraps a HandleFunc to record API requests for analytical purposes +func Record(next http.HandlerFunc) http.HandlerFunc { + return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + go analytics.Record(req) + + next.ServeHTTP(res, req) + }) +} -- cgit v1.2.3 From c716fb39d8ae2e3d3d767c1419997d2a529329a7 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Fri, 28 Oct 2016 17:06:04 -0700 Subject: code reorg and debugging bolt issues --- system/api/analytics/analytics.go | 97 ----------------------------------- system/api/analytics/init.go | 103 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 97 deletions(-) delete mode 100644 system/api/analytics/analytics.go create mode 100644 system/api/analytics/init.go (limited to 'system/api') diff --git a/system/api/analytics/analytics.go b/system/api/analytics/analytics.go deleted file mode 100644 index c30ce26..0000000 --- a/system/api/analytics/analytics.go +++ /dev/null @@ -1,97 +0,0 @@ -// Package analytics provides the methods to run an analytics reporting system -// for API requests which may be useful to users for measuring access and -// possibly identifying bad actors abusing requests. -package analytics - -import ( - "log" - "net/http" - "strings" - "time" - - "github.com/boltdb/bolt" -) - -type apiRequest struct { - URL string `json:"url"` - Method string `json:"http_method"` - RemoteAddr string `json:"ip_address"` - Timestamp int64 `json:"timestamp"` - External bool `json:"external"` -} - -var ( - store *bolt.DB - recordChan chan apiRequest -) - -// Record queues an apiRequest for metrics -func Record(req *http.Request) { - external := strings.Contains(req.URL.Path, "/external/") - - r := apiRequest{ - URL: req.URL.String(), - Method: req.Method, - RemoteAddr: req.RemoteAddr, - Timestamp: time.Now().Unix() * 1000, - External: external, - } - - // put r on buffered recordChan to take advantage of batch insertion in DB - recordChan <- r - -} - -// Close exports the abillity to close our db file. Should be called with defer -// after call to Init() from the same place. -func Close() { - err := store.Close() - if err != nil { - log.Println(err) - } -} - -// Init creates a db connection, should run an initial prune of old data, and -// sets up the queue/batching channel -func Init() { - store, err := bolt.Open("analytics.db", 0666, nil) - if err != nil { - log.Fatalln(err) - } - - recordChan = make(chan apiRequest, 1024*128) - - go serve() - - err = store.Update(func(tx *bolt.Tx) error { - - return nil - }) -} - -func serve() { - // make timer to notify select to batch request insert from recordChan - // interval: 1 minute - apiRequestTimer := time.NewTicker(time.Minute * 1) - - // make timer to notify select to remove old analytics - // interval: 2 weeks - // TODO: enable analytics backup service to cloud - pruneDBTimer := time.NewTicker(time.Hour * 24 * 14) - - for { - select { - case <-apiRequestTimer.C: - var reqs []apiRequest - batchSize := len(recordChan) - - for i := 0; i < batchSize; i++ { - reqs = append(reqs, <-recordChan) - } - - case <-pruneDBTimer.C: - - default: - } - } -} diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go new file mode 100644 index 0000000..c04a7f2 --- /dev/null +++ b/system/api/analytics/init.go @@ -0,0 +1,103 @@ +// Package analytics provides the methods to run an analytics reporting system +// for API requests which may be useful to users for measuring access and +// possibly identifying bad actors abusing requests. +package analytics + +import ( + "fmt" + "log" + "net/http" + "strings" + "time" + + "github.com/boltdb/bolt" +) + +type apiRequest struct { + URL string `json:"url"` + Method string `json:"http_method"` + RemoteAddr string `json:"ip_address"` + Timestamp int64 `json:"timestamp"` + External bool `json:"external"` +} + +var ( + store *bolt.DB + recordChan chan apiRequest +) + +// Record queues an apiRequest for metrics +func Record(req *http.Request) { + external := strings.Contains(req.URL.Path, "/external/") + + r := apiRequest{ + URL: req.URL.String(), + Method: req.Method, + RemoteAddr: req.RemoteAddr, + Timestamp: time.Now().Unix() * 1000, + External: external, + } + + // put r on buffered recordChan to take advantage of batch insertion in DB + recordChan <- r + +} + +// Close exports the abillity to close our db file. Should be called with defer +// after call to Init() from the same place. +func Close() { + err := store.Close() + if err != nil { + log.Println(err) + } +} + +// Init creates a db connection, should run an initial prune of old data, and +// sets up the queue/batching channel +func Init() { + store, err := bolt.Open("analytics.db", 0666, nil) + if err != nil { + log.Fatalln(err) + } + + fmt.Println("analytics", store) + + recordChan = make(chan apiRequest, 1024*128) + + go serve() + + err = store.Update(func(tx *bolt.Tx) error { + + return nil + }) + if err != nil { + log.Fatalln(err) + } +} + +func serve() { + // make timer to notify select to batch request insert from recordChan + // interval: 1 minute + apiRequestTimer := time.NewTicker(time.Minute * 1) + + // make timer to notify select to remove old analytics + // interval: 2 weeks + // TODO: enable analytics backup service to cloud + pruneDBTimer := time.NewTicker(time.Hour * 24 * 14) + + for { + select { + case <-apiRequestTimer.C: + var reqs []apiRequest + batchSize := len(recordChan) + + for i := 0; i < batchSize; i++ { + reqs = append(reqs, <-recordChan) + } + + case <-pruneDBTimer.C: + + default: + } + } +} -- cgit v1.2.3 From b6eb040045fcfeb39dda4fcd440d2be184c8e715 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sat, 29 Oct 2016 01:33:33 -0700 Subject: adding db/analytics init back in after reverting for debug --- system/api/analytics/init.go | 6 ++---- system/api/external.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'system/api') diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go index c04a7f2..c351bed 100644 --- a/system/api/analytics/init.go +++ b/system/api/analytics/init.go @@ -4,7 +4,6 @@ package analytics import ( - "fmt" "log" "net/http" "strings" @@ -55,13 +54,12 @@ func Close() { // Init creates a db connection, should run an initial prune of old data, and // sets up the queue/batching channel func Init() { - store, err := bolt.Open("analytics.db", 0666, nil) + var err error + store, err = bolt.Open("analytics.db", 0666, nil) if err != nil { log.Fatalln(err) } - fmt.Println("analytics", store) - recordChan = make(chan apiRequest, 1024*128) go serve() diff --git a/system/api/external.go b/system/api/external.go index 0da7eac..a65618b 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -8,12 +8,21 @@ import ( "github.com/bosssauce/ponzu/system/db" ) -// Externalable accepts or rejects external POST requests to /external/posts?type=Review +// Externalable accepts or rejects external POST requests to endpoints such as: +// /external/posts?type=Review type Externalable interface { // Accepts determines whether a type will allow external submissions Accepts() bool } +// Mergeable allows external post content to be approved and published through +// the public-facing API +type Mergeable interface { + // Approve copies an external post to the internal collection and triggers + // a re-sort of its content type posts + Approve() error +} + func externalPostsHandler(res http.ResponseWriter, req *http.Request) { if req.Method != http.MethodPost { res.WriteHeader(http.StatusMethodNotAllowed) -- cgit v1.2.3 From b1212fa6f48da1d539a73e1bd5a0bf6894b97d7d Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sat, 29 Oct 2016 17:36:47 -0700 Subject: adding db procedures and updating handler for external submissions / pending content --- system/api/external.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index a65618b..f9f2538 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -59,7 +59,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { } if ext.Accepts() { - _, err := db.SetContent(t+"_external"+":-1", req.Form) + err := db.SetPendingContent(t+"_pending", req.Form) if err != nil { log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) -- cgit v1.2.3 From ed4c47babef56f18df0a5b393b0c0fe79e659105 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sat, 29 Oct 2016 17:52:56 -0700 Subject: adding db procedures and updating handler for external submissions / pending content --- system/api/external.go | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index f9f2538..1c69afb 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -1,10 +1,14 @@ package api import ( + "fmt" "log" "net/http" + "strings" + "time" "github.com/bosssauce/ponzu/content" + "github.com/bosssauce/ponzu/system/admin" "github.com/bosssauce/ponzu/system/db" ) @@ -59,7 +63,44 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { } if ext.Accepts() { - err := db.SetPendingContent(t+"_pending", req.Form) + ts := fmt.Sprintf("%d", time.Now().Unix()*1000) + req.PostForm.Set("timestamp", ts) + req.PostForm.Set("updated", ts) + req.PostForm.Set("id", ts) + + urlPaths, err := admin.storeFileUploads(req) + if err != nil { + log.Println(err) + res.WriteHeader(http.StatusInternalServerError) + return + } + + for name, urlPath := range urlPaths { + req.PostForm.Add(name, urlPath) + } + + // check for any multi-value fields (ex. checkbox fields) + // and correctly format for db storage. Essentially, we need + // fieldX.0: value1, fieldX.1: value2 => fieldX: []string{value1, value2} + var discardKeys []string + for k, v := range req.PostForm { + if strings.Contains(k, ".") { + key := strings.Split(k, ".")[0] + + if req.PostForm.Get(key) == "" { + req.PostForm.Set(key, v[0]) + discardKeys = append(discardKeys, k) + } else { + req.PostForm.Add(key, v[0]) + } + } + } + + for _, discardKey := range discardKeys { + req.PostForm.Del(discardKey) + } + + err = db.SetPendingContent(t+"_pending", req.PostForm) if err != nil { log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) -- cgit v1.2.3 From c930db63601095ce386413b3eb764b71ee71fe2c Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sat, 29 Oct 2016 17:56:46 -0700 Subject: renaming and moving File upload logic into own package --- system/api/external.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 1c69afb..52240d5 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -8,7 +8,7 @@ import ( "time" "github.com/bosssauce/ponzu/content" - "github.com/bosssauce/ponzu/system/admin" + "github.com/bosssauce/ponzu/system/admin/upload" "github.com/bosssauce/ponzu/system/db" ) @@ -68,7 +68,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { req.PostForm.Set("updated", ts) req.PostForm.Set("id", ts) - urlPaths, err := admin.storeFileUploads(req) + urlPaths, err := upload.StoreFiles(req) if err != nil { log.Println(err) res.WriteHeader(http.StatusInternalServerError) -- cgit v1.2.3 From 3ba9236ae25cdf4a2b80b7a1f860edbf2e749e39 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sun, 30 Oct 2016 21:42:51 -0700 Subject: slight refactor of pending content code & reimplementing where needed --- system/api/external.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 52240d5..6489c68 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -66,7 +66,6 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { ts := fmt.Sprintf("%d", time.Now().Unix()*1000) req.PostForm.Set("timestamp", ts) req.PostForm.Set("updated", ts) - req.PostForm.Set("id", ts) urlPaths, err := upload.StoreFiles(req) if err != nil { @@ -100,7 +99,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { req.PostForm.Del(discardKey) } - err = db.SetPendingContent(t+"_pending", req.PostForm) + _, err = db.SetPendingContent(t, req.PostForm) if err != nil { log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) -- cgit v1.2.3 From dd0fd60357e8a8dcaf3732947a35e5072eeefaf7 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sun, 30 Oct 2016 22:35:47 -0700 Subject: refactor some db code and update how status vars interpolate throughour UI code --- system/api/external.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 6489c68..7426272 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -99,7 +99,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { req.PostForm.Del(discardKey) } - _, err = db.SetPendingContent(t, req.PostForm) + _, err = db.SetContent(t+":-1", req.PostForm) if err != nil { log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) -- cgit v1.2.3 From 38d6462f5a40317f8c2fdfbd5528b554e3611191 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Sun, 30 Oct 2016 22:40:08 -0700 Subject: fixing previously removed specifier for pending in refactored db set content --- system/api/external.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 7426272..4d52f48 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -99,7 +99,7 @@ func externalPostsHandler(res http.ResponseWriter, req *http.Request) { req.PostForm.Del(discardKey) } - _, err = db.SetContent(t+":-1", req.PostForm) + _, err = db.SetContent(t+"_pending:-1", req.PostForm) if err != nil { log.Println("[External] error:", err) res.WriteHeader(http.StatusInternalServerError) -- cgit v1.2.3 From f26549a2ddf1d9a3c5c4bfaf654b05d3861dbb7f Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 31 Oct 2016 00:37:25 -0700 Subject: initial code to support approving pending content --- system/api/external.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/api') diff --git a/system/api/external.go b/system/api/external.go index 4d52f48..4a42eb5 100644 --- a/system/api/external.go +++ b/system/api/external.go @@ -24,7 +24,7 @@ type Externalable interface { type Mergeable interface { // Approve copies an external post to the internal collection and triggers // a re-sort of its content type posts - Approve() error + Approve(req *http.Request) error } func externalPostsHandler(res http.ResponseWriter, req *http.Request) { -- cgit v1.2.3