Example #1
0
func Resize(c *middleware.Context) {
	w := c.QueryInt("width")
	p := c.Req.URL.Path
	color.Green("[path] %s", p)
	target := strings.TrimPrefix(p, "/resize")
	if strings.HasPrefix(target, "/cat/screen/") {
		var id int64
		fmt.Sscanf(target, "/cat/screen/%d?width=", &id)
		name, e := screen(id)
		if e != nil {
			color.Red("%s", e)
			return
		}
		target = name
	}
	savePath := "data/public/resize/" + com.ToStr(w) + "/" + target + ".jpg"
	if com.IsFile(savePath) {
		f, e := os.Open(savePath)
		if e != nil {
			color.Red("%s", e)
		}
		c.Resp.Header().Set("Content-Type", "image/jpeg")
		io.Copy(c.Resp, f)
		return
	}

	img, e := imaging.Open(filepath.Join("data/uploads", target))
	if e != nil {
		color.Red("%s", e)
		return
	}
	i := resize.Resize(uint(w), uint(w/2), img, resize.Bilinear)
	dir := filepath.Dir(target)
	os.MkdirAll(filepath.Join("data/public/resize/"+com.ToStr(w)+"/", dir), 0777)
	e = imaging.Save(i, savePath)
	if e != nil {
		color.Red("%s", e)
	}
	c.Resp.Header().Set("Content-Type", "image/jpeg")
	e = jpeg.Encode(c.Resp, i, nil)
	if e != nil {
		color.Red("%s", e)
	}
	//c.Redirect("/public/resize/" + com.ToStr(w) + "/" + target + ".jpg")
}
Example #2
0
func AllFeedJSON(c *middleware.Context) {
	p := c.QueryInt("p")
	if p < 1 {
		p = 1
	}
	feed, e := models.GetFeed(p)
	if e != nil {
		color.Red("%s", e)
	}

	/*cnt, e := models.FeedCount()
	if e != nil {
		color.Red("%s", e)
	}*/

	c.Data["feed"] = feed
	//c.Data["paginater"] = paginater.New(int(cnt), 10, p, 5)
	c.JSON(200, feed)
}
Example #3
0
func submitPost(c *middleware.Context) {

	s, e := models.NewSite(c.Query("link"), c.Query("title"))
	if e != nil {
		c.Flash.Error(e.Error(), true)
		if c.QueryInt("ajax") == 1 {
			c.JSON(200, e.Error())
			return
		}
		c.HTML(200, "catalog/submit")
		return
	}

	c.Flash.Success(fmt.Sprintf("%d  добавлен", s.Id), true)
	if c.QueryInt("ajax") == 1 {
		c.JSON(200, fmt.Sprintf("%d  добавлен", s.Id))
		return
	}
	c.HTML(200, "catalog/submit")
}