func createHouse(app *app, w http.ResponseWriter, r *http.Request) error { html := r.FormValue("html") if strings.TrimSpace(html) == "" { return impart.HTTPError{http.StatusBadRequest, "Supply something to publish."} } public := r.FormValue("public") == "true" houseID := store.GenerateFriendlyRandomString(8) _, err := app.db.Exec("INSERT INTO houses (id, html) VALUES (?, ?)", houseID, html) if err != nil { return err } if err = app.session.writeToken(w, houseID); err != nil { return err } resUser := newSessionInfo(houseID) if public { go addPublicAccess(app, houseID, html) } return impart.WriteSuccess(w, resUser, http.StatusCreated) }
func poster(w http.ResponseWriter, r *http.Request) { post := r.FormValue("w") if post == "" { fmt.Fprintf(w, "%s", indexPage) return } var friendlyId string var err error if *outDir != "" { // Using file-based storage friendlyId, err = store.SavePost(*outDir, []byte(post)) } else { // Using database storage friendlyId = store.GenerateFriendlyRandomString(store.FriendlyIdLen) editToken := store.Generate62RandomString(32) _, err = db.Exec("INSERT INTO posts (id, content, modify_token, text_appearance) VALUES (?, ?, ?, 'mono')", friendlyId, post, editToken) } if err != nil { fmt.Printf("Error saving: %s\n", err) fmt.Fprint(w, "Couldn't save :(\n") return } if *debugging { fmt.Printf("Saved new post %s\n", friendlyId) } fmt.Fprintf(w, "https://write.as/%s", friendlyId) if !strings.Contains(r.UserAgent(), "Android") { fmt.Fprint(w, "\n") } }