Add FileList view to view.html template
Also added the code for FileList loading on torrentService.
Cette révision appartient à :
Parent
f64ecb3d0f
révision
839e6068df
6 fichiers modifiés avec 45 ajouts et 10 suppressions
|
@ -58,7 +58,11 @@ func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error) {
|
|||
if db.Error != nil {
|
||||
return db, db.Error
|
||||
}
|
||||
db.AutoMigrate(&model.Torrent{}, &model.TorrentReport{}, &model.File{})
|
||||
db.AutoMigrate(&model.Torrent{}, &model.TorrentReport{})
|
||||
if db.Error != nil {
|
||||
return db, db.Error
|
||||
}
|
||||
db.AutoMigrate(&model.File{})
|
||||
if db.Error != nil {
|
||||
return db, db.Error
|
||||
}
|
||||
|
|
|
@ -5,12 +5,10 @@ type File struct {
|
|||
TorrentID uint `gorm:"column:torrent_id"`
|
||||
Path string `gorm:"column:path"`
|
||||
Filesize int64 `gorm:"column:filesize"`
|
||||
|
||||
Torrent *Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
|
||||
}
|
||||
|
||||
// Returns the total size of memory allocated for this struct
|
||||
func (f File) Size() int {
|
||||
return (1 + len(f.Path) + 2) * 8;
|
||||
return (2 + len(f.Path) + 2) * 8;
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ type CommentJSON struct {
|
|||
|
||||
type FileJSON struct {
|
||||
Path string `json:"path"`
|
||||
Length int64 `json:"length"`
|
||||
Filesize string `json:"filesize"`
|
||||
}
|
||||
|
||||
type TorrentJSON struct {
|
||||
|
@ -116,7 +116,7 @@ type TorrentJSON struct {
|
|||
Leechers uint32 `json:"leechers"`
|
||||
Completed uint32 `json:"completed"`
|
||||
LastScrape time.Time `json:"last_scrape"`
|
||||
FileList []File `json:"file_list"`
|
||||
FileList []FileJSON `json:"file_list"`
|
||||
}
|
||||
|
||||
// ToJSON converts a model.Torrent to its equivalent JSON structure
|
||||
|
@ -129,6 +129,10 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
|||
for _, c := range t.Comments {
|
||||
commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), Content: util.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC()})
|
||||
}
|
||||
fileListJSON := make([]FileJSON, 0, len(t.FileList))
|
||||
for _, f := range t.FileList {
|
||||
fileListJSON = append(fileListJSON, FileJSON{Path: f.Path, Filesize: util.FormatFilesize2(f.Filesize)})
|
||||
}
|
||||
uploader := ""
|
||||
if t.Uploader != nil {
|
||||
uploader = t.Uploader.Username
|
||||
|
@ -162,7 +166,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
|||
Seeders: t.Seeders,
|
||||
Completed: t.Completed,
|
||||
LastScrape: t.LastScrape,
|
||||
FileList: t.FileList,
|
||||
FileList: fileListJSON,
|
||||
}
|
||||
|
||||
return res
|
||||
|
|
|
@ -53,7 +53,7 @@ func GetTorrentById(id string) (torrent model.Torrent, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments")
|
||||
tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments").Preload("FileList")
|
||||
err = tmp.Error
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -80,6 +80,27 @@
|
|||
<hr>
|
||||
</div>
|
||||
</div>
|
||||
{{ if gt (len .FileList) 0 }}
|
||||
<div class="row" id="files">
|
||||
<div class="col-md-12">
|
||||
<h4>{{T "files"}}</h4>
|
||||
<div class="table-responsive">
|
||||
<table class="table custom-table-hover">
|
||||
<tr>
|
||||
<th class="col-xs-8">{{T "filename"}}</th>
|
||||
<th class="col-xs-1">{{T "size"}}</th>
|
||||
</tr>
|
||||
{{ range .FileList }}
|
||||
<tr>
|
||||
<td>{{.Path}}</td>
|
||||
<td>{{.Filesize}}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
<div class="row" id="comments">
|
||||
<div class="col-md-12">
|
||||
<h4>{{T "comments"}}</h4>
|
||||
|
|
|
@ -646,5 +646,13 @@
|
|||
{
|
||||
"id": "delete",
|
||||
"translation": "Delete"
|
||||
},
|
||||
{
|
||||
"id": "files",
|
||||
"translation": "Files"
|
||||
},
|
||||
{
|
||||
"id": "filename",
|
||||
"translation": "Filename"
|
||||
}
|
||||
]
|
||||
|
|
Référencer dans un nouveau ticket