//NewListItem returns ListItem struct from caches. func NewListItem(caches []*thread.Cache, remove bool, target string, search bool, filter, tag string) *ListItem { li := &ListItem{Remove: remove} li.Caches = make([]*CacheInfo, 0, len(caches)) if search { li.StrOpts = "?search_new_file=yes" } for _, ca := range caches { x, ok := checkCache(ca, target, filter, tag) if !ok { continue } ci := &CacheInfo{Cache: ca} li.Caches = append(li.Caches, ci) ci.Title = util.EscapeSpace(x) if target == "recent" { strTags := make([]string, user.Len(ca.Datfile)) for i, v := range user.GetByThread(ca.Datfile) { strTags[i] = strings.ToLower(v.Tagstr) } for _, st := range suggest.Get(ca.Datfile, nil) { if !util.HasString(strTags, strings.ToLower(st.Tagstr)) { ci.Sugtags = append(ci.Sugtags, st) } } } ci.Tags = user.GetByThread(ca.Datfile) } return li }
//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) } } }