fix torrents not creating because they are duplicates

This commit is contained in:
2026-02-03 18:38:01 +03:00
parent 7d647a00b4
commit 82b0c567fe
4 changed files with 40 additions and 11 deletions

View File

@@ -46,7 +46,7 @@ func (m *Model) Init() {
m.db.MustExec(`CREATE TABLE IF NOT EXISTS torrents (
id integer primary key,
title varchar not null,
guid varchar not null unique,
guid varchar not null,
indexer varchar not null,
pubdate datetime not null,
size integer not null,

View File

@@ -30,3 +30,14 @@ func (m *Model) GetTorrentById(torrentId int64) (*Torrent, error) {
return torrent, nil
}
func (m *Model) GetTorrentByGuid(guid string) (*Torrent, error) {
torrent := new(Torrent)
row := m.db.QueryRowx("SELECT * FROM torrents WHERE guid = ?", guid)
if err := row.StructScan(torrent); err != nil {
return nil, fmt.Errorf("torrent not found: %v", err)
}
return torrent, nil
}