Example #1
0
//Getall reload all records in cache in cachelist from network.
func Getall() {
	for _, ca := range thread.AllCaches() {
		log.Println(ca.Datfile, "is downloading...")
		GetCache(false, ca)
		log.Println(ca.Datfile, "end")
	}
}
//printCSV renders csv of caches saved in disk.
func printCSV(w http.ResponseWriter, r *http.Request) {
	g, err := new(w, r)
	if err != nil {
		log.Println(err)
		return
	}
	g.renderCSV(thread.AllCaches())
}
//printCSVChanges renders csv of caches which changes recently and are in disk(validstamp is newer).
func printCSVChanges(w http.ResponseWriter, r *http.Request) {
	g, err := new(w, r)
	if err != nil {
		log.Println(err)
		return
	}
	all := thread.AllCaches()
	sort.Sort(sort.Reverse(thread.NewSortByStamp(all, false)))
	g.renderCSV(all)
}
Example #4
0
//Load loads from the file, adds stamps/datfile pairs from cachelist and recentlist.
//and saves to file.
func Load() {
	allCaches := thread.AllCaches()
	allRecs := recentlist.GetRecords()
	err := db.DB.Update(func(tx *bolt.Tx) error {
		for _, c := range allCaches {
			setFromCache(tx, c)
		}
		for _, rec := range allRecs {
			c := thread.NewCache(rec.Datfile)
			setFromCache(tx, c)
		}
		return nil
	})
	if err != nil {
		log.Println(err)
	}
}
//printRSS reneders rss including newer records.
func printRSS(w http.ResponseWriter, r *http.Request) {
	g, err := new(w, r)
	if err != nil {
		log.Println(err)
		return
	}
	rsss := cgi.NewRSS("UTF-8", "", g.M["logo"], "http://"+g.Host(), "",
		"http://"+g.Host()+cfg.GatewayURL+"/"+"rss", g.M["description"], xslURL)
	for _, ca := range thread.AllCaches() {
		g.appendRSS(rsss, ca)
	}
	g.WR.Header().Set("Content-Type", "text/xml; charset=UTF-8")
	if rsss.Len() != 0 {
		g.WR.Header().Set("Last-Modified", g.RFC822Time(rsss.Feeds[0].Date))
	}
	rsss.MakeRSS1(g.WR)
}
//PrintTitle renders list of newer thread in the disk for the top page
func PrintTitle(w http.ResponseWriter, r *http.Request) {
	g, err := new(w, r)
	if err != nil {
		log.Println(err)
		return
	}
	if r.FormValue("cmd") != "" {
		g.jumpNewFile()
		return
	}
	all := thread.AllCaches()
	sort.Sort(sort.Reverse(thread.NewSortByStamp(all, false)))
	outputCachelist := make([]*thread.Cache, 0, thread.Len())
	for _, ca := range all {
		if time.Now().Unix() <= ca.Stamp()+cfg.TopRecentRange {
			outputCachelist = append(outputCachelist, ca)
		}
	}

	g.Header(g.M["logo"]+" - "+g.M["description"], "", nil, false)
	s := struct {
		Target        string
		Taglist       tag.Slice
		MchURL        string
		MchCategories []*mchCategory
		Types         string
		NoList        bool
		cgi.ListItem
		cgi.Defaults
	}{
		"changes",
		user.Get(),
		g.mchURL(""),
		g.mchCategories(),
		"thread",
		len(outputCachelist) == 0,
		*cgi.NewListItem(outputCachelist, false, "changes", false, g.Filter, g.Tag),
		*g.Defaults(),
	}
	cgi.RenderTemplate("top", s, g.WR)
	g.PrintNewElementForm()
	g.Footer(nil)
}
//printIndex renders threads in disk.
//id doChange threads are sorted by velocity.
func (g *gatewayCGI) printIndex(doChange bool) {
	str := "index"
	title := g.M[str]
	if doChange {
		str = "change"
		title = g.M["changes"]
	}

	if g.Filter != "" {
		title = fmt.Sprintf("%s : %s", g.M["string"], g.Filter)
	}
	g.Header(title, "", nil, true)
	fmt.Fprintf(g.WR, "<p>%s</p>", g.M["desc_"+str])
	cl := thread.AllCaches()
	if doChange {
		sort.Sort(sort.Reverse(thread.NewSortByStamp(cl, false)))
	} else {
		sort.Sort(sort.Reverse(thread.NewSortByVelocity(cl)))
	}
	g.PrintIndexList(cl, str, true, false, g.Filter, g.Tag)
}