diff --git a/internal/entity/file.go b/internal/entity/file.go index 51d2541ef..200936c7f 100644 --- a/internal/entity/file.go +++ b/internal/entity/file.go @@ -55,9 +55,9 @@ type File struct { FileWidth int `json:"Width" yaml:"Width,omitempty"` FileHeight int `json:"Height" yaml:"Height,omitempty"` FileOrientation int `json:"Orientation" yaml:"Orientation,omitempty"` - FileProjection string `gorm:"type:VARBINARY(32);" json:"Projection,omitempty" yaml:"Projection,omitempty"` + FileProjection string `gorm:"type:VARBINARY(40);" json:"Projection,omitempty" yaml:"Projection,omitempty"` FileAspectRatio float32 `gorm:"type:FLOAT;" json:"AspectRatio" yaml:"AspectRatio,omitempty"` - FileColorProfile string `gorm:"type:VARBINARY(32);" json:"ColorProfile,omitempty" yaml:"ColorProfile,omitempty"` + FileColorProfile string `gorm:"type:VARBINARY(40);" json:"ColorProfile,omitempty" yaml:"ColorProfile,omitempty"` FileMainColor string `gorm:"type:VARBINARY(16);index;" json:"MainColor" yaml:"MainColor,omitempty"` FileColors string `gorm:"type:VARBINARY(9);" json:"Colors" yaml:"Colors,omitempty"` FileLuminance string `gorm:"type:VARBINARY(9);" json:"Luminance" yaml:"Luminance,omitempty"` diff --git a/internal/entity/file_test.go b/internal/entity/file_test.go index 47481ad09..11ea29ead 100644 --- a/internal/entity/file_test.go +++ b/internal/entity/file_test.go @@ -332,7 +332,8 @@ func TestFile_SetProjection(t *testing.T) { t.Run("Sanitize", func(t *testing.T) { m := &File{} m.SetProjection(" 幸福 Hanzi are logograms developed for the writing of Chinese! ") - assert.Equal(t, "hanzi are logograms developed for the writing of chinese", m.FileProjection) + assert.Equal(t, "hanzi are logograms developed for the wr", m.FileProjection) + assert.Equal(t, TrimTypeString, len(m.FileProjection)) }) } diff --git a/internal/entity/values.go b/internal/entity/values.go index 99cde6e47..643c13971 100644 --- a/internal/entity/values.go +++ b/internal/entity/values.go @@ -6,7 +6,7 @@ import ( ) const ( - TrimTypeString = 32 + TrimTypeString = 40 ) // Values is a shortcut for map[string]interface{} @@ -63,7 +63,7 @@ func Trim(s string, maxLen int) string { if l <= maxLen { return s } else { - return s[:l-1] + return s[:maxLen] } } diff --git a/internal/entity/values_test.go b/internal/entity/values_test.go index 5372e9a3b..8b4e0bb9d 100644 --- a/internal/entity/values_test.go +++ b/internal/entity/values_test.go @@ -1,6 +1,7 @@ package entity import ( + "strings" "testing" "github.com/stretchr/testify/assert" @@ -12,11 +13,35 @@ func TestToASCII(t *testing.T) { } func TestTrim(t *testing.T) { - result := Trim(" 幸福 Hanzi are logograms developed for the writing of Chinese! ", 16) - assert.Equal(t, "幸福 Hanzi are logograms developed for the writing of Chinese", result) + t.Run("Foo", func(t *testing.T) { + result := Trim("Foo", 16) + assert.Equal(t, "Foo", result) + assert.Equal(t, 3, len(result)) + }) + t.Run("TrimFoo", func(t *testing.T) { + result := Trim(" Foo ", 16) + assert.Equal(t, "Foo", result) + assert.Equal(t, 3, len(result)) + }) + t.Run("TooLong", func(t *testing.T) { + result := Trim(" 幸福 Hanzi are logograms developed for the writing of Chinese! ", 16) + assert.Equal(t, "幸福 Hanzi are", result) + assert.Equal(t, 16, len(result)) + }) + t.Run("ToASCII", func(t *testing.T) { + result := Trim(ToASCII(strings.ToLower(" 幸福 Hanzi are logograms developed for the writing of Chinese! ")), TrimTypeString) + assert.Equal(t, "hanzi are logograms developed for the wr", result) + assert.Equal(t, 40, len(result)) + }) + t.Run("Empty", func(t *testing.T) { + result := Trim("", 999) + assert.Equal(t, "", result) + assert.Equal(t, 0, len(result)) + }) } func TestSanitizeTypeString(t *testing.T) { result := SanitizeTypeString(" 幸福 Hanzi are logograms developed for the writing of Chinese! ") - assert.Equal(t, "hanzi are logograms developed for the writing of chinese", result) + assert.Equal(t, "hanzi are logograms developed for the wr", result) + assert.Equal(t, TrimTypeString, len(result)) } diff --git a/internal/migrate/dialect_mysql.go b/internal/migrate/dialect_mysql.go index 2b9c42b6e..6d2b976ad 100644 --- a/internal/migrate/dialect_mysql.go +++ b/internal/migrate/dialect_mysql.go @@ -12,4 +12,9 @@ var DialectMySQL = Migrations{ Dialect: "mysql", Statements: []string{"DROP INDEX idx_places_place_label ON `places`;", "DROP INDEX uix_places_label ON `places`;"}, }, + { + ID: "20220103-115400", + Dialect: "mysql", + Statements: []string{"ALTER TABLE files MODIFY file_projection VARBINARY(40) NULL;", "ALTER TABLE files MODIFY file_color_profile VARBINARY(40) NULL;"}, + }, } diff --git a/internal/migrate/mysql/20220103-115400.sql b/internal/migrate/mysql/20220103-115400.sql new file mode 100644 index 000000000..143a017ad --- /dev/null +++ b/internal/migrate/mysql/20220103-115400.sql @@ -0,0 +1,2 @@ +ALTER TABLE files MODIFY file_projection VARBINARY(40) NULL; +ALTER TABLE files MODIFY file_color_profile VARBINARY(40) NULL; \ No newline at end of file diff --git a/internal/photoprism/convert.go b/internal/photoprism/convert.go index f43e33eb6..e66740c71 100644 --- a/internal/photoprism/convert.go +++ b/internal/photoprism/convert.go @@ -397,7 +397,7 @@ func (c *Convert) AvcConvertCommand(f *MediaFile, avcName, codecName string) (re "-r", "30", "-b:v", c.AvcBitrate(f), "-f", "mp4", - "-y", + "-y", avcName, ) } else {