Get FileList of new uploaded .torrent files
Cette révision appartient à :
Parent
58869114d7
révision
720c27e38f
2 fichiers modifiés avec 29 ajouts et 0 suppressions
|
@ -24,6 +24,13 @@ import (
|
|||
"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
|
||||
type UploadForm struct {
|
||||
Name string
|
||||
|
@ -39,6 +46,7 @@ type UploadForm struct {
|
|||
SubCategoryID int
|
||||
Filesize int64
|
||||
Filepath string
|
||||
FileList []UploadedFile
|
||||
}
|
||||
|
||||
// TODO: these should be in another package (?)
|
||||
|
@ -150,6 +158,15 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
|
||||
// extract filesize
|
||||
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 {
|
||||
// No torrent file provided
|
||||
magnetUrl, err := url.Parse(string(f.Magnet)) //?
|
||||
|
|
|
@ -60,6 +60,18 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
|
|||
Description: uploadForm.Description,
|
||||
UploaderID: user.ID}
|
||||
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))
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
|
|
Référencer dans un nouveau ticket