summaryrefslogtreecommitdiff
path: root/pkg/api/message.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/api/message.go')
-rw-r--r--pkg/api/message.go68
1 files changed, 0 insertions, 68 deletions
diff --git a/pkg/api/message.go b/pkg/api/message.go
deleted file mode 100644
index 81e863f..0000000
--- a/pkg/api/message.go
+++ /dev/null
@@ -1,68 +0,0 @@
-package api
-
-import (
- "encoding/base64"
- "fmt"
- "log"
- "net/http"
- "strings"
-)
-
-func (a *API) getBundleHandler(w http.ResponseWriter, r *http.Request) {
- ids := strings.Split(r.PathValue("ids"), "/")
-
- for _, messageID := range ids {
- msg, err := a.idec.GetMessage(messageID)
- if err != nil {
- log.Println("cant read file for message", messageID, err)
- continue
- }
-
- b64msg := base64.StdEncoding.EncodeToString([]byte(msg.Bundle()))
- fmt.Fprintf(w, "%s:%s\n", messageID, b64msg)
- }
-}
-
-func (a *API) getMessageHandler(w http.ResponseWriter, r *http.Request) {
- msgID := r.PathValue("msgID")
-
- msg, err := a.idec.GetMessage(msgID)
- if err != nil {
- http.Error(w, err.Error(), http.StatusBadRequest)
- }
-
- _, err = fmt.Fprintln(w, msg.Bundle())
-}
-
-func (a *API) postPointHandler(w http.ResponseWriter, r *http.Request) {
- msg, pauth := r.PathValue("tmsg"), r.PathValue("pauth")
- if err := r.ParseForm(); err != nil {
- http.Error(w, err.Error(), http.StatusBadRequest)
- return
- }
-
- form := r.PostForm
- if form.Has("tmsg") {
- msg = form.Get("tmsg")
- }
- if form.Has("pauth") {
- pauth = form.Get("pauth")
- }
-
- a.savePointMessage(w, msg, pauth)
-}
-
-func (a *API) savePointMessage(w http.ResponseWriter, rawMessage, auth string) error {
- point, err := a.idec.GetPointByAuth(auth)
- if err != nil {
- fmt.Fprintln(w, "error: no auth - wrong authstring")
- return err
- }
-
- if err := a.idec.SavePointMessage(point.Username, rawMessage); err != nil {
- return err
- }
- fmt.Fprintln(w, "msg ok")
-
- return nil
-}