예제 #1
0
func handleBookmarklet(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		output(c, w, "bookmarklet_not_loggedin")
		return
	}

	url := r.FormValue("url")
	title := r.FormValue("title")
	tagString := r.FormValue("tags")
	tags := strings.Split(tagString, ",")

	bm := bookmarks.NewBookmark(u, url, title, tags)
	_, err := bm.Save(c)
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}

	output(c, w, "bookmarklet_save", map[string]interface{}{
		"url":   url,
		"title": title,
		"tags":  tags,
	})
}
예제 #2
0
func handleCreate(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		return
	}

	r.ParseForm()
	url := r.FormValue("url")
	title := r.FormValue("title")
	tagString := r.FormValue("tags")
	if url == "" {
		output(c, w, "create")
		return
	}

	tags := strings.Split(tagString, ",")
	bm := bookmarks.NewBookmark(u, url, title, tags)
	_, err := bm.Save(c)
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Location", rootURL(c))
	w.WriteHeader(http.StatusFound)
	return
}
예제 #3
0
func handleDelete(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	u := user.Current(c)
	if u == nil {
		return
	}

	url := r.FormValue("url")
	bm := bookmarks.NewBookmark(u, url, "", []string{})
	_, err := bm.Delete(c)
	if err != nil {
		http.Error(w, err.String(), http.StatusInternalServerError)
		return
	}

	w.Header().Set("Location", rootURL(c))
	w.WriteHeader(http.StatusFound)
	return
}