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 {
|
if db.Error != nil {
|
||||||
return db, db.Error
|
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 {
|
if db.Error != nil {
|
||||||
return db, db.Error
|
return db, db.Error
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,11 @@ type File struct {
|
||||||
ID uint `gorm:"column:file_id;primary_key"`
|
ID uint `gorm:"column:file_id;primary_key"`
|
||||||
TorrentID uint `gorm:"column:torrent_id"`
|
TorrentID uint `gorm:"column:torrent_id"`
|
||||||
Path string `gorm:"column:path"`
|
Path string `gorm:"column:path"`
|
||||||
Filesize int64 `gorm:"column:filesize"`
|
Filesize int64 `gorm:"column:filesize"`
|
||||||
|
|
||||||
Torrent *Torrent `gorm:"AssociationForeignKey:TorrentID;ForeignKey:torrent_id"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the total size of memory allocated for this struct
|
// Returns the total size of memory allocated for this struct
|
||||||
func (f File) Size() int {
|
func (f File) Size() int {
|
||||||
return (1 + len(f.Path) + 2) * 8;
|
return (2 + len(f.Path) + 2) * 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,8 @@ type CommentJSON struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileJSON struct {
|
type FileJSON struct {
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Length int64 `json:"length"`
|
Filesize string `json:"filesize"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TorrentJSON struct {
|
type TorrentJSON struct {
|
||||||
|
@ -116,7 +116,7 @@ type TorrentJSON struct {
|
||||||
Leechers uint32 `json:"leechers"`
|
Leechers uint32 `json:"leechers"`
|
||||||
Completed uint32 `json:"completed"`
|
Completed uint32 `json:"completed"`
|
||||||
LastScrape time.Time `json:"last_scrape"`
|
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
|
// ToJSON converts a model.Torrent to its equivalent JSON structure
|
||||||
|
@ -129,6 +129,10 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
||||||
for _, c := range t.Comments {
|
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()})
|
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 := ""
|
uploader := ""
|
||||||
if t.Uploader != nil {
|
if t.Uploader != nil {
|
||||||
uploader = t.Uploader.Username
|
uploader = t.Uploader.Username
|
||||||
|
@ -162,7 +166,7 @@ func (t *Torrent) ToJSON() TorrentJSON {
|
||||||
Seeders: t.Seeders,
|
Seeders: t.Seeders,
|
||||||
Completed: t.Completed,
|
Completed: t.Completed,
|
||||||
LastScrape: t.LastScrape,
|
LastScrape: t.LastScrape,
|
||||||
FileList: t.FileList,
|
FileList: fileListJSON,
|
||||||
}
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
|
@ -53,7 +53,7 @@ func GetTorrentById(id string) (torrent model.Torrent, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments")
|
tmp := db.ORM.Where("torrent_id = ?", id).Preload("Comments").Preload("FileList")
|
||||||
err = tmp.Error
|
err = tmp.Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -80,6 +80,27 @@
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
</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="row" id="comments">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<h4>{{T "comments"}}</h4>
|
<h4>{{T "comments"}}</h4>
|
||||||
|
|
|
@ -646,5 +646,13 @@
|
||||||
{
|
{
|
||||||
"id": "delete",
|
"id": "delete",
|
||||||
"translation": "Delete"
|
"translation": "Delete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "files",
|
||||||
|
"translation": "Files"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "filename",
|
||||||
|
"translation": "Filename"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Référencer dans un nouveau ticket