Exemple #1
0
// DeleteController deletes images from galleries
func DeleteController(c *gin.Context) {
	var err error
	var df deleteForm

	err = c.Bind(&df)
	if err != nil {
		c.Error(err).SetMeta("image.DeleteController.Bind")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// start transaction
	tx, err := u.Storm.Begin(true)
	if err != nil {
		c.Error(err).SetMeta("image.DeleteController.Begin")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}
	defer tx.Rollback()

	var gallery m.GalleryType

	err = tx.One("ID", df.Gallery, &gallery)
	if err != nil {
		c.Error(err).SetMeta("image.DeleteController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	sort.Sort(gallery.Files)

	// remove the file from the slice
	for i := len(gallery.Files) - 1; i >= 0; i-- {
		file := gallery.Files[i]

		if file.ID == df.Image {
			gallery.Files = append(gallery.Files[:i], gallery.Files[i+1:]...)
		}
	}

	err = tx.Save(&gallery)
	if err != nil {
		c.Error(err).SetMeta("image.DeleteController.Save")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// commit
	tx.Commit()

	c.Redirect(http.StatusFound, c.Request.Referer())

	return

}
Exemple #2
0
// UpdateController updates gallery information
func UpdateController(c *gin.Context) {
	var err error
	var uf updateForm

	err = c.Bind(&uf)
	if err != nil {
		c.Error(err).SetMeta("gallery.UpdateController.Bind")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// start transaction
	tx, err := u.Storm.Begin(true)
	if err != nil {
		c.Error(err).SetMeta("gallery.UpdateController.Begin")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}
	defer tx.Rollback()

	var gallery m.GalleryType

	// get gallery details
	err = tx.One("ID", uf.ID, &gallery)
	if err != nil {
		c.Error(err).SetMeta("gallery.UpdateController.One")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	gallery.Title = uf.Title
	gallery.Desc = uf.Desc
	gallery.Category = uf.Category

	// save with updated info
	err = tx.Save(&gallery)
	if err != nil {
		c.Error(err).SetMeta("gallery.UpdateController.Save")
		c.HTML(http.StatusInternalServerError, "error.tmpl", nil)
		return
	}

	// commit
	tx.Commit()

	c.Redirect(http.StatusFound, fmt.Sprintf("/comics/%d/1", uf.Category))

	return

}
Exemple #3
0
// AddKey will add a key to the gallery
func AddKey(gid int) (err error) {

	// start transaction
	tx, err := u.Storm.Begin(true)
	if err != nil {
		return
	}
	defer tx.Rollback()

	var gallery m.GalleryType

	err = tx.One("ID", gid, &gallery)
	if err != nil {
		return
	}

	sort.Sort(gallery.Keys)

	key := m.KeyType{
		Key:     u.GenerateRandomPassword(20),
		Created: time.Now(),
	}

	gallery.Keys = append(gallery.Keys, key)

	err = tx.Save(&gallery)
	if err != nil {
		return
	}

	// commit
	tx.Commit()

	return

}