Metadata: Limit file projection & color_profile to 40 ASCII chars #1830

This commit is contained in:
Michael Mayer 2022-01-03 12:09:00 +01:00
parent f19ea6c578
commit 7823d7faaa
7 changed files with 42 additions and 9 deletions

View file

@ -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"`

View file

@ -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))
})
}

View file

@ -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]
}
}

View file

@ -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))
}

View file

@ -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;"},
},
}

View file

@ -0,0 +1,2 @@
ALTER TABLE files MODIFY file_projection VARBINARY(40) NULL;
ALTER TABLE files MODIFY file_color_profile VARBINARY(40) NULL;

View file

@ -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 {