Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 32 additions & 25 deletions server/web/api/upload.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
package api

import (
"mime/multipart"
"net/http"

"server/log"
set "server/settings"
"server/torr"
"server/torr/state"
"server/web/api/utils"

"github.com/gin-gonic/gin"
)

// torrentUpload godoc
//
// @Summary Add .torrent file
// @Description Only one file support.
// @Summary Add .torrent files
// @Description Supports multiple files. Returns array of statuses.
//
// @Tags API
//
// @Param file formData file true "Torrent file to insert"
// @Param file formData file true "Torrent file(s) to insert"
// @Param save formData string false "Save to DB"
// @Param title formData string false "Torrent title"
// @Param title formData string false "Torrent title (single file only)"
// @Param category formData string false "Torrent category"
// @Param poster formData string false "Torrent poster"
// @Param poster formData string false "Torrent poster (single file only)"
// @Param data formData string false "Torrent data"
//
// @Accept multipart/form-data
//
// @Produce json
// @Success 200 {object} state.TorrentStatus "Torrent status"
// @Success 200 {array} state.TorrentStatus "Torrent statuses"
// @Router /torrent/upload [post]
func torrentUpload(c *gin.Context) {
form, err := c.MultipartForm()
Expand All @@ -55,24 +57,34 @@ func torrentUpload(c *gin.Context) {
if len(form.Value["data"]) > 0 {
data = form.Value["data"][0]
}
var tor *torr.Torrent
for name, file := range form.File {
log.TLogln("add .torrent", name)

torrFile, err := file[0].Open()
var files []*multipart.FileHeader
for _, fh := range form.File {
files = append(files, fh...)
}

var stats []*state.TorrentStatus
for _, fh := range files {
log.TLogln("add .torrent", fh.Filename)

torrFile, err := fh.Open()
if err != nil {
log.TLogln("error upload torrent:", err)
continue
}
defer torrFile.Close()

spec, err := utils.ParseFile(torrFile)
torrFile.Close()
if err != nil {
log.TLogln("error upload torrent:", err)
continue
}

tor, err = torr.AddTorrent(spec, title, poster, data, category)
tor, err := torr.AddTorrent(spec, title, poster, data, category)
if err != nil {
log.TLogln("error upload torrent:", err)
continue
}

if tor.Data != "" && set.BTsets.EnableDebug {
log.TLogln("torrent data:", tor.Data)
Expand All @@ -81,27 +93,22 @@ func torrentUpload(c *gin.Context) {
log.TLogln("torrent category:", tor.Category)
}

if err != nil {
log.TLogln("error upload torrent:", err)
continue
}

go func() {
if !tor.GotInfo() {
go func(t *torr.Torrent) {
if !t.GotInfo() {
log.TLogln("error add torrent:", "torrent connection timeout")
return
}

if tor.Title == "" {
tor.Title = tor.Name()
if t.Title == "" {
t.Title = t.Name()
}

if save {
torr.SaveTorrentToDB(tor)
torr.SaveTorrentToDB(t)
}
}()
}(tor)

break
stats = append(stats, tor.Status())
}
c.JSON(200, tor.Status())
c.JSON(200, stats)
}
20 changes: 10 additions & 10 deletions server/web/pages/template/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,20 @@ var Mstile150x150png []byte
//go:embed pages/site.webmanifest
var Sitewebmanifest []byte

//go:embed pages/static/js/2.d0681903.chunk.js
var Staticjs2d0681903chunkjs []byte
//go:embed pages/static/js/2.c7959c35.chunk.js
var Staticjs2c7959c35chunkjs []byte

//go:embed pages/static/js/2.d0681903.chunk.js.LICENSE.txt
var Staticjs2d0681903chunkjsLICENSEtxt []byte
//go:embed pages/static/js/2.c7959c35.chunk.js.LICENSE.txt
var Staticjs2c7959c35chunkjsLICENSEtxt []byte

//go:embed pages/static/js/2.d0681903.chunk.js.map
var Staticjs2d0681903chunkjsmap []byte
//go:embed pages/static/js/2.c7959c35.chunk.js.map
var Staticjs2c7959c35chunkjsmap []byte

//go:embed pages/static/js/main.53e2dc27.chunk.js
var Staticjsmain53e2dc27chunkjs []byte
//go:embed pages/static/js/main.c937891b.chunk.js
var Staticjsmainc937891bchunkjs []byte

//go:embed pages/static/js/main.53e2dc27.chunk.js.map
var Staticjsmain53e2dc27chunkjsmap []byte
//go:embed pages/static/js/main.c937891b.chunk.js.map
var Staticjsmainc937891bchunkjsmap []byte

//go:embed pages/static/js/runtime-main.5ed86a79.js
var Staticjsruntimemain5ed86a79js []byte
Expand Down
14 changes: 7 additions & 7 deletions server/web/pages/template/pages/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"files": {
"main.js": "./static/js/main.53e2dc27.chunk.js",
"main.js.map": "./static/js/main.53e2dc27.chunk.js.map",
"main.js": "./static/js/main.c937891b.chunk.js",
"main.js.map": "./static/js/main.c937891b.chunk.js.map",
"runtime-main.js": "./static/js/runtime-main.5ed86a79.js",
"runtime-main.js.map": "./static/js/runtime-main.5ed86a79.js.map",
"static/js/2.d0681903.chunk.js": "./static/js/2.d0681903.chunk.js",
"static/js/2.d0681903.chunk.js.map": "./static/js/2.d0681903.chunk.js.map",
"static/js/2.c7959c35.chunk.js": "./static/js/2.c7959c35.chunk.js",
"static/js/2.c7959c35.chunk.js.map": "./static/js/2.c7959c35.chunk.js.map",
"index.html": "./index.html",
"static/js/2.d0681903.chunk.js.LICENSE.txt": "./static/js/2.d0681903.chunk.js.LICENSE.txt"
"static/js/2.c7959c35.chunk.js.LICENSE.txt": "./static/js/2.c7959c35.chunk.js.LICENSE.txt"
},
"entrypoints": [
"static/js/runtime-main.5ed86a79.js",
"static/js/2.d0681903.chunk.js",
"static/js/main.53e2dc27.chunk.js"
"static/js/2.c7959c35.chunk.js",
"static/js/main.c937891b.chunk.js"
]
}
2 changes: 1 addition & 1 deletion server/web/pages/template/pages/index.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions server/web/pages/template/pages/static/js/2.c7959c35.chunk.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions server/web/pages/template/pages/static/js/2.d0681903.chunk.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions server/web/pages/template/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func RouteWebPages(route gin.IRouter) {
etag := fmt.Sprintf("%x", md5.Sum(Browserconfigxml))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/xml; charset=utf-8", Browserconfigxml)
c.Data(200, "application/xml; charset=utf-8", Browserconfigxml)
})

route.GET("/dlnaicon-120.png", func(c *gin.Context) {
Expand Down Expand Up @@ -280,39 +280,39 @@ func RouteWebPages(route gin.IRouter) {
c.Data(200, "application/manifest+json", Sitewebmanifest)
})

route.GET("/static/js/2.d0681903.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2d0681903chunkjs))
route.GET("/static/js/2.c7959c35.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2c7959c35chunkjs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/javascript; charset=utf-8", Staticjs2d0681903chunkjs)
c.Data(200, "text/javascript; charset=utf-8", Staticjs2c7959c35chunkjs)
})

route.GET("/static/js/2.d0681903.chunk.js.LICENSE.txt", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2d0681903chunkjsLICENSEtxt))
route.GET("/static/js/2.c7959c35.chunk.js.LICENSE.txt", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2c7959c35chunkjsLICENSEtxt))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/plain; charset=utf-8", Staticjs2d0681903chunkjsLICENSEtxt)
c.Data(200, "text/plain; charset=utf-8", Staticjs2c7959c35chunkjsLICENSEtxt)
})

route.GET("/static/js/2.d0681903.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2d0681903chunkjsmap))
route.GET("/static/js/2.c7959c35.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2c7959c35chunkjsmap))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/json", Staticjs2d0681903chunkjsmap)
c.Data(200, "application/json", Staticjs2c7959c35chunkjsmap)
})

route.GET("/static/js/main.53e2dc27.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain53e2dc27chunkjs))
route.GET("/static/js/main.c937891b.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmainc937891bchunkjs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/javascript; charset=utf-8", Staticjsmain53e2dc27chunkjs)
c.Data(200, "text/javascript; charset=utf-8", Staticjsmainc937891bchunkjs)
})

route.GET("/static/js/main.53e2dc27.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain53e2dc27chunkjsmap))
route.GET("/static/js/main.c937891b.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmainc937891bchunkjsmap))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/json", Staticjsmain53e2dc27chunkjsmap)
c.Data(200, "application/json", Staticjsmainc937891bchunkjsmap)
})

route.GET("/static/js/runtime-main.5ed86a79.js", func(c *gin.Context) {
Expand Down
Loading