(app *App, w http.ResponseWriter, r *http.Request)
| 73 | } |
| 74 | |
| 75 | func handleGetSplitContent(app *App, w http.ResponseWriter, r *http.Request) error { |
| 76 | var collID int64 |
| 77 | var collLookupID string |
| 78 | var coll *Collection |
| 79 | var err error |
| 80 | vars := mux.Vars(r) |
| 81 | if collAlias := vars["alias"]; collAlias != "" { |
| 82 | // Fetch collection information, since an alias is provided |
| 83 | coll, err = app.db.GetCollection(collAlias) |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | collID = coll.ID |
| 88 | collLookupID = coll.Alias |
| 89 | } |
| 90 | |
| 91 | p, err := app.db.GetPost(vars["post"], collID) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | |
| 96 | receipt := r.FormValue("receipt") |
| 97 | if receipt == "" { |
| 98 | return impart.HTTPError{http.StatusBadRequest, "No `receipt` given."} |
| 99 | } |
| 100 | err = verifyReceipt(receipt, collLookupID) |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | |
| 105 | d := struct { |
| 106 | Content string `json:"body"` |
| 107 | HTMLContent string `json:"html_body"` |
| 108 | }{} |
| 109 | |
| 110 | if exc := strings.Index(p.Content, shortCodePaid); exc > -1 { |
| 111 | baseURL := "" |
| 112 | if coll != nil { |
| 113 | baseURL = coll.CanonicalURL() |
| 114 | } |
| 115 | |
| 116 | d.Content = p.Content[exc+len(shortCodePaid):] |
| 117 | d.HTMLContent = applyMarkdown([]byte(d.Content), baseURL, app.cfg) |
| 118 | } |
| 119 | |
| 120 | return impart.WriteSuccess(w, d, http.StatusOK) |
| 121 | } |
| 122 | |
| 123 | func verifyReceipt(receipt, id string) error { |
| 124 | receiptsHost := os.Getenv("RECEIPTS_HOST") |
nothing calls this directly
no test coverage detected