Esempio n. 1
0
// 数据初始化
func (this *BaseController) Prepare() {
	// 获取今天日期
	t := time.Now().Format("20060102")
	// 定义一个日志模型
	var sclog models.SC_Log
	// 查询今天入库数量
	models.GetOneByQuery(models.DbLog, bson.M{"day": t}, &sclog)
	// 添加到模板中
	this.Data["Today"] = sclog.PutNums

	// 获取所有种子数量
	all := models.Count(models.DbInfo, nil)
	// 使用到模板中
	this.Data["All"] = all

	// 判断用户语言
	if this.setLang() {
		i := strings.Index(this.Ctx.Request.RequestURI, "?")
		this.Redirect(this.Ctx.Request.RequestURI[:i], 302)
		return
	}
}
Esempio n. 2
0
// 显示页
func (this *IndexController) View() {
	// 获取InfoHash
	infohash := this.Ctx.Input.Param(":infohash")

	// 将infohash转换为大写
	infohash = strings.ToUpper(infohash)

	// 定义一个SC_Info
	var scinfo models.SC_Info

	// 获取种子信息
	models.GetOneByQuery(models.DbInfo, bson.M{"infohash": infohash}, &scinfo)

	if scinfo.InfoHash == "" {
		// 如果infohash为空或小于40则报错
		this.Abort("404")
	}

	// 设置种子标题
	this.Data["Caption"] = scinfo.Caption

	// 定义两个SC_Info列表
	var hots []models.SC_Info

	// 获取热门种子列表
	models.GetDataByQuery(models.DbInfo, 0, 5, "-hot", nil, &hots)
	// 设置热门列表
	this.Data["HotList"] = hots

	// 自增下载次数
	models.SetAdd(models.DbInfo, bson.M{"infohash": infohash}, "views", true)

	// 设置创建时间
	this.Data["CreateTime"] = scinfo.CreateTime
	// 设置入库时间
	this.Data["PutTime"] = scinfo.PutTime
	// 设置文件大小
	this.Data["Length"] = scinfo.Length
	// 设置关键词
	this.Data["Keys"] = scinfo.Keys
	// 设置种子热度
	this.Data["Hot"] = scinfo.Hot
	// 设置文件数量
	this.Data["FileCount"] = scinfo.FileCount
	// 设置InfoHash
	this.Data["InfoHash"] = scinfo.InfoHash
	// 设置文件列表
	this.Data["FileList"] = scinfo.FileList
	// 设置下载链接
	this.Data["Down"] = fmt.Sprintf("http://btcache.me/torrent/%s", scinfo.InfoHash)

	// 二维码文件是否存在
	if _, err := os.Stat("/static/qrcode/" + scinfo.InfoHash[0:1] + "/" + scinfo.InfoHash[1:2] + "/" + scinfo.InfoHash[2:3] + "/" + scinfo.InfoHash[3:4] + "/" + scinfo.InfoHash[4:5] + "/" + scinfo.InfoHash[5:6] + "/" + scinfo.InfoHash[6:7] + "/" + scinfo.InfoHash + ".png"); err != nil {
		// 存在则设置二维码图片
		this.Data["Qrcode"] = "/static/qrcode/" + scinfo.InfoHash[0:1] + "/" + scinfo.InfoHash[1:2] + "/" + scinfo.InfoHash[2:3] + "/" + scinfo.InfoHash[3:4] + "/" + scinfo.InfoHash[4:5] + "/" + scinfo.InfoHash[5:6] + "/" + scinfo.InfoHash[6:7] + "/" + scinfo.InfoHash + ".png"
	}

	// 自增查看次数
	models.SaveLog(time.Now().Format("20060102"), "viewnums")

	// 输出模板
	this.TplNames = "view.html"
}