Esempio n. 1
0
//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)
		}
	}
}
Esempio n. 2
0
//makeOneRow makes one row of CSV depending on c.
func (g *gatewayCGI) makeOneRow(c string, ca *thread.Cache, p, title string) string {
	switch c {
	case "file":
		return ca.Datfile
	case "stamp":
		return strconv.FormatInt(ca.Stamp(), 10)
	case "date":
		return time.Unix(ca.Stamp(), 0).String()
	case "path":
		return p
	case "uri":
		if g.Host() != "" && p != "" {
			return "http://" + g.Host() + p
		}
	case "type":
		return "thread"
	case "title":
		return title
	case "records":
		return strconv.Itoa(ca.Len())
	case "size":
		return strconv.FormatInt(ca.Size(), 10)
	case "tag":
		return user.String(ca.Datfile)
	case "sugtag":
		return suggest.String(ca.Datfile)
	}
	return ""
}