mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 21:19:18 +00:00
Reverting changes after I forgot to create a new branch for testing.
This commit is contained in:
@@ -188,14 +188,6 @@ func MigrateDatabase(db *gorm.DB) error {
|
|||||||
log.Printf("Failed to run exif fields migration: %v\n", err)
|
log.Printf("Failed to run exif fields migration: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// // PJ-Watson: Attempt to add new column for FaceGroup.PreviewImageFace
|
|
||||||
if !(db.Migrator().HasColumn(&models.FaceGroup{}, "preview_image_face")) {
|
|
||||||
db.Migrator().AddColumn(&models.FaceGroup{}, "preview_image_face")
|
|
||||||
}
|
|
||||||
if err := migrate_face_preview(db); err != nil {
|
|
||||||
log.Printf("Failed to run face groups preview image migration: %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,211 +0,0 @@
|
|||||||
package database
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/photoview/photoview/api/graphql/models"
|
|
||||||
// "github.com/pkg/errors"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Migrate face groups
|
|
||||||
func migrate_face_preview(db *gorm.DB) error {
|
|
||||||
|
|
||||||
// err = db.Transaction(func(tx *gorm.DB) error {
|
|
||||||
var facegroup models.FaceGroup
|
|
||||||
|
|
||||||
fmt.Println("Got here")
|
|
||||||
|
|
||||||
rows, err := db.Model(&models.FaceGroup{}).Rows()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for rows.Next() {
|
|
||||||
db.ScanRows(rows, &facegroup)
|
|
||||||
|
|
||||||
if err := db.Model(&facegroup).Update("preview_image_face", &facegroup.ImageFaces[0]).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Println(product)
|
|
||||||
}
|
|
||||||
|
|
||||||
// if err := r.Database.Model(&album).Update("cover_id", coverID).Error; err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// faceGroupColumns, err := db.Migrator().ColumnTypes(&models.FaceGroup{})
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
// err = db.Transaction(func(tx *gorm.DB) error {
|
|
||||||
// for _, faceCol := range faceGroupColumns {
|
|
||||||
// if faceCol.Name() == "preview_image_face" {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// switch exifCol.DatabaseTypeName() {
|
|
||||||
// case "double", "numeric", "real":
|
|
||||||
// // correct type, do nothing
|
|
||||||
// default:
|
|
||||||
// // do migration
|
|
||||||
// if err := migrate_exif_fields_exposure(db); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if exifCol.Name() == "flash" {
|
|
||||||
// switch exifCol.DatabaseTypeName() {
|
|
||||||
// case "double", "numeric", "real":
|
|
||||||
// // correct type, do nothing
|
|
||||||
// default:
|
|
||||||
// // do migration
|
|
||||||
// if err := migrate_exif_fields_flash(db); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if err := db.AutoMigrate(&models.MediaEXIF{}); err != nil {
|
|
||||||
// return errors.Wrap(err, "failed to auto migrate media_exif after exposure conversion")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// })
|
|
||||||
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// func migrate_exif_fields_exposure(db *gorm.DB) error {
|
|
||||||
// log.Println("Migrating `media_exif.exposure` from string to double")
|
|
||||||
//
|
|
||||||
// err := db.Transaction(func(tx *gorm.DB) error {
|
|
||||||
//
|
|
||||||
// if err := tx.Exec("UPDATE media_exif SET exposure = NULL WHERE exposure = ''").Error; err != nil {
|
|
||||||
// return errors.Wrapf(err, "convert flash attribute empty values to NULL")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// type exifModel struct {
|
|
||||||
// ID int `gorm:"primarykey"`
|
|
||||||
// Exposure *string
|
|
||||||
// }
|
|
||||||
// var results []exifModel
|
|
||||||
//
|
|
||||||
// return tx.Model(&exifModel{}).Table("media_exif").Where("exposure LIKE '%/%'").FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
|
||||||
// for _, result := range results {
|
|
||||||
//
|
|
||||||
// if result.Exposure == nil {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// frac := strings.Split(*result.Exposure, "/")
|
|
||||||
// if len(frac) != 2 {
|
|
||||||
// return errors.Errorf("failed to convert exposure value (%s) expected format x/y", frac)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// numerator, err := strconv.ParseFloat(frac[0], 64)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// denominator, err := strconv.ParseFloat(frac[1], 64)
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// decimalValue := numerator / denominator
|
|
||||||
// *result.Exposure = fmt.Sprintf("%f", decimalValue)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// tx.Save(&results)
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// }).Error
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return errors.Wrap(err, "migrating `media_exif.exposure` failed")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func migrate_exif_fields_flash(db *gorm.DB) error {
|
|
||||||
// log.Println("Migrating `media_exif.flash` from string to int")
|
|
||||||
//
|
|
||||||
// err := db.Transaction(func(tx *gorm.DB) error {
|
|
||||||
//
|
|
||||||
// if err := tx.Exec("UPDATE media_exif SET flash = NULL WHERE flash = ''").Error; err != nil {
|
|
||||||
// return errors.Wrapf(err, "convert flash attribute empty values to NULL")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// type exifModel struct {
|
|
||||||
// ID int `gorm:"primarykey"`
|
|
||||||
// Flash *string
|
|
||||||
// }
|
|
||||||
// var results []exifModel
|
|
||||||
//
|
|
||||||
// var flashDescriptions = map[int]string{
|
|
||||||
// 0x0: "No Flash",
|
|
||||||
// 0x1: "Fired",
|
|
||||||
// 0x5: "Fired, Return not detected",
|
|
||||||
// 0x7: "Fired, Return detected",
|
|
||||||
// 0x8: "On, Did not fire",
|
|
||||||
// 0x9: "On, Fired",
|
|
||||||
// 0xD: "On, Return not detected",
|
|
||||||
// 0xF: "On, Return detected",
|
|
||||||
// 0x10: "Off, Did not fire",
|
|
||||||
// 0x14: "Off, Did not fire, Return not detected",
|
|
||||||
// 0x18: "Auto, Did not fire",
|
|
||||||
// 0x19: "Auto, Fired",
|
|
||||||
// 0x1D: "Auto, Fired, Return not detected",
|
|
||||||
// 0x1F: "Auto, Fired, Return detected",
|
|
||||||
// 0x20: "No flash function",
|
|
||||||
// 0x30: "Off, No flash function",
|
|
||||||
// 0x41: "Fired, Red-eye reduction",
|
|
||||||
// 0x45: "Fired, Red-eye reduction, Return not detected",
|
|
||||||
// 0x47: "Fired, Red-eye reduction, Return detected",
|
|
||||||
// 0x49: "On, Red-eye reduction",
|
|
||||||
// 0x4D: "On, Red-eye reduction, Return not detected",
|
|
||||||
// 0x4F: "On, Red-eye reduction, Return detected",
|
|
||||||
// 0x50: "Off, Red-eye reduction",
|
|
||||||
// 0x58: "Auto, Did not fire, Red-eye reduction",
|
|
||||||
// 0x59: "Auto, Fired, Red-eye reduction",
|
|
||||||
// 0x5D: "Auto, Fired, Red-eye reduction, Return not detected",
|
|
||||||
// 0x5F: "Auto, Fired, Red-eye reduction, Return detected",
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return tx.Model(&exifModel{}).Table("media_exif").Where("flash IS NOT NULL").FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
|
|
||||||
// for _, result := range results {
|
|
||||||
//
|
|
||||||
// if result.Flash == nil {
|
|
||||||
// continue
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// for index, name := range flashDescriptions {
|
|
||||||
// if *result.Flash == name {
|
|
||||||
// *result.Flash = fmt.Sprintf("%d", index)
|
|
||||||
// break
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// tx.Save(&results)
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// }).Error
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return errors.Wrap(err, "migrating `media_exif.flash` failed")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# GraphQL schema example
|
|
||||||
#
|
|
||||||
# https://gqlgen.com/getting-started/
|
|
||||||
|
|
||||||
type Todo {
|
|
||||||
id: ID!
|
|
||||||
text: String!
|
|
||||||
done: Boolean!
|
|
||||||
user: User!
|
|
||||||
}
|
|
||||||
|
|
||||||
type User {
|
|
||||||
id: ID!
|
|
||||||
name: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Query {
|
|
||||||
todos: [Todo!]!
|
|
||||||
}
|
|
||||||
|
|
||||||
input NewTodo {
|
|
||||||
text: String!
|
|
||||||
userId: String!
|
|
||||||
}
|
|
||||||
|
|
||||||
type Mutation {
|
|
||||||
createTodo(input: NewTodo!): Todo!
|
|
||||||
}
|
|
||||||
@@ -81,7 +81,6 @@ type ComplexityRoot struct {
|
|||||||
ImageFaceCount func(childComplexity int) int
|
ImageFaceCount func(childComplexity int) int
|
||||||
ImageFaces func(childComplexity int, paginate *models.Pagination) int
|
ImageFaces func(childComplexity int, paginate *models.Pagination) int
|
||||||
Label func(childComplexity int) int
|
Label func(childComplexity int) int
|
||||||
PreviewImageFace func(childComplexity int) int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FaceRectangle struct {
|
FaceRectangle struct {
|
||||||
@@ -513,13 +512,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
|||||||
|
|
||||||
return e.complexity.FaceGroup.Label(childComplexity), true
|
return e.complexity.FaceGroup.Label(childComplexity), true
|
||||||
|
|
||||||
case "FaceGroup.PreviewImageFace":
|
|
||||||
if e.complexity.FaceGroup.PreviewImageFace == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.FaceGroup.PreviewImageFace(childComplexity), true
|
|
||||||
|
|
||||||
case "FaceRectangle.maxX":
|
case "FaceRectangle.maxX":
|
||||||
if e.complexity.FaceRectangle.MaxX == nil {
|
if e.complexity.FaceRectangle.MaxX == nil {
|
||||||
break
|
break
|
||||||
@@ -2059,7 +2051,6 @@ type FaceGroup {
|
|||||||
label: String
|
label: String
|
||||||
imageFaces(paginate: Pagination): [ImageFace!]!
|
imageFaces(paginate: Pagination): [ImageFace!]!
|
||||||
imageFaceCount: Int!
|
imageFaceCount: Int!
|
||||||
PreviewImageFace: ImageFace!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageFace {
|
type ImageFace {
|
||||||
@@ -3627,41 +3618,6 @@ func (ec *executionContext) _FaceGroup_imageFaceCount(ctx context.Context, field
|
|||||||
return ec.marshalNInt2int(ctx, field.Selections, res)
|
return ec.marshalNInt2int(ctx, field.Selections, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _FaceGroup_PreviewImageFace(ctx context.Context, field graphql.CollectedField, obj *models.FaceGroup) (ret graphql.Marshaler) {
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
fc := &graphql.FieldContext{
|
|
||||||
Object: "FaceGroup",
|
|
||||||
Field: field,
|
|
||||||
Args: nil,
|
|
||||||
IsMethod: false,
|
|
||||||
IsResolver: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.PreviewImageFace, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
if !graphql.HasFieldError(ctx, fc) {
|
|
||||||
ec.Errorf(ctx, "must not be null")
|
|
||||||
}
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(models.ImageFace)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalNImageFace2githubᚗcomᚋphotoviewᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐImageFace(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _FaceRectangle_minX(ctx context.Context, field graphql.CollectedField, obj *models.FaceRectangle) (ret graphql.Marshaler) {
|
func (ec *executionContext) _FaceRectangle_minX(ctx context.Context, field graphql.CollectedField, obj *models.FaceRectangle) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
@@ -10504,11 +10460,6 @@ func (ec *executionContext) _FaceGroup(ctx context.Context, sel ast.SelectionSet
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
})
|
})
|
||||||
case "PreviewImageFace":
|
|
||||||
out.Values[i] = ec._FaceGroup_PreviewImageFace(ctx, field, obj)
|
|
||||||
if out.Values[i] == graphql.Null {
|
|
||||||
atomic.AddUint32(&invalids, 1)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
panic("unknown field " + strconv.Quote(field.Name))
|
panic("unknown field " + strconv.Quote(field.Name))
|
||||||
}
|
}
|
||||||
@@ -12210,10 +12161,6 @@ func (ec *executionContext) marshalNID2ᚕintᚄ(ctx context.Context, sel ast.Se
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) marshalNImageFace2githubᚗcomᚋphotoviewᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐImageFace(ctx context.Context, sel ast.SelectionSet, v models.ImageFace) graphql.Marshaler {
|
|
||||||
return ec._ImageFace(ctx, sel, &v)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) marshalNImageFace2ᚕᚖgithubᚗcomᚋphotoviewᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐImageFaceᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.ImageFace) graphql.Marshaler {
|
func (ec *executionContext) marshalNImageFace2ᚕᚖgithubᚗcomᚋphotoviewᚋphotoviewᚋapiᚋgraphqlᚋmodelsᚐImageFaceᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.ImageFace) graphql.Marshaler {
|
||||||
ret := make(graphql.Array, len(v))
|
ret := make(graphql.Array, len(v))
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ type FaceGroup struct {
|
|||||||
Model
|
Model
|
||||||
Label *string
|
Label *string
|
||||||
ImageFaces []ImageFace `gorm:"constraint:OnDelete:CASCADE;"`
|
ImageFaces []ImageFace `gorm:"constraint:OnDelete:CASCADE;"`
|
||||||
PreviewImageFace ImageFace `gorm:"constraint:OnDelete:CASCADE;"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageFace struct {
|
type ImageFace struct {
|
||||||
|
|||||||
@@ -383,7 +383,6 @@ type FaceGroup {
|
|||||||
label: String
|
label: String
|
||||||
imageFaces(paginate: Pagination): [ImageFace!]!
|
imageFaces(paginate: Pagination): [ImageFace!]!
|
||||||
imageFaceCount: Int!
|
imageFaceCount: Int!
|
||||||
PreviewImageFace: ImageFace!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageFace {
|
type ImageFace {
|
||||||
|
|||||||
@@ -155,7 +155,6 @@ func (fd *FaceDetector) classifyFace(db *gorm.DB, face *face.Face, media *models
|
|||||||
|
|
||||||
faceGroup = models.FaceGroup{
|
faceGroup = models.FaceGroup{
|
||||||
ImageFaces: []models.ImageFace{imageFace},
|
ImageFaces: []models.ImageFace{imageFace},
|
||||||
PreviewImageFace: []models.ImageFace{imageFace}[0],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.Create(&faceGroup).Error; err != nil {
|
if err := db.Create(&faceGroup).Error; err != nil {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export interface resetAlbumCover_resetAlbumCover {
|
|||||||
|
|
||||||
export interface resetAlbumCover {
|
export interface resetAlbumCover {
|
||||||
/**
|
/**
|
||||||
* Reset the assigned cover photo for an album
|
* Reset the assigned cover image for an album
|
||||||
*/
|
*/
|
||||||
resetAlbumCover: resetAlbumCover_resetAlbumCover
|
resetAlbumCover: resetAlbumCover_resetAlbumCover
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export interface setAlbumCover_setAlbumCover {
|
|||||||
|
|
||||||
export interface setAlbumCover {
|
export interface setAlbumCover {
|
||||||
/**
|
/**
|
||||||
* Assign a cover photo to an album
|
* Assign a cover image to an album
|
||||||
*/
|
*/
|
||||||
setAlbumCover: setAlbumCover_setAlbumCover
|
setAlbumCover: setAlbumCover_setAlbumCover
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user