Add category associated to each torrent

This commit is contained in:
LIAUD Corentin
2023-11-22 14:08:10 +01:00
parent 286609acec
commit 8c92856595
22 changed files with 171 additions and 70 deletions

View File

@@ -55,7 +55,7 @@ func play(c *gin.Context) {
}
if tor.Stat == state.TorrentInDB {
tor, err = torr.AddTorrent(spec, tor.Title, tor.Poster, tor.Data)
tor, err = torr.AddTorrent(spec, tor.Title, tor.Poster, tor.Data, tor.Category)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return

View File

@@ -96,7 +96,7 @@ func stream(c *gin.Context) {
data = tor.Data
}
if tor == nil || tor.Stat == state.TorrentInDB {
tor, err = torr.AddTorrent(spec, title, poster, data)
tor, err = torr.AddTorrent(spec, title, poster, data, tor.Category)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
@@ -170,6 +170,7 @@ func streamNoAuth(c *gin.Context) {
title := c.Query("title")
poster := c.Query("poster")
data := ""
category := c.Query("category")
if link == "" {
c.AbortWithError(http.StatusBadRequest, errors.New("link should not be empty"))
@@ -194,9 +195,10 @@ func streamNoAuth(c *gin.Context) {
title = tor.Title
poster = tor.Poster
data = tor.Data
category = tor.Category
if tor.Stat == state.TorrentInDB {
tor, err = torr.AddTorrent(spec, title, poster, data)
tor, err = torr.AddTorrent(spec, title, poster, data, category)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return

View File

@@ -21,6 +21,7 @@ type torrReqJS struct {
Link string `json:"link,omitempty"`
Hash string `json:"hash,omitempty"`
Title string `json:"title,omitempty"`
Category string `json:"category,omitempty"`
Poster string `json:"poster,omitempty"`
Data string `json:"data,omitempty"`
SaveToDB bool `json:"save_to_db,omitempty"`
@@ -90,7 +91,10 @@ func addTorrent(req torrReqJS, c *gin.Context) {
return
}
tor, err := torr.AddTorrent(torrSpec, req.Title, req.Poster, req.Data)
tor, err := torr.AddTorrent(torrSpec, req.Title, req.Poster, req.Data, req.Category)
log.TLogln("Final torrent category: ", tor.Category)
if err != nil {
log.TLogln("error add torrent:", err)
c.AbortWithError(http.StatusInternalServerError, err)

View File

@@ -20,6 +20,7 @@ import (
// @Param file formData file true "Torrent file to insert"
// @Param save formData string false "Save to DB"
// @Param title formData string false "Torrent title"
// @Param category formData string false "Torrent category"
// @Param poster formData string false "Torrent poster"
// @Param data formData string false "Torrent data"
//
@@ -41,6 +42,10 @@ func torrentUpload(c *gin.Context) {
if len(form.Value["title"]) > 0 {
title = form.Value["title"][0]
}
category := ""
if len(form.Value["category"]) > 0 {
category = form.Value["category"][0]
}
poster := ""
if len(form.Value["poster"]) > 0 {
poster = form.Value["poster"][0]
@@ -66,7 +71,7 @@ func torrentUpload(c *gin.Context) {
continue
}
tor, err = torr.AddTorrent(spec, title, poster, data)
tor, err = torr.AddTorrent(spec, title, poster, data, category)
if err != nil {
log.TLogln("error upload torrent:", err)
continue