Ejemplo n.º 1
0
//checkInfo checks posted info and returs thread name.
//if ok.
func (m *mchCGI) checkInfo(info map[string]string) string {
	var key string
	if info["subject"] != "" {
		key = util.FileEncode("thread", info["subject"])
	} else {
		n, err := strconv.ParseInt(info["key"], 10, 64)
		if err != nil {
			m.errorResp(err.Error(), info)
			return ""
		}
		key = keylib.GetFilekey(n)
	}

	switch {
	case info["body"] == "":
		m.errorResp("本文がありません.", info)
		return ""
	case thread.NewCache(key).Exists(), m.HasAuth():
	case info["subject"] != "":
		m.errorResp("掲示版を作る権限がありません", info)
		return ""
	default:
		m.errorResp("掲示版がありません", info)
		return ""
	}

	if info["subject"] == "" && key == "" {
		m.errorResp("フォームが変です.", info)
		return ""
	}
	return key
}
Ejemplo n.º 2
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)
}