Esempio n. 1
0
//printRecord renders record.txt , with records in cache ca.
func (t *threadCGI) printRecord(ca *thread.Cache, rec *record.Record) {
	thumbnailSize := ""
	var suffix string
	var attachSize int64
	if at := rec.GetBodyValue("attach", ""); at != "" {
		suffix = rec.GetBodyValue("suffix", "")
		attachFile := rec.AttachPath("")
		attachSize = int64(len(at)*57/78) + 1000
		reg := regexp.MustCompile("^[0-9A-Za-z]+")
		if !reg.MatchString(suffix) {
			suffix = cfg.SuffixTXT
		}
		typ := mime.TypeByExtension("." + suffix)
		if typ == "" {
			typ = "text/plain"
		}
		if util.IsValidImage(typ, attachFile) {
			thumbnailSize = cfg.DefaultThumbnailSize
		}
	}
	body := rec.GetBodyValue("body", "")
	body = t.HTMLFormat(body, cfg.ThreadURL, t.Path(), false)
	removeID := rec.GetBodyValue("remove_id", "")
	if len(removeID) > 8 {
		removeID = removeID[:8]
	}
	resAnchor := t.ResAnchor(removeID, cfg.ThreadURL, t.Path(), false)

	id8 := rec.ID
	if len(id8) > 8 {
		id8 = id8[:8]
	}
	s := struct {
		Datfile    string
		Rec        *record.Record
		RecHead    record.Head
		Sid        string
		AttachSize int64
		Suffix     string
		Body       template.HTML
		Thumbnail  string
		RemoveID   string
		ResAnchor  string
		cgi.Defaults
	}{
		ca.Datfile,
		rec,
		rec.CopyHead(),
		id8,
		attachSize,
		suffix,
		template.HTML(body),
		thumbnailSize,
		removeID,
		resAnchor,
		*t.Defaults(),
	}
	cgi.RenderTemplate("record", s, t.WR)
}