add id to file struct

This commit is contained in:
yourok
2019-09-20 13:10:23 +03:00
parent c23483fdc0
commit 7309272e7d

View File

@@ -19,6 +19,7 @@ type Torrent struct {
type File struct { type File struct {
Name string Name string
Id int
Size int64 Size int64
Viewed bool Viewed bool
} }
@@ -101,6 +102,12 @@ func SaveTorrentDB(torrent *Torrent) error {
if err != nil { if err != nil {
return fmt.Errorf("error save torrent files: %v", err) return fmt.Errorf("error save torrent files: %v", err)
} }
err = ffdb.Put([]byte("Id"), i2b(int64(f.Id)))
if err != nil {
return fmt.Errorf("error save torrent files: %v", err)
}
err = ffdb.Put([]byte("Size"), i2b(f.Size)) err = ffdb.Put([]byte("Size"), i2b(f.Size))
if err != nil { if err != nil {
return fmt.Errorf("error save torrent files: %v", err) return fmt.Errorf("error save torrent files: %v", err)
@@ -189,7 +196,13 @@ func LoadTorrentDB(hash string) (*Torrent, error) {
return fmt.Errorf("error load torrent files") return fmt.Errorf("error load torrent files")
} }
tmp := ffdb.Get([]byte("Size")) tmp := ffdb.Get([]byte("Id"))
if tmp == nil {
return fmt.Errorf("error load torrent file")
}
file.Id = int(b2i(tmp))
tmp = ffdb.Get([]byte("Size"))
if tmp == nil { if tmp == nil {
return fmt.Errorf("error load torrent file") return fmt.Errorf("error load torrent file")
} }