Ejemplo n.º 1
0
//printThreadHead renders head part of thread page with cookie.
func (t *threadCGI) printThreadHead(path, id string, page int, ca *thread.Cache, rss string) error {
	switch {
	case ca.HasRecord():
		if !t.IsBot() {
			download.GetCache(true, ca)
		} else {
			log.Println("bot detected, not get cache")
		}
	case t.CheckGetCache():
		ca.Subscribe()
		if t.Req.FormValue("search_new_file") == "" {
			download.GetCache(true, ca)
		}
	default:
		t.Print404(nil, id)
		return errors.New("no records")
	}
	var access string
	var newcookie []*http.Cookie
	if ca.HasRecord() && id == "" && page == 0 {
		cookie, err := t.Req.Cookie("access")
		if err == nil {
			access = cookie.Value
		} else {
			log.Println(err)
		}
		newcookie = t.setCookie(ca, access)
	}
	t.Header(path, rss, newcookie, false)
	return nil
}
Ejemplo n.º 2
0
//printAttach renders the content of attach file and makes thumnail if needed and possible.
func (t *threadCGI) printAttach(datfile, id string, stamp int64, thumbnailSize, suffix string) {
	ca := thread.NewCache(datfile)
	switch {
	case ca.HasRecord():
	case t.CheckGetCache():
		download.GetCache(true, ca)
	default:
		t.Print404(ca, "")
		return
	}
	rec := record.New(ca.Datfile, id, stamp)
	if !rec.Exists() {
		t.Print404(ca, "")
		return
	}
	if err := rec.Load(); err != nil {
		t.Print404(ca, "")
		return
	}
	if rec.GetBodyValue("suffix", "") != suffix {
		t.Print404(ca, "")
		return
	}
	t.renderAttach(rec, suffix, stamp, thumbnailSize)
}
Ejemplo n.º 3
0
//threadApp load thread.Cache specified in the url and returns dat file
//listing records. if thread.Cache len=0 or for each refering the thread.Cache 4 times
//reloads thread.Cache fron network.
func (m *mchCGI) threadApp(board, datkey string) {
	m.WR.Header().Set("Content-Type", "text/plain; charset=Shift_JIS")
	n, err := strconv.ParseInt(datkey, 10, 64)
	if err != nil {
		log.Println(err)
		return
	}
	key := keylib.GetFilekey(n)
	if err != nil {
		m.WR.WriteHeader(404)
		fmt.Fprintf(m.WR, "404 Not Found")
		return
	}
	data := thread.NewCache(key)

	if !data.Exists() {
		m.WR.WriteHeader(404)
		fmt.Fprintf(m.WR, "404 Not Found")
		return
	}

	if m.CheckGetCache() {
		download.GetCache(true, data)
	}

	thread := keylib.MakeDat(data, board, m.Req.Host)
	str := strings.Join(thread, "\n") + "\n"
	m.serveContent("a.txt", time.Unix(data.Stamp(), 0), str)
}