Backend: Split up "util" package

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer
2020-01-06 15:22:46 +01:00
parent e43983d579
commit f6d4e62ea8
41 changed files with 150 additions and 117 deletions

View File

@@ -21,7 +21,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// GET /api/v1/albums
@@ -33,13 +33,13 @@ func GetAlbums(router *gin.RouterGroup, conf *config.Config) {
err := c.MustBindWith(&f, binding.Form)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
result, err := q.Albums(f)
if err != nil {
c.AbortWithStatusJSON(400, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(400, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -58,7 +58,7 @@ func GetAlbum(router *gin.RouterGroup, conf *config.Config) {
m, err := q.FindAlbumByUUID(id)
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -77,7 +77,7 @@ func CreateAlbum(router *gin.RouterGroup, conf *config.Config) {
var f form.Album
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -117,7 +117,7 @@ func UpdateAlbum(router *gin.RouterGroup, conf *config.Config) {
var f form.Album
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -127,7 +127,7 @@ func UpdateAlbum(router *gin.RouterGroup, conf *config.Config) {
m, err := q.FindAlbumByUUID(id)
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -155,7 +155,7 @@ func DeleteAlbum(router *gin.RouterGroup, conf *config.Config) {
m, err := q.FindAlbumByUUID(id)
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -184,7 +184,7 @@ func LikeAlbum(router *gin.RouterGroup, conf *config.Config) {
album, err := q.FindAlbumByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -212,7 +212,7 @@ func DislikeAlbum(router *gin.RouterGroup, conf *config.Config) {
album, err := q.FindAlbumByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -236,13 +236,13 @@ func AddPhotosToAlbum(router *gin.RouterGroup, conf *config.Config) {
var f form.PhotoUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}
@@ -250,7 +250,7 @@ func AddPhotosToAlbum(router *gin.RouterGroup, conf *config.Config) {
a, err := q.FindAlbumByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -287,13 +287,13 @@ func RemovePhotosFromAlbum(router *gin.RouterGroup, conf *config.Config) {
var f form.PhotoUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}
@@ -301,7 +301,7 @@ func RemovePhotosFromAlbum(router *gin.RouterGroup, conf *config.Config) {
a, err := q.FindAlbumByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -325,7 +325,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) {
a, err := q.FindAlbumByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -336,7 +336,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) {
})
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -347,7 +347,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) {
if err := os.MkdirAll(zipPath, 0700); err != nil {
log.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": util.UcFirst("failed to create zip directory")})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": ling.UcFirst("failed to create zip directory")})
return
}
@@ -355,7 +355,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) {
if err != nil {
log.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -371,7 +371,7 @@ func DownloadAlbum(router *gin.RouterGroup, conf *config.Config) {
if file.Exists(fileName) {
if err := addFileToZip(zipWriter, fileName, fileAlias); err != nil {
log.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": util.UcFirst("failed to create zip file")})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": ling.UcFirst("failed to create zip file")})
return
}
log.Infof("album: added \"%s\" as \"%s\"", f.FileName, fileAlias)

View File

@@ -10,7 +10,7 @@ import (
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
"github.com/gin-gonic/gin"
)
@@ -28,13 +28,13 @@ func BatchPhotosDelete(router *gin.RouterGroup, conf *config.Config) {
var f form.PhotoUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}
@@ -65,13 +65,13 @@ func BatchPhotosRestore(router *gin.RouterGroup, conf *config.Config) {
var f form.PhotoUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}
@@ -101,13 +101,13 @@ func BatchAlbumsDelete(router *gin.RouterGroup, conf *config.Config) {
var f form.AlbumUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Albums) == 0 {
log.Error("no albums selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no albums selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no albums selected")})
return
}
@@ -137,13 +137,13 @@ func BatchPhotosPrivate(router *gin.RouterGroup, conf *config.Config) {
var f form.PhotoUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}
@@ -172,13 +172,13 @@ func BatchPhotosStory(router *gin.RouterGroup, conf *config.Config) {
var f form.PhotoUUIDs
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}

View File

@@ -3,11 +3,11 @@ package api
import (
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
var (
ErrReadOnly = gin.H{"code": 403, "error": util.UcFirst(config.ErrReadOnly.Error())}
ErrUnauthorized = gin.H{"code": 401, "error": util.UcFirst(config.ErrUnauthorized.Error())}
ErrUploadNSFW = gin.H{"code": 403, "error": util.UcFirst(config.ErrUploadNSFW.Error())}
ErrReadOnly = gin.H{"code": 403, "error": ling.UcFirst(config.ErrReadOnly.Error())}
ErrUnauthorized = gin.H{"code": 401, "error": ling.UcFirst(config.ErrUnauthorized.Error())}
ErrUploadNSFW = gin.H{"code": 403, "error": ling.UcFirst(config.ErrUploadNSFW.Error())}
)

View File

@@ -12,7 +12,7 @@ import (
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/nsfw"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
var ind *photoprism.Index
@@ -51,7 +51,7 @@ func StartIndexing(router *gin.RouterGroup, conf *config.Config) {
var f form.IndexOptions
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -16,7 +16,7 @@ import (
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/internal/thumb"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// GET /api/v1/labels
@@ -28,13 +28,13 @@ func GetLabels(router *gin.RouterGroup, conf *config.Config) {
err := c.MustBindWith(&f, binding.Form)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
result, err := q.Labels(f)
if err != nil {
c.AbortWithStatusJSON(400, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(400, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -61,7 +61,7 @@ func LikeLabel(router *gin.RouterGroup, conf *config.Config) {
label, err := q.FindLabelByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -94,7 +94,7 @@ func DislikeLabel(router *gin.RouterGroup, conf *config.Config) {
label, err := q.FindLabelByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -9,7 +9,7 @@ import (
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/file"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
"github.com/gin-gonic/gin"
)
@@ -50,12 +50,12 @@ func UpdatePhoto(router *gin.RouterGroup, conf *config.Config) {
m, err := q.FindPhotoByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if err := c.BindJSON(&m); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -116,7 +116,7 @@ func LikePhoto(router *gin.RouterGroup, conf *config.Config) {
m, err := q.FindPhotoByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -146,7 +146,7 @@ func DislikePhoto(router *gin.RouterGroup, conf *config.Config) {
m, err := q.FindPhotoByUUID(c.Param("uuid"))
if err != nil {
c.AbortWithStatusJSON(404, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(404, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
@@ -35,14 +35,14 @@ func GetPhotos(router *gin.RouterGroup, conf *config.Config) {
err := c.MustBindWith(&f, binding.Form)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
result, err := q.Photos(f)
if err != nil {
c.AbortWithStatusJSON(400, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(400, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/session"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// POST /api/v1/session
@@ -16,7 +16,7 @@ func CreateSession(router *gin.RouterGroup, conf *config.Config) {
var f form.Login
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -6,7 +6,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// GET /api/v1/settings
@@ -34,7 +34,7 @@ func SaveSettings(router *gin.RouterGroup, conf *config.Config) {
s := conf.Settings()
if err := c.BindJSON(s); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -9,7 +9,7 @@ import (
"time"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
"github.com/gin-gonic/gin"
)
@@ -33,7 +33,7 @@ func Upload(router *gin.RouterGroup, conf *config.Config) {
f, err := c.MultipartForm()
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -44,7 +44,7 @@ func Upload(router *gin.RouterGroup, conf *config.Config) {
p := path.Join(conf.ImportPath(), "upload", subPath)
if err := os.MkdirAll(p, os.ModePerm); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -54,7 +54,7 @@ func Upload(router *gin.RouterGroup, conf *config.Config) {
log.Debugf("upload: saving file \"%s\"", file.Filename)
if err := c.SaveUploadedFile(file, filename); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}

View File

@@ -15,7 +15,7 @@ import (
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/query"
"github.com/photoprism/photoprism/internal/rnd"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
"github.com/gin-gonic/gin"
)
@@ -27,13 +27,13 @@ func CreateZip(router *gin.RouterGroup, conf *config.Config) {
start := time.Now()
if err := c.BindJSON(&f); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst(err.Error())})
return
}
if len(f.Photos) == 0 {
log.Error("no photos selected")
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": util.UcFirst("no photos selected")})
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": ling.UcFirst("no photos selected")})
return
}
@@ -53,7 +53,7 @@ func CreateZip(router *gin.RouterGroup, conf *config.Config) {
if err := os.MkdirAll(zipPath, 0700); err != nil {
log.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": util.UcFirst("failed to create zip directory")})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": ling.UcFirst("failed to create zip directory")})
return
}
@@ -61,7 +61,7 @@ func CreateZip(router *gin.RouterGroup, conf *config.Config) {
if err != nil {
log.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": util.UcFirst(err.Error())})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": ling.UcFirst(err.Error())})
return
}
@@ -77,7 +77,7 @@ func CreateZip(router *gin.RouterGroup, conf *config.Config) {
if file.Exists(fileName) {
if err := addFileToZip(zipWriter, fileName, fileAlias); err != nil {
log.Error(err)
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": util.UcFirst("failed to create zip file")})
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"error": ling.UcFirst("failed to create zip file")})
return
}
log.Infof("zip: added \"%s\" as \"%s\"", f.FileName, fileAlias)

View File

@@ -0,0 +1,14 @@
/*
This package contains profiling functions, mainly for testing.
Additional information can be found in our Developer Guide:
https://github.com/photoprism/photoprism/wiki
*/
package capture
import (
"github.com/photoprism/photoprism/internal/event"
)
var log = event.Log

View File

@@ -0,0 +1,19 @@
package capture
import (
"bytes"
"os"
"testing"
"github.com/sirupsen/logrus"
)
var logBuffer bytes.Buffer
func TestMain(m *testing.M) {
log = logrus.StandardLogger()
log.Out = &logBuffer
log.SetLevel(logrus.DebugLevel)
code := m.Run()
os.Exit(code)
}

View File

@@ -1,4 +1,4 @@
package util
package capture
import (
"bytes"
@@ -7,7 +7,7 @@ import (
)
// Returns output to stdout and stderr for testing
func CaptureOutput(f func()) string {
func Output(f func()) string {
r, w, err := os.Pipe()
if err != nil {
panic(err)

View File

@@ -1,4 +1,4 @@
package util
package capture
import (
"fmt"
@@ -8,8 +8,8 @@ import (
"github.com/stretchr/testify/assert"
)
func TestCaptureOutput(t *testing.T) {
result := CaptureOutput(func() {
func TestOutput(t *testing.T) {
result := Output(func() {
fmt.Fprint(os.Stdout, "foo")
fmt.Fprint(os.Stderr, "bar")
})

View File

@@ -1,10 +1,10 @@
package util
package capture
import (
"time"
)
func ProfileTime(start time.Time, name string) {
func Time(start time.Time, name string) {
elapsed := time.Since(start)
log.Debugf("%s [%s]", name, elapsed)
}

View File

@@ -1,4 +1,4 @@
package util
package capture
import (
"fmt"
@@ -8,9 +8,9 @@ import (
"github.com/stretchr/testify/assert"
)
func TestProfileTime(t *testing.T) {
func TestTime(t *testing.T) {
start := time.Now()
time.Sleep(1 * time.Millisecond)
ProfileTime(start, fmt.Sprintf("%s", "Successful test"))
Time(start, fmt.Sprintf("%s", "Successful test"))
assert.Contains(t, logBuffer.String(), "Successful test [")
}

View File

@@ -3,8 +3,8 @@ package commands
import (
"testing"
"github.com/photoprism/photoprism/internal/capture"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/util"
"github.com/stretchr/testify/assert"
)
@@ -13,7 +13,7 @@ func TestConfigCommand(t *testing.T) {
ctx := config.CliTestContext()
output := util.CaptureOutput(func() {
output := capture.Output(func() {
err = ConfigCommand.Run(ctx)
})

View File

@@ -8,7 +8,7 @@ import (
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/maps"
"github.com/photoprism/photoprism/internal/s2"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
var locationMutex = sync.Mutex{}
@@ -93,9 +93,9 @@ func (m *Location) Keywords() []string {
strings.ToLower(m.Category()),
}
result = append(result, util.Keywords(m.Name())...)
result = append(result, util.Keywords(m.Label())...)
result = append(result, util.Keywords(m.Notes())...)
result = append(result, ling.Keywords(m.Name())...)
result = append(result, ling.Keywords(m.Label())...)
result = append(result, ling.Keywords(m.Notes())...)
return result
}

View File

@@ -5,7 +5,7 @@ import (
"time"
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// A photo can have multiple images and sidecar files
@@ -70,8 +70,8 @@ func (m *Photo) IndexKeywords(keywords []string, db *gorm.DB) {
var keywordIds []uint
// Index title and description
keywords = append(keywords, util.Keywords(m.PhotoTitle)...)
keywords = append(keywords, util.Keywords(m.PhotoDescription)...)
keywords = append(keywords, ling.Keywords(m.PhotoTitle)...)
keywords = append(keywords, ling.Keywords(m.PhotoDescription)...)
last := ""
sort.Strings(keywords)

View File

@@ -1,4 +1,4 @@
package util
package ling
var Months = [...]string{
"Unknown",

View File

@@ -1,4 +1,4 @@
package util
package ling
import (
"testing"

View File

@@ -1,4 +1,4 @@
package util
package ling
import (
"regexp"

View File

@@ -1,4 +1,4 @@
package util
package ling
import (
"testing"

View File

@@ -1,11 +1,11 @@
/*
Package config contains filesystem related utility functions.
Package ling contains linguistics related functionality.
Additional information can be found in our Developer Guide:
https://github.com/photoprism/photoprism/wiki
*/
package util
package ling
import (
"github.com/photoprism/photoprism/internal/event"

View File

@@ -1,4 +1,4 @@
package util
package ling
import (
"bytes"

View File

@@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
package util
package ling
var Stopwords = map[string]bool{
"abc": true,

View File

@@ -1,4 +1,4 @@
package util
package ling
import (
"regexp"

View File

@@ -1,4 +1,4 @@
package util
package ling
import (
"testing"

View File

@@ -10,7 +10,7 @@ import (
"github.com/melihmucuk/geocache"
"github.com/photoprism/photoprism/internal/s2"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
type Location struct {
@@ -123,7 +123,7 @@ func (l Location) CountryCode() (result string) {
}
func (l Location) Keywords() (result []string) {
return util.Keywords(l.LocDisplayName)
return ling.Keywords(l.LocDisplayName)
}
func (l Location) Source() string {

View File

@@ -3,7 +3,7 @@ package osm
import (
"strings"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
var labelTitles = map[string]string{
@@ -33,5 +33,5 @@ func (l Location) Name() (result string) {
result = result[:i]
}
return util.Title(strings.TrimSpace(result))
return ling.Title(strings.TrimSpace(result))
}

View File

@@ -7,7 +7,7 @@ import (
gc "github.com/patrickmn/go-cache"
"github.com/photoprism/photoprism/internal/s2"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// Location
@@ -113,7 +113,7 @@ func (l Location) Longitude() (result float64) {
}
func (l Location) Keywords() (result []string) {
return util.Keywords(l.Label())
return ling.Keywords(l.Label())
}
func (l Location) Source() string {

View File

@@ -11,7 +11,7 @@ import (
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
const (
@@ -130,7 +130,7 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions) IndexResult {
if photo.NoTitle() || (fileChanged || o.UpdateTitle) && photo.PhotoTitleChanged == false && photo.NoLocation() {
if len(labels) > 0 && labels[0].Priority >= -1 && labels[0].Uncertainty <= 85 && labels[0].Name != "" {
photo.PhotoTitle = fmt.Sprintf("%s / %s", util.Title(labels[0].Name), m.DateCreated().Format("2006"))
photo.PhotoTitle = fmt.Sprintf("%s / %s", ling.Title(labels[0].Name), m.DateCreated().Format("2006"))
} else if !photo.TakenAtLocal.IsZero() {
var daytimeString string
hour := photo.TakenAtLocal.Hour()
@@ -407,13 +407,13 @@ func (ind *Index) indexLocation(mediaFile *MediaFile, photo *entity.Photo, label
if title := labels.Title(location.Name()); title != "" { // TODO: User defined title format
log.Infof("index: using label \"%s\" to create photo title", title)
if location.NoCity() || location.LongCity() || location.CityContains(title) {
photo.PhotoTitle = fmt.Sprintf("%s / %s / %s", util.Title(title), location.CountryName(), photo.TakenAt.Format("2006"))
photo.PhotoTitle = fmt.Sprintf("%s / %s / %s", ling.Title(title), location.CountryName(), photo.TakenAt.Format("2006"))
} else {
photo.PhotoTitle = fmt.Sprintf("%s / %s / %s", util.Title(title), location.City(), photo.TakenAt.Format("2006"))
photo.PhotoTitle = fmt.Sprintf("%s / %s / %s", ling.Title(title), location.City(), photo.TakenAt.Format("2006"))
}
} else if location.Name() != "" && location.City() != "" {
if len(location.Name()) > 45 {
photo.PhotoTitle = util.Title(location.Name())
photo.PhotoTitle = ling.Title(location.Name())
} else if len(location.Name()) > 20 || len(location.City()) > 16 || strings.Contains(location.Name(), location.City()) {
photo.PhotoTitle = fmt.Sprintf("%s / %s", location.Name(), photo.TakenAt.Format("2006"))
} else {

View File

@@ -4,7 +4,7 @@ import (
"sort"
"strings"
"github.com/photoprism/photoprism/internal/util"
"github.com/photoprism/photoprism/internal/ling"
)
// Label represents a MediaFile label (automatically created).
@@ -54,10 +54,10 @@ func (l Labels) AppendLabel(label Label) Labels {
func (l Labels) Keywords() (result []string) {
for _, label := range l {
result = append(result, util.Keywords(label.Name)...)
result = append(result, ling.Keywords(label.Name)...)
for _, c := range label.Categories {
result = append(result, util.Keywords(c)...)
result = append(result, ling.Keywords(c)...)
}
}
@@ -67,7 +67,7 @@ func (l Labels) Keywords() (result []string) {
func (l Labels) Title(fallback string) string {
fallbackRunes := len([]rune(fallback))
if fallbackRunes < 2 || fallbackRunes > 25 || util.ContainsNumber(fallback) {
if fallbackRunes < 2 || fallbackRunes > 25 || ling.ContainsNumber(fallback) {
fallback = ""
}

View File

@@ -8,12 +8,12 @@ import (
"strings"
"time"
"github.com/photoprism/photoprism/internal/capture"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/file"
"github.com/photoprism/photoprism/internal/thumb"
"github.com/disintegration/imaging"
"github.com/photoprism/photoprism/internal/util"
)
// CreateThumbnailsFromOriginals creates default thumbnails for all originals.
@@ -83,7 +83,7 @@ func (m *MediaFile) Resample(path string, typeName string) (img image.Image, err
}
func (m *MediaFile) CreateDefaultThumbnails(thumbPath string, force bool) (err error) {
defer util.ProfileTime(time.Now(), fmt.Sprintf("creating thumbnails for \"%s\"", m.Filename()))
defer capture.Time(time.Now(), fmt.Sprintf("creating thumbnails for \"%s\"", m.Filename()))
hash := m.Hash()

View File

@@ -5,9 +5,9 @@ import (
"strings"
"time"
"github.com/photoprism/photoprism/internal/capture"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/util"
)
// AlbumResult contains found albums
@@ -54,7 +54,7 @@ func (s *Repo) Albums(f form.AlbumSearch) (results []AlbumResult, err error) {
return results, err
}
defer util.ProfileTime(time.Now(), fmt.Sprintf("search: %+v", f))
defer capture.Time(time.Now(), fmt.Sprintf("search: %+v", f))
q := s.db.NewScope(nil).DB()

View File

@@ -6,9 +6,9 @@ import (
"time"
"github.com/gosimple/slug"
"github.com/photoprism/photoprism/internal/capture"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/util"
)
// LabelResult contains found labels
@@ -91,7 +91,7 @@ func (s *Repo) Labels(f form.LabelSearch) (results []LabelResult, err error) {
return results, err
}
defer util.ProfileTime(time.Now(), fmt.Sprintf("search: %+v", f))
defer capture.Time(time.Now(), fmt.Sprintf("search: %+v", f))
q := s.db.NewScope(nil).DB()

View File

@@ -6,9 +6,9 @@ import (
"time"
"github.com/gosimple/slug"
"github.com/photoprism/photoprism/internal/capture"
"github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/form"
"github.com/photoprism/photoprism/internal/util"
)
// PhotoResult contains found photos and their main file plus other meta data.
@@ -103,7 +103,7 @@ func (s *Repo) Photos(f form.PhotoSearch) (results []PhotoResult, err error) {
return results, err
}
defer util.ProfileTime(time.Now(), fmt.Sprintf("search: %+v", f))
defer capture.Time(time.Now(), fmt.Sprintf("search: %+v", f))
q := s.db.NewScope(nil).DB()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB