Example #1
0
// InputController is the handler for the page where people can enter the gallery password
func InputController(c *gin.Context) {

	comicID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.Error(err).SetMeta("keys.InputController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("keys.InputController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	vals := struct {
		Meta m.Metadata
		ID   int
	}{
		Meta: metadata,
		ID:   comicID,
	}

	c.HTML(http.StatusOK, "gallerypassword.tmpl", vals)

	return

}
Example #2
0
// NewController posts new blogs
func NewController(c *gin.Context) {

	// holds our page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("blog.NewController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	vals := struct {
		Meta m.Metadata
		Csrf string
		New  bool
		Edit bool
	}{
		Meta: metadata,
		Csrf: c.MustGet("csrf_token").(string),
		New:  true,
		Edit: false,
	}

	c.HTML(http.StatusOK, "blogedit.tmpl", vals)

	return

}
Example #3
0
// EditController edits category details
func EditController(c *gin.Context) {
	var err error

	blogID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.Error(err).SetMeta("blog.EditController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("blog.EditController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	var blog m.BlogType

	// get the gallery from bolt
	err = u.Storm.One("ID", blogID, &blog)
	if err != nil {
		c.Error(err).SetMeta("blog.EditController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	vals := struct {
		Meta m.Metadata
		Csrf string
		Blog m.BlogType
		New  bool
		Edit bool
	}{
		Meta: metadata,
		Csrf: c.MustGet("csrf_token").(string),
		Blog: blog,
		New:  false,
		Edit: true,
	}

	c.HTML(http.StatusOK, "blogedit.tmpl", vals)

	return

}
Example #4
0
// EditController edits link details
func EditController(c *gin.Context) {
	var err error

	linkID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.Error(err).SetMeta("link.EditController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("link.EditController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	var link m.LinkType

	// get the gallery from bolt
	err = u.Storm.One("ID", linkID, &link)
	if err != nil {
		c.Error(err).SetMeta("link.EditController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	vals := struct {
		Meta m.Metadata
		Csrf string
		Link m.LinkType
	}{
		Meta: metadata,
		Csrf: c.MustGet("csrf_token").(string),
		Link: link,
	}

	c.HTML(http.StatusOK, "linkedit.tmpl", vals)

	return

}
Example #5
0
// EditController edits category details
func EditController(c *gin.Context) {
	var err error

	comicID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.Error(err).SetMeta("category.EditController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("category.EditController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	var cat m.CategoryType

	// get the gallery from bolt
	err = u.Storm.One("ID", comicID, &cat)
	if err != nil {
		c.Error(err).SetMeta("category.EditController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	vals := struct {
		Meta     m.Metadata
		Csrf     string
		Category m.CategoryType
	}{
		Meta:     metadata,
		Csrf:     c.MustGet("csrf_token").(string),
		Category: cat,
	}

	c.HTML(http.StatusOK, "categoryedit.tmpl", vals)

	return

}
Example #6
0
// IndexController handles the galleries index page
func IndexController(c *gin.Context) {
	var err error

	categoryID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.Error(err).SetMeta("gallery.IndexController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	currentPage, _ := strconv.Atoi(c.Param("page"))
	if currentPage < 1 {
		currentPage = 1
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("gallery.IndexController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	var total []m.GalleryType

	err = u.Storm.Find("Category", categoryID, &total)
	if err != nil {
		c.Error(err).SetMeta("gallery.IndexController.Find")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds our pagination data
	paginate := u.Paged{}

	paginate.Path = "/comics"
	paginate.CurrentPage = currentPage
	paginate.Total = len(total)
	paginate.PerPage = 6
	paginate.Desc()

	var category m.CategoryType

	// get category info
	err = u.Storm.One("ID", categoryID, &category)
	if err != nil {
		c.Error(err).SetMeta("gallery.IndexController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// convert the gallery desc
	category.DescOut = u.Markdown(category.Desc)

	var galleries []m.GalleryType

	// get all the galleries with a limit
	err = u.Storm.Find("Category", categoryID, &galleries, storm.Limit(paginate.PerPage), storm.Skip(paginate.Skip), storm.Reverse())
	if err != nil {
		c.Error(err).SetMeta("gallery.IndexController.Find")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	for idx := range galleries {
		// cover image is the first image in the slice
		galleries[idx].Cover = galleries[idx].Files[0].Filename
	}

	// values for template
	vals := struct {
		Meta      m.Metadata
		Paged     u.Paged
		Category  m.CategoryType
		Galleries []m.GalleryType
		All       bool
	}{
		Meta:      metadata,
		Paged:     paginate,
		Category:  category,
		Galleries: galleries,
		All:       true,
	}

	c.HTML(http.StatusOK, "gallery.tmpl", vals)

	return

}
Example #7
0
// ViewController handles the blog index page
func ViewController(c *gin.Context) {
	var err error

	currentPage, err := strconv.Atoi(c.Param("page"))
	if currentPage < 1 {
		currentPage = 1
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("blog.ViewController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// get a count of the blogs
	total, err := u.Storm.Count(&m.BlogType{})
	if err != nil {
		c.Error(err).SetMeta("blog.ViewController.Count")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds our pagination data
	paginate := u.Paged{}

	paginate.Path = "/blog"
	paginate.CurrentPage = currentPage
	paginate.Total = total
	paginate.PerPage = 10
	paginate.Desc()

	var posts m.Blogs

	// get all the blog posts with a limit
	err = u.Storm.All(&posts, storm.Limit(paginate.PerPage), storm.Skip(paginate.Skip), storm.Reverse())
	if err != nil {
		c.Error(err).SetMeta("blog.ViewController.All")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	for idx, post := range posts {
		// format post with markdown
		posts[idx].ContentOut = u.Markdown(post.Content)
		// convert time
		posts[idx].HumanTime = post.StoredTime.Format("2006-01-02")
	}

	// values for template
	vals := struct {
		Meta  m.Metadata
		Paged u.Paged
		Posts m.Blogs
	}{
		Meta:  metadata,
		Paged: paginate,
		Posts: posts,
	}

	c.HTML(http.StatusOK, "blog.tmpl", vals)

	return

}
Example #8
0
// EditController edits category details
func EditController(c *gin.Context) {
	var err error

	galleryID, err := strconv.Atoi(c.Param("gallery"))
	if err != nil {
		c.Error(err).SetMeta("image.EditController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	imageID, err := strconv.Atoi(c.Param("image"))
	if err != nil {
		c.Error(err).SetMeta("image.EditController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("image.EditController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	var gallery m.GalleryType
	var image m.FileType

	err = u.Storm.One("ID", galleryID, &gallery)
	if err != nil {
		c.Error(err).SetMeta("image.EditController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	sort.Sort(gallery.Files)

	// update the image info
	for i := len(gallery.Files) - 1; i >= 0; i-- {
		file := gallery.Files[i]

		if file.ID == imageID {
			image = file
		}
	}

	vals := struct {
		Meta    m.Metadata
		Csrf    string
		Gallery m.GalleryType
		Image   m.FileType
	}{
		Meta:    metadata,
		Csrf:    c.MustGet("csrf_token").(string),
		Gallery: gallery,
		Image:   image,
	}

	c.HTML(http.StatusOK, "imageedit.tmpl", vals)

	return

}
Example #9
0
// ViewController handles the comic image pages
func ViewController(c *gin.Context) {
	var err error

	// the key for private galleries
	privateKey := c.Query("key")

	comicID, err := strconv.Atoi(c.Param("id"))
	if err != nil {
		c.Error(err).SetMeta("image.ViewController")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	currentPage, err := strconv.Atoi(c.Param("page"))
	if currentPage < 1 {
		currentPage = 1
	}

	// holds out page metadata from settings
	metadata, err := u.GetMetadata()
	if err != nil {
		c.Error(err).SetMeta("image.ViewController.GetMetadata")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	var gallery m.GalleryType
	var image m.FileType
	var title string

	err = u.Storm.One("ID", comicID, &gallery)
	if err != nil {
		c.Error(err).SetMeta("image.ViewController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// holds our pagination data
	paginate := u.Paged{}

	paginate.Key = privateKey
	paginate.Path = "/image/" + c.Param("id")
	paginate.CurrentPage = currentPage
	paginate.Total = len(gallery.Files)
	paginate.PerPage = 1
	paginate.Desc()

	sort.Sort(gallery.Files)

	for i, c := range gallery.Files {
		i++
		if i == currentPage {
			image = c
		}
	}

	// convert the gallery desc
	image.DescOut = u.Markdown(image.Desc)

	title = gallery.Title

	// values for template
	vals := struct {
		Meta  m.Metadata
		Paged u.Paged
		Comic int
		Title string
		Image m.FileType
	}{
		Meta:  metadata,
		Paged: paginate,
		Comic: comicID,
		Title: title,
		Image: image,
	}

	c.HTML(http.StatusOK, "image.tmpl", vals)

	return

}