精简后的项目:仅保留 api/ui 源码、文档、构建依赖

This commit is contained in:
gallery
2026-09-11 16:11:09 +08:00
commit 490e85634e
457 changed files with 86862 additions and 0 deletions
@@ -0,0 +1,24 @@
package migrations
import (
"fmt"
"github.com/photoview/photoview/api/graphql/models"
"gorm.io/gorm"
)
// MigrateForExifGPSCorrection finds and removes invalid GPS data from media_exif table
func MigrateForExifGPSCorrection(db *gorm.DB) error {
return db.Transaction(func(tx *gorm.DB) error {
if err := tx.Model(&models.MediaEXIF{}).
Where("ABS(gps_longitude) > ?", 90).
Or("ABS(gps_latitude) > ?", 90).
Updates(map[string]interface{}{
"gps_latitude": nil,
"gps_longitude": nil,
}).Error; err != nil {
return fmt.Errorf("failed to remove invalid GPS data from media_exif table: %w", err)
}
return nil
})
}
@@ -0,0 +1,54 @@
package migrations_test
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
"github.com/photoview/photoview/api/database/migrations"
"github.com/photoview/photoview/api/graphql/models"
"github.com/photoview/photoview/api/test_utils"
)
func TestExifMigration(t *testing.T) {
db := test_utils.DatabaseTest(t)
defer db.Exec("DELETE FROM media_exif") // Clean up after test
// Create test data
exifEntries := []models.MediaEXIF{
{GPSLatitude: floatPtr(90.1), GPSLongitude: floatPtr(90.0)}, // Invalid GPSLatitude
{GPSLatitude: floatPtr(-90.1), GPSLongitude: floatPtr(-90.0)}, // Invalid GPSLatitude
{GPSLatitude: floatPtr(90.0), GPSLongitude: floatPtr(90.1)}, // Invalid GPSLongitude
{GPSLatitude: floatPtr(-90.0), GPSLongitude: floatPtr(-90.1)}, // Invalid GPSLongitude
{GPSLatitude: floatPtr(90.0), GPSLongitude: floatPtr(90.0)}, // Valid GPS data
{GPSLatitude: floatPtr(-90.0), GPSLongitude: floatPtr(-90.0)}, // Valid GPS data
{GPSLatitude: floatPtr(90.1), GPSLongitude: floatPtr(90.1)}, // Invalid GPSLatitude and GPSLongitude
{GPSLatitude: floatPtr(-90.1), GPSLongitude: floatPtr(-90.1)}, // Invalid GPSLatitude and GPSLongitude
}
// Insert test data
for _, entry := range exifEntries {
assert.NoError(t, db.Create(&entry).Error)
}
// Run migration
assert.NoError(t, migrations.MigrateForExifGPSCorrection(db))
// Validate the results
var results []models.MediaEXIF
assert.NoError(t, db.Find(&results).Error)
for _, entry := range results {
if entry.GPSLatitude != nil {
assert.LessOrEqual(t, math.Abs(*entry.GPSLatitude), 90.0, "GPSLatitude should be within [-90, 90]: %+v", entry)
}
if entry.GPSLongitude != nil {
assert.LessOrEqual(t, math.Abs(*entry.GPSLongitude), 90.0, "GPSLongitude should be within [-90, 90]: %+v", entry)
}
}
}
func floatPtr(f float64) *float64 {
return &f
}
@@ -0,0 +1,11 @@
package migrations_test
import (
"testing"
"github.com/photoview/photoview/api/test_utils"
)
func TestMain(m *testing.M) {
test_utils.IntegrationTestRun(m)
}