Exemple #1
0
func importHandler(w http.ResponseWriter, r *http.Request) {
	file, _, err := r.FormFile("opmlFile")

	if err != nil {
		log.Print(err)
		return
	}
	contents, err := ioutil.ReadAll(file)

	if err != nil {
		log.Print(err)
		return
	}

	userid := getUserId(w, r)
	urls, err := parser.ParseOPML(contents)

	if err != nil {
		log.Print(err)
		return
	}

	for _, url := range urls {

		feed := data.Feed{Id: data.GenerateId(url), Url: url}
		was_inserted := db.AddFeed(feed, userid)

		if was_inserted {
			fetchFeed(feed)
		}
	}

	fmt.Fprintf(w, "%s", "Imported")
}
Exemple #2
0
func addFeedHandler(w http.ResponseWriter, r *http.Request) {
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}
	type JsonData struct {
		Url string
	}
	var jsonData JsonData
	json.Unmarshal(body, &jsonData)

	feed := data.Feed{Id: data.GenerateId(jsonData.Url), Url: jsonData.Url, Title: jsonData.Url}
	userid := getUserId(w, r)

	was_inserted := db.AddFeed(feed, userid)

	if was_inserted {
		fetchFeed(feed)
	}

	listFeedsHandler(w, r)
}