Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Get FileList of new uploaded .torrent files

Cette révision appartient à :
ElegantMonkey 2017-05-14 12:28:48 -03:00
Parent 58869114d7
révision 720c27e38f
2 fichiers modifiés avec 29 ajouts et 0 suppressions

Voir le fichier

@ -24,6 +24,13 @@ import (
"github.com/zeebo/bencode" "github.com/zeebo/bencode"
) )
// Use this, because we seem to avoid using models, and we would need
// the torrent ID to create the File in the DB
type UploadedFile struct {
Path string
Filesize int64
}
// UploadForm serializing HTTP form for torrent upload // UploadForm serializing HTTP form for torrent upload
type UploadForm struct { type UploadForm struct {
Name string Name string
@ -39,6 +46,7 @@ type UploadForm struct {
SubCategoryID int SubCategoryID int
Filesize int64 Filesize int64
Filepath string Filepath string
FileList []UploadedFile
} }
// TODO: these should be in another package (?) // TODO: these should be in another package (?)
@ -150,6 +158,15 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
// extract filesize // extract filesize
f.Filesize = int64(torrent.TotalSize()) f.Filesize = int64(torrent.TotalSize())
// extract filelist
fileInfos := torrent.Info.GetFiles()
for _, info := range fileInfos {
f.FileList = append(f.FileList, UploadedFile{
Path: info.Path.FilePath(),
Filesize: int64(info.Length),
})
}
} else { } else {
// No torrent file provided // No torrent file provided
magnetUrl, err := url.Parse(string(f.Magnet)) //? magnetUrl, err := url.Parse(string(f.Magnet)) //?

Voir le fichier

@ -60,6 +60,18 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
Description: uploadForm.Description, Description: uploadForm.Description,
UploaderID: user.ID} UploaderID: user.ID}
db.ORM.Create(&torrent) db.ORM.Create(&torrent)
// add filelist to files db, if we have one
if len(uploadForm.FileList) > 0 {
for _, uploadedFile := range uploadForm.FileList {
file := model.File{
TorrentID: torrent.ID,
Path: uploadedFile.Path,
Filesize: uploadedFile.Filesize}
db.ORM.Create(&file)
}
}
url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.ID), 10)) url, err := Router.Get("view_torrent").URL("id", strconv.FormatUint(uint64(torrent.ID), 10))
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)