From ef30870ce38cad25be87a423aa3ca05a893e4e76 Mon Sep 17 00:00:00 2001 From: kilo Date: Wed, 8 Nov 2017 08:50:52 +0100 Subject: [PATCH] Update torrent.go --- models/torrent.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/models/torrent.go b/models/torrent.go index e68ed7d0..157c7378 100644 --- a/models/torrent.go +++ b/models/torrent.go @@ -21,6 +21,7 @@ import ( "github.com/NyaaPantsu/nyaa/utils/format" "github.com/NyaaPantsu/nyaa/utils/log" "github.com/NyaaPantsu/nyaa/utils/sanitize" + "github.com/anacrolix/torrent" "github.com/bradfitz/slice" "github.com/fatih/structs" ) @@ -463,6 +464,24 @@ func (t *Torrent) Update(unscope bool) (int, error) { return http.StatusOK, nil } +func (t *Torrent) CreateFileList(Files []torrent.File) ([]File, error) { + var createdFilelist []File + t.Filesize = 0 + + for _, uploadedFile := range Files { + file := File{TorrentID: t.ID, Filesize: uploadedFile.Length()} + err := file.SetPath([]string{uploadedFile.DisplayPath(), ""}) + if err != nil { + return []File{}, err + } + createdFilelist = append(createdFilelist, file) + t.Filesize += uploadedFile.Length() + ORM.Create(&file) + } + + return createdFilelist, nil +} + // UpdateUnscope : Update a torrent based on model func (t *Torrent) UpdateUnscope() (int, error) { return t.Update(true)