More database stuff

master
Noah Pederson 6 years ago
parent 863e4923fd
commit 8fae32d143
  1. 4
      database/database.go
  2. 10
      models/comics.go
  3. 16
      scanner/comicscanner.go

@ -158,10 +158,12 @@ func AddComic(comic models.ComicInfo, file models.ComicFile) bool {
log.Fatal(err)
}
stmt, err := tx.Prepare(INSERT_COMIC_INFO)
stmt, err := tx.Prepare(INSERT_COMIC_FILE_INFO)
res, _ := stmt.Exec(file.RelativePath, file.AbsolutePath, file.Hash, file.FileSize)
if err != nil {
log.Fatal(err)
}
log.Printf("Results:%x", res)
defer stmt.Close()

@ -12,8 +12,8 @@ type ComicInfo struct {
Credits credit `json:"credits"`
Volume string `json:"volume"`
Genres []string `json:"genres"`
DateAdded int `json:"date_added"`
PublishDate int `json:"publish_date"`
DateAdded int64 `json:"date_added"`
PublishDate int64 `json:"publish_date"`
Synopsis string `json:"synopsis"`
Characters []string `json:"characters"`
Rating float32 `json:"rating"`
@ -27,7 +27,7 @@ type ComicFile struct {
RelativePath string `json:"relative_path"`
AbsolutePath string `json:"absolute_path"`
Hash string `json:"hash"` //MD5 hash
FileSize int `json:"filesize"`
FileSize int64 `json:"filesize"`
}
type credit struct {
@ -49,8 +49,8 @@ type UserProgress struct {
ComicInfoID int `json:"comic_info_id"`
Read bool `json:"read"`
Completed bool `json:"completed"`
DateLastRead int `json:"date_last_read"`
DateCompleted int `json:"date_completed"`
DateLastRead int64 `json:"date_last_read"`
DateCompleted int64 `json:"date_completed"`
LastReadPage int `json:"last_read_page"`
}

@ -10,6 +10,8 @@ import (
"path/filepath"
"strings"
"log"
"git.chiefnoah.tech/chiefnoah/gocomics/models"
"git.chiefnoah.tech/chiefnoah/gocomics/database"
)
func Scan(f string) error {
@ -33,8 +35,18 @@ func visit(p string, f os.FileInfo, e error) error {
log.Print("Error: ", err)
return err
}
md5 := md5.Sum(file)
fmt.Printf("MD5: %x\n", md5)
var comicfile models.ComicFile
checksum := md5.Sum(file)
n := len(checksum)
comicfile.Hash = string(checksum[:n])
comicfile.FileSize = int64(f.Size())
comicfile.AbsolutePath = p
comicfile.RelativePath = ""
fmt.Printf("MD5: %x\n", comicfile.Hash)
database.AddComic(models.ComicInfo{}, comicfile)
}
return nil

Loading…
Cancel
Save