mirror of
https://github.com/photoprism/photoprism.git
synced 2025-10-05 08:47:12 +08:00
Albums: Zip download #15
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
@@ -7,16 +7,13 @@ import (
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/photoprism/photoprism/internal/config"
|
||||
"github.com/photoprism/photoprism/internal/form"
|
||||
"github.com/photoprism/photoprism/internal/models"
|
||||
"github.com/photoprism/photoprism/internal/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type PhotoUUIDs struct {
|
||||
Photos []string `json:"photos"`
|
||||
}
|
||||
|
||||
// POST /api/v1/batch/photos/delete
|
||||
func BatchPhotosDelete(router *gin.RouterGroup, conf *config.Config) {
|
||||
router.POST("/batch/photos/delete", func(c *gin.Context) {
|
||||
@@ -27,24 +24,24 @@ func BatchPhotosDelete(router *gin.RouterGroup, conf *config.Config) {
|
||||
|
||||
start := time.Now()
|
||||
|
||||
var params PhotoUUIDs
|
||||
var f form.PhotoUUIDs
|
||||
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
if err := c.BindJSON(&f); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Photos) == 0 {
|
||||
if len(f.Photos) == 0 {
|
||||
log.Error("no photos selected")
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("deleting photos: %#v", params.Photos)
|
||||
log.Infof("deleting photos: %#v", f.Photos)
|
||||
|
||||
db := conf.Db()
|
||||
|
||||
db.Where("photo_uuid IN (?)", params.Photos).Delete(&models.Photo{})
|
||||
db.Where("photo_uuid IN (?)", f.Photos).Delete(&models.Photo{})
|
||||
|
||||
elapsed := time.Since(start)
|
||||
|
||||
@@ -62,24 +59,24 @@ func BatchPhotosPrivate(router *gin.RouterGroup, conf *config.Config) {
|
||||
|
||||
start := time.Now()
|
||||
|
||||
var params PhotoUUIDs
|
||||
var f form.PhotoUUIDs
|
||||
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
if err := c.BindJSON(&f); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Photos) == 0 {
|
||||
if len(f.Photos) == 0 {
|
||||
log.Error("no photos selected")
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("marking photos as private: %#v", params.Photos)
|
||||
log.Infof("marking photos as private: %#v", f.Photos)
|
||||
|
||||
db := conf.Db()
|
||||
|
||||
db.Model(models.Photo{}).Where("photo_uuid IN (?)", params.Photos).UpdateColumn("photo_private", gorm.Expr("IF (`photo_private`, 0, 1)"))
|
||||
db.Model(models.Photo{}).Where("photo_uuid IN (?)", f.Photos).UpdateColumn("photo_private", gorm.Expr("IF (`photo_private`, 0, 1)"))
|
||||
|
||||
elapsed := time.Since(start)
|
||||
|
||||
@@ -97,25 +94,25 @@ func BatchPhotosStory(router *gin.RouterGroup, conf *config.Config) {
|
||||
|
||||
start := time.Now()
|
||||
|
||||
var params PhotoUUIDs
|
||||
var f form.PhotoUUIDs
|
||||
|
||||
if err := c.BindJSON(¶ms); err != nil {
|
||||
if err := c.BindJSON(&f); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
|
||||
return
|
||||
}
|
||||
|
||||
if len(params.Photos) == 0 {
|
||||
if len(f.Photos) == 0 {
|
||||
log.Error("no photos selected")
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("marking photos as story: %#v", params.Photos)
|
||||
log.Infof("marking photos as story: %#v", f.Photos)
|
||||
|
||||
db := conf.Db()
|
||||
|
||||
db.Model(models.Photo{}).Where("photo_uuid IN (?)", params.Photos).Updates(map[string]interface{}{
|
||||
"photo_story": gorm.Expr("IF (`photo_story`, 0, 1)"),
|
||||
db.Model(models.Photo{}).Where("photo_uuid IN (?)", f.Photos).Updates(map[string]interface{}{
|
||||
"photo_story": gorm.Expr("IF (`photo_story`, 0, 1)"),
|
||||
})
|
||||
|
||||
elapsed := time.Since(start)
|
||||
|
Reference in New Issue
Block a user