Backend: Rename "models" package to "entity"
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
5aa116ee06
commit
4e06deda76
|
@ -10,9 +10,9 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
"github.com/photoprism/photoprism/internal/form"
|
"github.com/photoprism/photoprism/internal/form"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/repo"
|
"github.com/photoprism/photoprism/internal/repo"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -78,7 +78,7 @@ func CreateAlbum(router *gin.RouterGroup, conf *config.Config) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
m := models.NewAlbum(f.AlbumName)
|
m := entity.NewAlbum(f.AlbumName)
|
||||||
|
|
||||||
if res := conf.Db().Create(m); res.Error != nil {
|
if res := conf.Db().Create(m); res.Error != nil {
|
||||||
log.Error(res.Error.Error())
|
log.Error(res.Error.Error())
|
||||||
|
@ -245,14 +245,14 @@ func AddPhotosToAlbum(router *gin.RouterGroup, conf *config.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db := conf.Db()
|
db := conf.Db()
|
||||||
var added []*models.PhotoAlbum
|
var added []*entity.PhotoAlbum
|
||||||
var failed []string
|
var failed []string
|
||||||
|
|
||||||
for _, photoUUID := range f.Photos {
|
for _, photoUUID := range f.Photos {
|
||||||
if p, err := r.FindPhotoByUUID(photoUUID); err != nil {
|
if p, err := r.FindPhotoByUUID(photoUUID); err != nil {
|
||||||
failed = append(failed, photoUUID)
|
failed = append(failed, photoUUID)
|
||||||
} else {
|
} else {
|
||||||
added = append(added, models.NewPhotoAlbum(p.PhotoUUID, a.AlbumUUID).FirstOrCreate(db))
|
added = append(added, entity.NewPhotoAlbum(p.PhotoUUID, a.AlbumUUID).FirstOrCreate(db))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ func RemovePhotosFromAlbum(router *gin.RouterGroup, conf *config.Config) {
|
||||||
|
|
||||||
db := conf.Db()
|
db := conf.Db()
|
||||||
|
|
||||||
db.Where("album_uuid = ? AND photo_uuid IN (?)", a.AlbumUUID, f.Photos).Delete(&models.PhotoAlbum{})
|
db.Where("album_uuid = ? AND photo_uuid IN (?)", a.AlbumUUID, f.Photos).Delete(&entity.PhotoAlbum{})
|
||||||
|
|
||||||
event.Success(fmt.Sprintf("photos removed from %s", a.AlbumName))
|
event.Success(fmt.Sprintf("photos removed from %s", a.AlbumName))
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/photoprism/photoprism/internal/config"
|
"github.com/photoprism/photoprism/internal/config"
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
"github.com/photoprism/photoprism/internal/form"
|
"github.com/photoprism/photoprism/internal/form"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -42,7 +42,7 @@ func BatchPhotosDelete(router *gin.RouterGroup, conf *config.Config) {
|
||||||
|
|
||||||
db := conf.Db()
|
db := conf.Db()
|
||||||
|
|
||||||
db.Where("photo_uuid IN (?)", f.Photos).Delete(&models.Photo{})
|
db.Where("photo_uuid IN (?)", f.Photos).Delete(&entity.Photo{})
|
||||||
|
|
||||||
elapsed := int(time.Since(start).Seconds())
|
elapsed := int(time.Since(start).Seconds())
|
||||||
|
|
||||||
|
@ -79,8 +79,8 @@ func BatchAlbumsDelete(router *gin.RouterGroup, conf *config.Config) {
|
||||||
|
|
||||||
db := conf.Db()
|
db := conf.Db()
|
||||||
|
|
||||||
db.Where("album_uuid IN (?)", f.Albums).Delete(&models.Album{})
|
db.Where("album_uuid IN (?)", f.Albums).Delete(&entity.Album{})
|
||||||
db.Where("album_uuid IN (?)", f.Albums).Delete(&models.PhotoAlbum{})
|
db.Where("album_uuid IN (?)", f.Albums).Delete(&entity.PhotoAlbum{})
|
||||||
|
|
||||||
event.Publish("config.updated", event.Data(conf.ClientConfig()))
|
event.Publish("config.updated", event.Data(conf.ClientConfig()))
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ func BatchPhotosPrivate(router *gin.RouterGroup, conf *config.Config) {
|
||||||
|
|
||||||
db := conf.Db()
|
db := conf.Db()
|
||||||
|
|
||||||
db.Model(models.Photo{}).Where("photo_uuid IN (?)", f.Photos).UpdateColumn("photo_private", gorm.Expr("IF (`photo_private`, 0, 1)"))
|
db.Model(entity.Photo{}).Where("photo_uuid IN (?)", f.Photos).UpdateColumn("photo_private", gorm.Expr("IF (`photo_private`, 0, 1)"))
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ func BatchPhotosStory(router *gin.RouterGroup, conf *config.Config) {
|
||||||
|
|
||||||
db := conf.Db()
|
db := conf.Db()
|
||||||
|
|
||||||
db.Model(models.Photo{}).Where("photo_uuid IN (?)", f.Photos).Updates(map[string]interface{}{
|
db.Model(entity.Photo{}).Where("photo_uuid IN (?)", f.Photos).Updates(map[string]interface{}{
|
||||||
"photo_story": gorm.Expr("IF (`photo_story`, 0, 1)"),
|
"photo_story": gorm.Expr("IF (`photo_story`, 0, 1)"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
_ "github.com/jinzhu/gorm/dialects/mysql"
|
_ "github.com/jinzhu/gorm/dialects/mysql"
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||||
gc "github.com/patrickmn/go-cache"
|
gc "github.com/patrickmn/go-cache"
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/tidb"
|
"github.com/photoprism/photoprism/internal/tidb"
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -531,22 +531,22 @@ func (c *Config) MigrateDb() {
|
||||||
// db.LogMode(true)
|
// db.LogMode(true)
|
||||||
|
|
||||||
db.AutoMigrate(
|
db.AutoMigrate(
|
||||||
&models.File{},
|
&entity.File{},
|
||||||
&models.Photo{},
|
&entity.Photo{},
|
||||||
&models.Event{},
|
&entity.Event{},
|
||||||
&models.Location{},
|
&entity.Location{},
|
||||||
&models.Camera{},
|
&entity.Camera{},
|
||||||
&models.Lens{},
|
&entity.Lens{},
|
||||||
&models.Country{},
|
&entity.Country{},
|
||||||
&models.Share{},
|
&entity.Share{},
|
||||||
|
|
||||||
&models.Album{},
|
&entity.Album{},
|
||||||
&models.PhotoAlbum{},
|
&entity.PhotoAlbum{},
|
||||||
&models.Label{},
|
&entity.Label{},
|
||||||
&models.Category{},
|
&entity.Category{},
|
||||||
&models.PhotoLabel{},
|
&entity.PhotoLabel{},
|
||||||
&models.Keyword{},
|
&entity.Keyword{},
|
||||||
&models.PhotoKeyword{},
|
&entity.PhotoKeyword{},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,8 +554,8 @@ func (c *Config) MigrateDb() {
|
||||||
func (c *Config) ClientConfig() ClientConfig {
|
func (c *Config) ClientConfig() ClientConfig {
|
||||||
db := c.Db()
|
db := c.Db()
|
||||||
|
|
||||||
var cameras []*models.Camera
|
var cameras []*entity.Camera
|
||||||
var albums []*models.Album
|
var albums []*entity.Album
|
||||||
|
|
||||||
type country struct {
|
type country struct {
|
||||||
LocCountry string
|
LocCountry string
|
||||||
|
@ -592,7 +592,7 @@ func (c *Config) ClientConfig() ClientConfig {
|
||||||
Select("COUNT(*) AS countries").
|
Select("COUNT(*) AS countries").
|
||||||
Take(&count)
|
Take(&count)
|
||||||
|
|
||||||
db.Model(&models.Location{}).
|
db.Model(&entity.Location{}).
|
||||||
Select("DISTINCT loc_country_code, loc_country").
|
Select("DISTINCT loc_country_code, loc_country").
|
||||||
Scan(&countries)
|
Scan(&countries)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
// Labels can have zero or more categories with the same or a similar meaning
|
// Labels can have zero or more categories with the same or a similar meaning
|
||||||
type Category struct {
|
type Category struct {
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gosimple/slug"
|
"github.com/gosimple/slug"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -7,4 +7,4 @@ Additional information concerning data storage can be found in our Developer Gui
|
||||||
|
|
||||||
https://github.com/photoprism/photoprism/wiki/Storage
|
https://github.com/photoprism/photoprism/wiki/Storage
|
||||||
*/
|
*/
|
||||||
package models
|
package entity
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gosimple/slug"
|
"github.com/gosimple/slug"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
// Photo location
|
// Photo location
|
||||||
type Location struct {
|
type Location struct {
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import "github.com/jinzhu/gorm"
|
import "github.com/jinzhu/gorm"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -1,4 +1,4 @@
|
||||||
package models
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/internal/config"
|
"github.com/photoprism/photoprism/internal/config"
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
)
|
)
|
||||||
|
@ -179,7 +179,7 @@ func (i *Importer) DestinationFilename(mainFile *MediaFile, mediaFile *MediaFile
|
||||||
fileExtension := mediaFile.Extension()
|
fileExtension := mediaFile.Extension()
|
||||||
dateCreated := mainFile.DateCreated()
|
dateCreated := mainFile.DateCreated()
|
||||||
|
|
||||||
if file, err := models.FindFileByHash(i.conf.Db(), mediaFile.Hash()); err == nil {
|
if file, err := entity.FindFileByHash(i.conf.Db(), mediaFile.Hash()); err == nil {
|
||||||
existingFilename := i.conf.OriginalsPath() + string(os.PathSeparator) + file.FileName
|
existingFilename := i.conf.OriginalsPath() + string(os.PathSeparator) + file.FileName
|
||||||
return existingFilename, fmt.Errorf("\"%s\" is identical to \"%s\" (%s)", mediaFile.Filename(), file.FileName, mediaFile.Hash())
|
return existingFilename, fmt.Errorf("\"%s\" is identical to \"%s\" (%s)", mediaFile.Filename(), file.FileName, mediaFile.Hash())
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/event"
|
"github.com/photoprism/photoprism/internal/event"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ const (
|
||||||
type IndexResult string
|
type IndexResult string
|
||||||
|
|
||||||
func (i *Indexer) indexMediaFile(mediaFile *MediaFile, o IndexerOptions) IndexResult {
|
func (i *Indexer) indexMediaFile(mediaFile *MediaFile, o IndexerOptions) IndexResult {
|
||||||
var photo models.Photo
|
var photo entity.Photo
|
||||||
var file, primaryFile models.File
|
var file, primaryFile entity.File
|
||||||
var isPrimary = false
|
var isPrimary = false
|
||||||
var exifData *Exif
|
var exifData *Exif
|
||||||
var photoQuery, fileQuery *gorm.DB
|
var photoQuery, fileQuery *gorm.DB
|
||||||
|
@ -98,8 +98,8 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile, o IndexerOptions) IndexRe
|
||||||
|
|
||||||
if fileChanged || o.UpdateCamera {
|
if fileChanged || o.UpdateCamera {
|
||||||
// Set UpdateCamera, Lens, Focal Length and F Number
|
// Set UpdateCamera, Lens, Focal Length and F Number
|
||||||
photo.Camera = models.NewCamera(mediaFile.CameraModel(), mediaFile.CameraMake()).FirstOrCreate(i.db)
|
photo.Camera = entity.NewCamera(mediaFile.CameraModel(), mediaFile.CameraMake()).FirstOrCreate(i.db)
|
||||||
photo.Lens = models.NewLens(mediaFile.LensModel(), mediaFile.LensMake()).FirstOrCreate(i.db)
|
photo.Lens = entity.NewLens(mediaFile.LensModel(), mediaFile.LensMake()).FirstOrCreate(i.db)
|
||||||
photo.PhotoFocalLength = mediaFile.FocalLength()
|
photo.PhotoFocalLength = mediaFile.FocalLength()
|
||||||
photo.PhotoFNumber = mediaFile.FNumber()
|
photo.PhotoFNumber = mediaFile.FNumber()
|
||||||
photo.PhotoIso = mediaFile.Iso()
|
photo.PhotoIso = mediaFile.Iso()
|
||||||
|
@ -273,7 +273,7 @@ func (i *Indexer) classifyImage(jpeg *MediaFile) (results Labels) {
|
||||||
|
|
||||||
func (i *Indexer) addLabels(photoId uint, labels Labels) {
|
func (i *Indexer) addLabels(photoId uint, labels Labels) {
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
lm := models.NewLabel(label.Name, label.Priority).FirstOrCreate(i.db)
|
lm := entity.NewLabel(label.Name, label.Priority).FirstOrCreate(i.db)
|
||||||
|
|
||||||
if lm.New {
|
if lm.New {
|
||||||
event.Publish("count.labels", event.Data{
|
event.Publish("count.labels", event.Data{
|
||||||
|
@ -286,11 +286,11 @@ func (i *Indexer) addLabels(photoId uint, labels Labels) {
|
||||||
i.db.Save(&lm)
|
i.db.Save(&lm)
|
||||||
}
|
}
|
||||||
|
|
||||||
plm := models.NewPhotoLabel(photoId, lm.ID, label.Uncertainty, label.Source).FirstOrCreate(i.db)
|
plm := entity.NewPhotoLabel(photoId, lm.ID, label.Uncertainty, label.Source).FirstOrCreate(i.db)
|
||||||
|
|
||||||
// Add categories
|
// Add categories
|
||||||
for _, category := range label.Categories {
|
for _, category := range label.Categories {
|
||||||
sn := models.NewLabel(category, -1).FirstOrCreate(i.db)
|
sn := entity.NewLabel(category, -1).FirstOrCreate(i.db)
|
||||||
i.db.Model(&lm).Association("LabelCategories").Append(sn)
|
i.db.Model(&lm).Association("LabelCategories").Append(sn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,13 +302,13 @@ func (i *Indexer) addLabels(photoId uint, labels Labels) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Indexer) indexLocation(mediaFile *MediaFile, photo *models.Photo, keywords []string, labels Labels, fileChanged bool, o IndexerOptions) ([]string, Labels) {
|
func (i *Indexer) indexLocation(mediaFile *MediaFile, photo *entity.Photo, keywords []string, labels Labels, fileChanged bool, o IndexerOptions) ([]string, Labels) {
|
||||||
if location, err := mediaFile.Location(); err == nil {
|
if location, err := mediaFile.Location(); err == nil {
|
||||||
i.db.FirstOrCreate(location, "id = ?", location.ID)
|
i.db.FirstOrCreate(location, "id = ?", location.ID)
|
||||||
photo.Location = location
|
photo.Location = location
|
||||||
photo.LocationEstimated = false
|
photo.LocationEstimated = false
|
||||||
|
|
||||||
photo.Country = models.NewCountry(location.LocCountryCode, location.LocCountry).FirstOrCreate(i.db)
|
photo.Country = entity.NewCountry(location.LocCountryCode, location.LocCountry).FirstOrCreate(i.db)
|
||||||
|
|
||||||
if photo.Country.New {
|
if photo.Country.New {
|
||||||
event.Publish("count.countries", event.Data{
|
event.Publish("count.countries", event.Data{
|
||||||
|
@ -381,8 +381,8 @@ func (i *Indexer) indexLocation(mediaFile *MediaFile, photo *models.Photo, keywo
|
||||||
return keywords, labels
|
return keywords, labels
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Indexer) estimateLocation(photo *models.Photo) {
|
func (i *Indexer) estimateLocation(photo *entity.Photo) {
|
||||||
var recentPhoto models.Photo
|
var recentPhoto entity.Photo
|
||||||
|
|
||||||
if result := i.db.Unscoped().Order(gorm.Expr("ABS(DATEDIFF(taken_at, ?)) ASC", photo.TakenAt)).Preload("Country").First(&recentPhoto); result.Error == nil {
|
if result := i.db.Unscoped().Order(gorm.Expr("ABS(DATEDIFF(taken_at, ?)) ASC", photo.TakenAt)).Preload("Country").First(&recentPhoto); result.Error == nil {
|
||||||
if recentPhoto.Country != nil {
|
if recentPhoto.Country != nil {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/djherbis/times"
|
"github.com/djherbis/times"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ type MediaFile struct {
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
exifData *Exif
|
exifData *Exif
|
||||||
location *models.Location
|
location *entity.Location
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMediaFile returns a new MediaFile.
|
// NewMediaFile returns a new MediaFile.
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
@ -37,12 +37,12 @@ type openstreetmapLocation struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Location See https://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding
|
// Location See https://wiki.openstreetmap.org/wiki/Nominatim#Reverse_Geocoding
|
||||||
func (m *MediaFile) Location() (*models.Location, error) {
|
func (m *MediaFile) Location() (*entity.Location, error) {
|
||||||
if m.location != nil {
|
if m.location != nil {
|
||||||
return m.location, nil
|
return m.location, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
location := &models.Location{}
|
location := &entity.Location{}
|
||||||
|
|
||||||
openstreetmapLocation := &openstreetmapLocation{
|
openstreetmapLocation := &openstreetmapLocation{
|
||||||
Address: &openstreetmapAddress{},
|
Address: &openstreetmapAddress{},
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/internal/config"
|
"github.com/photoprism/photoprism/internal/config"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -162,7 +162,7 @@ func TestThumbnails_ThumbnailFromFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("valid parameter", func(t *testing.T) {
|
t.Run("valid parameter", func(t *testing.T) {
|
||||||
fileModel := &models.File{
|
fileModel := &entity.File{
|
||||||
FileName: conf.ExamplesPath() + "/elephants.jpg",
|
FileName: conf.ExamplesPath() + "/elephants.jpg",
|
||||||
FileHash: "1234568889",
|
FileHash: "1234568889",
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ func TestThumbnails_ThumbnailFromFile(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("hash too short", func(t *testing.T) {
|
t.Run("hash too short", func(t *testing.T) {
|
||||||
fileModel := &models.File{
|
fileModel := &entity.File{
|
||||||
FileName: conf.ExamplesPath() + "/elephants.jpg",
|
FileName: conf.ExamplesPath() + "/elephants.jpg",
|
||||||
FileHash: "123",
|
FileHash: "123",
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func TestThumbnails_ThumbnailFromFile(t *testing.T) {
|
||||||
assert.Equal(t, "file hash is empty or too short: 123", err.Error())
|
assert.Equal(t, "file hash is empty or too short: 123", err.Error())
|
||||||
})
|
})
|
||||||
t.Run("filename too short", func(t *testing.T) {
|
t.Run("filename too short", func(t *testing.T) {
|
||||||
fileModel := &models.File{
|
fileModel := &entity.File{
|
||||||
FileName: "xxx",
|
FileName: "xxx",
|
||||||
FileHash: "12367890",
|
FileHash: "12367890",
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/form"
|
"github.com/photoprism/photoprism/internal/form"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ type AlbumResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAlbumByUUID returns a Album based on the UUID.
|
// FindAlbumByUUID returns a Album based on the UUID.
|
||||||
func (s *Repo) FindAlbumByUUID(albumUUID string) (album models.Album, err error) {
|
func (s *Repo) FindAlbumByUUID(albumUUID string) (album entity.Album, err error) {
|
||||||
if err := s.db.Where("album_uuid = ?", albumUUID).First(&album).Error; err != nil {
|
if err := s.db.Where("album_uuid = ?", albumUUID).First(&album).Error; err != nil {
|
||||||
return album, err
|
return album, err
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func (s *Repo) FindAlbumByUUID(albumUUID string) (album models.Album, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAlbumThumbByUUID returns a album preview file based on the uuid.
|
// FindAlbumThumbByUUID returns a album preview file based on the uuid.
|
||||||
func (s *Repo) FindAlbumThumbByUUID(albumUUID string) (file models.File, err error) {
|
func (s *Repo) FindAlbumThumbByUUID(albumUUID string) (file entity.File, err error) {
|
||||||
// s.db.LogMode(true)
|
// s.db.LogMode(true)
|
||||||
|
|
||||||
if err := s.db.Where("files.file_primary AND files.deleted_at IS NULL").
|
if err := s.db.Where("files.file_primary AND files.deleted_at IS NULL").
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package repo
|
package repo
|
||||||
|
|
||||||
import "github.com/photoprism/photoprism/internal/models"
|
import "github.com/photoprism/photoprism/internal/entity"
|
||||||
|
|
||||||
// FindFiles finds files returning maximum results defined by limit
|
// FindFiles finds files returning maximum results defined by limit
|
||||||
// and finding them from an offest defined by offset.
|
// and finding them from an offest defined by offset.
|
||||||
func (s *Repo) FindFiles(limit int, offset int) (files []models.File, err error) {
|
func (s *Repo) FindFiles(limit int, offset int) (files []entity.File, err error) {
|
||||||
if err := s.db.Where(&models.File{}).Limit(limit).Offset(offset).Find(&files).Error; err != nil {
|
if err := s.db.Where(&entity.File{}).Limit(limit).Offset(offset).Find(&files).Error; err != nil {
|
||||||
return files, err
|
return files, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ func (s *Repo) FindFiles(limit int, offset int) (files []models.File, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindFilesByUUID
|
// FindFilesByUUID
|
||||||
func (s *Repo) FindFilesByUUID(u []string, limit int, offset int) (files []models.File, err error) {
|
func (s *Repo) FindFilesByUUID(u []string, limit int, offset int) (files []entity.File, err error) {
|
||||||
if err := s.db.Where("(photo_uuid IN (?) AND file_primary = 1) OR file_uuid IN (?)", u, u).Preload("Photo").Limit(limit).Offset(offset).Find(&files).Error; err != nil {
|
if err := s.db.Where("(photo_uuid IN (?) AND file_primary = 1) OR file_uuid IN (?)", u, u).Preload("Photo").Limit(limit).Offset(offset).Find(&files).Error; err != nil {
|
||||||
return files, err
|
return files, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func (s *Repo) FindFilesByUUID(u []string, limit int, offset int) (files []model
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindFileByPhotoUUID
|
// FindFileByPhotoUUID
|
||||||
func (s *Repo) FindFileByPhotoUUID(u string) (file models.File, err error) {
|
func (s *Repo) FindFileByPhotoUUID(u string) (file entity.File, err error) {
|
||||||
if err := s.db.Where("photo_uuid = ? AND file_primary = 1", u).Preload("Photo").First(&file).Error; err != nil {
|
if err := s.db.Where("photo_uuid = ? AND file_primary = 1", u).Preload("Photo").First(&file).Error; err != nil {
|
||||||
return file, err
|
return file, err
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func (s *Repo) FindFileByPhotoUUID(u string) (file models.File, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindFileByID returns a mediafile given a certain ID.
|
// FindFileByID returns a mediafile given a certain ID.
|
||||||
func (s *Repo) FindFileByID(id string) (file models.File, err error) {
|
func (s *Repo) FindFileByID(id string) (file entity.File, err error) {
|
||||||
if err := s.db.Where("id = ?", id).Preload("Photo").First(&file).Error; err != nil {
|
if err := s.db.Where("id = ?", id).Preload("Photo").First(&file).Error; err != nil {
|
||||||
return file, err
|
return file, err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func (s *Repo) FindFileByID(id string) (file models.File, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindFileByHash finds a file with a given hash string.
|
// FindFileByHash finds a file with a given hash string.
|
||||||
func (s *Repo) FindFileByHash(fileHash string) (file models.File, err error) {
|
func (s *Repo) FindFileByHash(fileHash string) (file entity.File, err error) {
|
||||||
if err := s.db.Where("file_hash = ?", fileHash).Preload("Photo").First(&file).Error; err != nil {
|
if err := s.db.Where("file_hash = ?", fileHash).Preload("Photo").First(&file).Error; err != nil {
|
||||||
return file, err
|
return file, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/form"
|
"github.com/photoprism/photoprism/internal/form"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ type LabelResult struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindLabelBySlug returns a Label based on the slug name.
|
// FindLabelBySlug returns a Label based on the slug name.
|
||||||
func (s *Repo) FindLabelBySlug(labelSlug string) (label models.Label, err error) {
|
func (s *Repo) FindLabelBySlug(labelSlug string) (label entity.Label, err error) {
|
||||||
if err := s.db.Where("label_slug = ?", labelSlug).First(&label).Error; err != nil {
|
if err := s.db.Where("label_slug = ?", labelSlug).First(&label).Error; err != nil {
|
||||||
return label, err
|
return label, err
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ func (s *Repo) FindLabelBySlug(labelSlug string) (label models.Label, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindLabelThumbBySlug returns a label preview file based on the slug name.
|
// FindLabelThumbBySlug returns a label preview file based on the slug name.
|
||||||
func (s *Repo) FindLabelThumbBySlug(labelSlug string) (file models.File, err error) {
|
func (s *Repo) FindLabelThumbBySlug(labelSlug string) (file entity.File, err error) {
|
||||||
// s.db.LogMode(true)
|
// s.db.LogMode(true)
|
||||||
|
|
||||||
if err := s.db.Where("files.file_primary AND files.deleted_at IS NULL").
|
if err := s.db.Where("files.file_primary AND files.deleted_at IS NULL").
|
||||||
|
@ -70,8 +70,8 @@ func (s *Repo) Labels(f form.LabelSearch) (results []LabelResult, err error) {
|
||||||
|
|
||||||
if f.Query != "" {
|
if f.Query != "" {
|
||||||
var labelIds []uint
|
var labelIds []uint
|
||||||
var categories []models.Category
|
var categories []entity.Category
|
||||||
var label models.Label
|
var label entity.Label
|
||||||
|
|
||||||
likeString := "%" + strings.ToLower(f.Query) + "%"
|
likeString := "%" + strings.ToLower(f.Query) + "%"
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gosimple/slug"
|
"github.com/gosimple/slug"
|
||||||
|
"github.com/photoprism/photoprism/internal/entity"
|
||||||
"github.com/photoprism/photoprism/internal/form"
|
"github.com/photoprism/photoprism/internal/form"
|
||||||
"github.com/photoprism/photoprism/internal/models"
|
|
||||||
"github.com/photoprism/photoprism/internal/util"
|
"github.com/photoprism/photoprism/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ func (s *Repo) Photos(f form.PhotoSearch) (results []PhotoResult, err error) {
|
||||||
Joins("LEFT JOIN photos_labels ON photos_labels.photo_id = photos.id").
|
Joins("LEFT JOIN photos_labels ON photos_labels.photo_id = photos.id").
|
||||||
Where("photos.deleted_at IS NULL AND files.file_missing = 0").
|
Where("photos.deleted_at IS NULL AND files.file_missing = 0").
|
||||||
Group("photos.id, files.id")
|
Group("photos.id, files.id")
|
||||||
var categories []models.Category
|
var categories []entity.Category
|
||||||
var label models.Label
|
var label entity.Label
|
||||||
var labelIds []uint
|
var labelIds []uint
|
||||||
|
|
||||||
if f.Label != "" {
|
if f.Label != "" {
|
||||||
|
@ -320,7 +320,7 @@ func (s *Repo) Photos(f form.PhotoSearch) (results []PhotoResult, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindPhotoByID returns a Photo based on the ID.
|
// FindPhotoByID returns a Photo based on the ID.
|
||||||
func (s *Repo) FindPhotoByID(photoID uint64) (photo models.Photo, err error) {
|
func (s *Repo) FindPhotoByID(photoID uint64) (photo entity.Photo, err error) {
|
||||||
if err := s.db.Where("id = ?", photoID).First(&photo).Error; err != nil {
|
if err := s.db.Where("id = ?", photoID).First(&photo).Error; err != nil {
|
||||||
return photo, err
|
return photo, err
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ func (s *Repo) FindPhotoByID(photoID uint64) (photo models.Photo, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindPhotoByUUID returns a Photo based on the UUID.
|
// FindPhotoByUUID returns a Photo based on the UUID.
|
||||||
func (s *Repo) FindPhotoByUUID(photoUUID string) (photo models.Photo, err error) {
|
func (s *Repo) FindPhotoByUUID(photoUUID string) (photo entity.Photo, err error) {
|
||||||
if err := s.db.Where("photo_uuid = ?", photoUUID).First(&photo).Error; err != nil {
|
if err := s.db.Where("photo_uuid = ?", photoUUID).First(&photo).Error; err != nil {
|
||||||
return photo, err
|
return photo, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue