//doRecent renders records whose timestamp is in range of one specified in url.
func doRecent(w http.ResponseWriter, r *http.Request) {
	s, err := new(w, r)
	if err != nil {
		log.Println(err)
		return
	}
	reg := regexp.MustCompile("^recent/?([-0-9A-Za-z/]*)$")
	m := reg.FindStringSubmatch(s.Path())
	if m == nil {
		log.Println("illegal url")
		return
	}
	stamp := m[1]
	last := time.Now().Unix() + cfg.RecentRange
	begin, end, _ := s.parseStamp(stamp, last)
	for _, i := range recentlist.GetRecords() {
		if begin > i.Stamp || i.Stamp > end {
			continue
		}
		ca := thread.NewCache(i.Datfile)
		cont := fmt.Sprintf("%d<>%s<>%s", i.Stamp, i.ID, i.Datfile)
		if user.Len(ca.Datfile) > 0 {
			cont += "<>tag:" + user.String(ca.Datfile)
		}
		_, err := fmt.Fprintf(w, "%s\n", cont)
		if err != nil {
			log.Println(err)
		}
	}
}
Beispiel #2
0
//CreateAllCachedirs creates all dirs in recentlist to be retrived when called recentlist.getall.
//(heavymoon)
func CreateAllCachedirs() {
	recs := recentlist.GetRecords()
	err := db.DB.Update(func(tx *bolt.Tx) error {
		for _, rh := range recs {
			ca := NewCache(rh.Datfile)
			if !ca.Exists() {
				ca.subscribe(tx)
			}
		}
		return nil
	})
	if err != nil {
		log.Println(err)
	}
}
Beispiel #3
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)
	}
}