Ejemplo n.º 1
0
/**
 * 提交一个链接并保存到数据库
 */
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.CreateLinkSubmitForm()
	f.FillByRequest(ctx.Request)

	var resubmit bool
	if ctx.Get("resubmit") == "true" {
		resubmit = true
	}
	user := ctx.Data["user"].(*models.User)
	success, linkId, errorMsgs, _ := models.Link_SaveForm(f, user.Id, resubmit)

	if success {
		go addLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本   TODO:

		return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
	} else if linkId > 0 {
		return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId))
	} else {
		ctx.ViewData["Errors"] = errorMsgs
		ctx.ViewData["Values"] = f.Values()
	}
	return ctx.View(nil)

}
Ejemplo n.º 2
0
func (self *BaseCrawler) saveLink(url, title string) (err error) {
	defer func() {
		if err != nil {
			if strings.Index(err.Error(), "Url已经提交过") > -1 {
				goku.Logger().Logln("Crawler saveLink:", err.Error(), url, title)
			} else {
				goku.Logger().Errorln("Crawler saveLink error:", err.Error(), url, title)
			}
		}
	}()
	idCount := len(self.UserIds)
	if idCount < 1 {
		err = errors.New("no user ids")
		return
	}
	userId := self.UserIds[rand.Int63n(int64(idCount))]
	user := models.User_GetById(userId)
	if user == nil || user.Id < 1 {
		err = errors.New("no selected user")
		return
	}

	if strings.Index(url, "news.dbanotes.net") > 0 {
		return nil
	}
	// 移除多余的字符
	if strings.LastIndex(title, ")") == len(title)-1 && strings.Index(title, " (") > 0 {
		title = title[0:strings.LastIndex(title, " (")]
	}

	topics := []string{}
	ltitle := strings.ToLower(title)
	for i := 0; i < lenTopTopics; i++ {
		if strings.Index(ltitle, topTopics[i].NameLower) > -1 {
			if len(topTopics[i].Name) > 1 {
				topics = append(topics, topTopics[i].Name)
			}
		}
	}

	m := map[string]string{
		"title":   title,
		"context": url,
		"topics":  strings.Join(topics, ","),
	}
	f := forms.CreateLinkSubmitForm()
	f.FillByMap(m)

	success, linkId, errMsg, _ := models.Link_SaveForm(f, user.Id, false)

	if success {
		go controllers.AddLinkForSearch(0, f.CleanValues(), linkId, user.Name) //contextType:0: url, 1:文本   TODO:
	} else {
		err = errors.New(strings.Join(errMsg, ", "))
		return
	}
	return nil
}
Ejemplo n.º 3
0
/**
 * 提交一个链接并保存到数据库
 */
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.CreateLinkSubmitForm()
	f.FillByRequest(ctx.Request)

	success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id)

	if success {
		return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
	} else {
		ctx.ViewData["Errors"] = errorMsgs
		ctx.ViewData["Values"] = f.Values()
	}
	return ctx.View(nil)

}
Ejemplo n.º 4
0
/**
 * 提交一个链接并保存到数据库
 */
func link_submit(ctx *goku.HttpContext) goku.ActionResulter {

	f := forms.CreateLinkSubmitForm()
	f.FillByRequest(ctx.Request)

	var resubmit bool
	if ctx.Get("resubmit") == "true" {
		resubmit = true
	}

	success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id, resubmit)

	if success {
		return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
	} else if linkId > 0 {
		return ctx.Redirect(fmt.Sprintf("/link/%d?already_submitted=true", linkId))
	} else {
		ctx.ViewData["Errors"] = errorMsgs
		ctx.ViewData["Values"] = f.Values()
	}
	return ctx.View(nil)

}
Ejemplo n.º 5
0
			"title":   ctx.Get("t"),
			"context": ctx.Get("u"),
		}
		return ctx.View(nil)

	}).Filters(filters.NewRequireLoginFilter()).

	/**
	 * 提交一个链接并保存到数据库
	 */
	Post("submit", func(ctx *goku.HttpContext) goku.ActionResulter {

		f := forms.CreateLinkSubmitForm()
		f.FillByRequest(ctx.Request)

		success, linkId, errorMsgs := models.Link_SaveForm(f, (ctx.Data["user"].(*models.User)).Id)

		if success {
			return ctx.Redirect(fmt.Sprintf("/link/%d", linkId))
		} else {
			ctx.ViewData["Errors"] = errorMsgs
			ctx.ViewData["Values"] = f.Values()
		}
		return ctx.View(nil)

	}).Filters(filters.NewRequireLoginFilter()).

	/**
	 * 提交评论并保存到数据库
	 */
	Post("ajax-comment", func(ctx *goku.HttpContext) goku.ActionResulter {