mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 22:09:20 +00:00
Work on sqlite support
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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[:])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user