Work on sqlite support

This commit is contained in:
viktorstrate
2021-01-17 12:45:23 +01:00
parent f711da4d9c
commit fcdb5b4e7b
7 changed files with 45 additions and 17 deletions

View File

@@ -1,8 +1,6 @@
package models
import (
"crypto/md5"
"encoding/hex"
"path"
"strings"
"time"
@@ -40,12 +38,10 @@ func (Media) TableName() string {
func (m *Media) BeforeSave(tx *gorm.DB) error {
// Update hashes
hash := md5.Sum([]byte(m.Path))
m.PathHash = hex.EncodeToString(hash[:])
m.PathHash = MD5Hash(m.Path)
if m.SideCarPath != nil {
hash = md5.Sum([]byte(*m.SideCarPath))
encodedHash := hex.EncodeToString(hash[:])
encodedHash := MD5Hash(*m.SideCarPath)
m.SideCarHash = &encodedHash
}

View File

@@ -1,6 +1,9 @@
package models
import (
"crypto/md5"
"encoding/hex"
"gorm.io/gorm"
"gorm.io/gorm/clause"
)
@@ -38,3 +41,9 @@ func (filter *Filter) FormatSQL(tx *gorm.DB) *gorm.DB {
return tx
}
// MD5Hash hashes value to a 32 length digest, the result is the same as the MYSQL function md5()
func MD5Hash(value string) string {
hash := md5.Sum([]byte(value))
return hex.EncodeToString(hash[:])
}