Example #1
0
func Upload(c *middleware.Context) {
	c.Req.ParseMultipartForm(32 << 20)
	file, _, err := c.Req.FormFile("uploadfile")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer file.Close()

	name := uuid.NewV4().String()

	//.fmt.Fprintf(w, "%v", handler.Header)
	err = os.MkdirAll("data/uploads/"+makePaths(name), 0777)
	if err != nil {
		return
	}
	f, err := os.OpenFile("data/uploads/"+makePaths(name)+"/"+name, os.O_WRONLY|os.O_CREATE, 0777)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f.Close()
	io.Copy(f, file)
	c.JSON(200, makePaths(name))
}
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")
}