diff --git a/internal/api/album.go b/internal/api/album.go index 95f156fe3..e08ff000e 100644 --- a/internal/api/album.go +++ b/internal/api/album.go @@ -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) diff --git a/internal/api/batch.go b/internal/api/batch.go index aaa85b9a9..51b56bde5 100644 --- a/internal/api/batch.go +++ b/internal/api/batch.go @@ -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 } diff --git a/internal/api/errors.go b/internal/api/errors.go index cb6f5869c..ace065781 100644 --- a/internal/api/errors.go +++ b/internal/api/errors.go @@ -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())} ) diff --git a/internal/api/index.go b/internal/api/index.go index 225c3906d..18f80d071 100644 --- a/internal/api/index.go +++ b/internal/api/index.go @@ -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 } diff --git a/internal/api/label.go b/internal/api/label.go index 75611c4e2..acac9e7f5 100644 --- a/internal/api/label.go +++ b/internal/api/label.go @@ -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 } diff --git a/internal/api/photo.go b/internal/api/photo.go index 293659161..0e42ba774 100644 --- a/internal/api/photo.go +++ b/internal/api/photo.go @@ -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 } diff --git a/internal/api/photo_search.go b/internal/api/photo_search.go index 3be2f3a9f..ef91f8d32 100644 --- a/internal/api/photo_search.go +++ b/internal/api/photo_search.go @@ -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 } diff --git a/internal/api/session.go b/internal/api/session.go index 66ccbc984..aa2abb574 100644 --- a/internal/api/session.go +++ b/internal/api/session.go @@ -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 } diff --git a/internal/api/settings.go b/internal/api/settings.go index 24ff0cf7f..0a77eca00 100644 --- a/internal/api/settings.go +++ b/internal/api/settings.go @@ -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 } diff --git a/internal/api/upload.go b/internal/api/upload.go index 7e463842a..04300f1f8 100644 --- a/internal/api/upload.go +++ b/internal/api/upload.go @@ -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 } diff --git a/internal/api/zip.go b/internal/api/zip.go index 11c9c9ce9..449c8967e 100644 --- a/internal/api/zip.go +++ b/internal/api/zip.go @@ -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) diff --git a/internal/capture/capture.go b/internal/capture/capture.go new file mode 100644 index 000000000..f3a348fd2 --- /dev/null +++ b/internal/capture/capture.go @@ -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 diff --git a/internal/capture/capture_test.go b/internal/capture/capture_test.go new file mode 100644 index 000000000..0fdfc0ab5 --- /dev/null +++ b/internal/capture/capture_test.go @@ -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) +} diff --git a/internal/util/capture.go b/internal/capture/output.go similarity index 88% rename from internal/util/capture.go rename to internal/capture/output.go index 57b9cef84..1e5114a2b 100644 --- a/internal/util/capture.go +++ b/internal/capture/output.go @@ -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) diff --git a/internal/util/capture_test.go b/internal/capture/output_test.go similarity index 67% rename from internal/util/capture_test.go rename to internal/capture/output_test.go index 4cd167959..b47f2830b 100644 --- a/internal/util/capture_test.go +++ b/internal/capture/output_test.go @@ -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") }) diff --git a/internal/util/time.go b/internal/capture/time.go similarity index 59% rename from internal/util/time.go rename to internal/capture/time.go index 7f312173c..03edad75d 100644 --- a/internal/util/time.go +++ b/internal/capture/time.go @@ -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) } diff --git a/internal/util/time_test.go b/internal/capture/time_test.go similarity index 64% rename from internal/util/time_test.go rename to internal/capture/time_test.go index 217190c2c..b691b99f0 100644 --- a/internal/util/time_test.go +++ b/internal/capture/time_test.go @@ -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 [") } diff --git a/internal/commands/config_test.go b/internal/commands/config_test.go index 314c50e46..30e001f59 100644 --- a/internal/commands/config_test.go +++ b/internal/commands/config_test.go @@ -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) }) diff --git a/internal/entity/location.go b/internal/entity/location.go index 16de657df..d99992564 100644 --- a/internal/entity/location.go +++ b/internal/entity/location.go @@ -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 } diff --git a/internal/entity/photo.go b/internal/entity/photo.go index 1ddea6e67..dc805a152 100644 --- a/internal/entity/photo.go +++ b/internal/entity/photo.go @@ -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) diff --git a/internal/util/date.go b/internal/ling/date.go similarity index 93% rename from internal/util/date.go rename to internal/ling/date.go index 2737d2382..616518886 100644 --- a/internal/util/date.go +++ b/internal/ling/date.go @@ -1,4 +1,4 @@ -package util +package ling var Months = [...]string{ "Unknown", diff --git a/internal/util/date_test.go b/internal/ling/date_test.go similarity index 94% rename from internal/util/date_test.go rename to internal/ling/date_test.go index 65d61cefd..10df42c28 100644 --- a/internal/util/date_test.go +++ b/internal/ling/date_test.go @@ -1,4 +1,4 @@ -package util +package ling import ( "testing" diff --git a/internal/util/gen.go b/internal/ling/gen.go similarity index 100% rename from internal/util/gen.go rename to internal/ling/gen.go diff --git a/internal/util/keywords.go b/internal/ling/keywords.go similarity index 96% rename from internal/util/keywords.go rename to internal/ling/keywords.go index c7756e4fc..bbda53631 100644 --- a/internal/util/keywords.go +++ b/internal/ling/keywords.go @@ -1,4 +1,4 @@ -package util +package ling import ( "regexp" diff --git a/internal/util/keywords_test.go b/internal/ling/keywords_test.go similarity index 96% rename from internal/util/keywords_test.go rename to internal/ling/keywords_test.go index c99af5e12..717e2033d 100644 --- a/internal/util/keywords_test.go +++ b/internal/ling/keywords_test.go @@ -1,4 +1,4 @@ -package util +package ling import ( "testing" diff --git a/internal/util/util.go b/internal/ling/ling.go similarity index 75% rename from internal/util/util.go rename to internal/ling/ling.go index 3e2bc076f..ffb4377f5 100644 --- a/internal/util/util.go +++ b/internal/ling/ling.go @@ -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" diff --git a/internal/util/util_test.go b/internal/ling/ling_test.go similarity index 95% rename from internal/util/util_test.go rename to internal/ling/ling_test.go index fd188d4a8..db7aa147c 100644 --- a/internal/util/util_test.go +++ b/internal/ling/ling_test.go @@ -1,4 +1,4 @@ -package util +package ling import ( "bytes" diff --git a/internal/util/resources/stopwords.txt b/internal/ling/resources/stopwords.txt similarity index 100% rename from internal/util/resources/stopwords.txt rename to internal/ling/resources/stopwords.txt diff --git a/internal/util/stopwords.go b/internal/ling/stopwords.go similarity index 99% rename from internal/util/stopwords.go rename to internal/ling/stopwords.go index c04405ecb..3ce56477a 100644 --- a/internal/util/stopwords.go +++ b/internal/ling/stopwords.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -package util +package ling var Stopwords = map[string]bool{ "abc": true, diff --git a/internal/util/strings.go b/internal/ling/strings.go similarity index 98% rename from internal/util/strings.go rename to internal/ling/strings.go index a2726b7e7..bdcc7083a 100644 --- a/internal/util/strings.go +++ b/internal/ling/strings.go @@ -1,4 +1,4 @@ -package util +package ling import ( "regexp" diff --git a/internal/util/strings_test.go b/internal/ling/strings_test.go similarity index 99% rename from internal/util/strings_test.go rename to internal/ling/strings_test.go index 09e268acf..90abb3726 100644 --- a/internal/util/strings_test.go +++ b/internal/ling/strings_test.go @@ -1,4 +1,4 @@ -package util +package ling import ( "testing" diff --git a/internal/maps/osm/location.go b/internal/maps/osm/location.go index 9423205fd..1d50e82c2 100644 --- a/internal/maps/osm/location.go +++ b/internal/maps/osm/location.go @@ -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 { diff --git a/internal/maps/osm/title.go b/internal/maps/osm/title.go index 274256949..2cd592454 100644 --- a/internal/maps/osm/title.go +++ b/internal/maps/osm/title.go @@ -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)) } diff --git a/internal/maps/places/location.go b/internal/maps/places/location.go index 5fa018e82..65bb8a022 100644 --- a/internal/maps/places/location.go +++ b/internal/maps/places/location.go @@ -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 { diff --git a/internal/photoprism/index_mediafile.go b/internal/photoprism/index_mediafile.go index f3b53f17f..e5decede8 100644 --- a/internal/photoprism/index_mediafile.go +++ b/internal/photoprism/index_mediafile.go @@ -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 { diff --git a/internal/photoprism/label.go b/internal/photoprism/label.go index 0e83efdf6..2e784d53d 100644 --- a/internal/photoprism/label.go +++ b/internal/photoprism/label.go @@ -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 = "" } diff --git a/internal/photoprism/thumbnails.go b/internal/photoprism/thumbnails.go index 88d9d5fc3..a07335f63 100644 --- a/internal/photoprism/thumbnails.go +++ b/internal/photoprism/thumbnails.go @@ -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() diff --git a/internal/query/album.go b/internal/query/album.go index cf1b5a058..7707f2116 100644 --- a/internal/query/album.go +++ b/internal/query/album.go @@ -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() diff --git a/internal/query/label.go b/internal/query/label.go index b3e0daaad..eb29644b7 100644 --- a/internal/query/label.go +++ b/internal/query/label.go @@ -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() diff --git a/internal/query/photo.go b/internal/query/photo.go index 7187235e5..10dae9620 100644 --- a/internal/query/photo.go +++ b/internal/query/photo.go @@ -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() diff --git a/internal/util/testdata/test.jpg b/internal/util/testdata/test.jpg deleted file mode 100644 index 0c8c04edb..000000000 Binary files a/internal/util/testdata/test.jpg and /dev/null differ