Add hashes for each book

Check if the uploaded book is already in the library
This commit is contained in:
Las Zenow 2020-05-03 09:35:17 +00:00
parent 154867c50c
commit a1ee320eba
4 changed files with 41 additions and 5 deletions

View file

@ -1,6 +1,8 @@
package database
import (
log "github.com/cihub/seelog"
"strings"
"time"
@ -17,9 +19,10 @@ type Book struct {
Description string
Tags []string `pg:"tags,array"`
Date string
Lang string `pg:"type:varchar(3)"`
Isbn string `pg:"type:varchar(13)"`
FileSize int `pg:"type:integer"`
Lang string `pg:"type:varchar(3)"`
Isbn string `pg:"type:varchar(13)"`
FileSize int `pg:"type:integer"`
FileHash []byte
Cover bool `pg:",notnull"`
Active bool `pg:",notnull"`
UploadDate time.Time `pg:"type:timestamp"`
@ -165,6 +168,18 @@ func (db *pgDB) IsBookActive(id string) bool {
return active[0]
}
// ExistsBookHash checks if the given hash matches the hash of any book in the lbirary
func (db *pgDB) ExistsBookHash(hash []byte) bool {
count, err := db.sql.Model(&Book{}).
Where("file_hash = ?", hash).
Count()
if err != nil {
log.Warnf("There was an error looking for the hash: %v", err)
return false
}
return count > 0
}
type columnq struct {
column string
value string