Merge branch 'master' into old-engine

This commit is contained in:
nikk gitanes
2023-03-02 05:02:55 +03:00
93 changed files with 170 additions and 119 deletions

View File

@@ -1,25 +1,15 @@
package api
import (
"context"
"errors"
"fmt"
"net/http"
"os"
"os/exec"
"path/filepath"
"server/utils"
"server/ffprobe"
settings2 "server/settings"
"github.com/gin-gonic/gin"
"gopkg.in/vansante/go-ffprobe.v2"
)
func commandExists(cmd string) bool {
_, err := exec.LookPath(cmd)
return err == nil
}
func ffp(c *gin.Context) {
hash := c.Param("hash")
indexStr := c.Param("id")
@@ -29,26 +19,9 @@ func ffp(c *gin.Context) {
return
}
host := utils.GetScheme(c) + "://" + c.Request.Host + "/stream?link=" + hash + "&index=" + indexStr + "&play"
// log.Println("ffprobe", host)
host := "http://127.0.0.1:" + settings2.Port + "/stream?link=" + hash + "&index=" + indexStr + "&play"
ctx, cancelFn := context.WithCancel(context.Background())
defer cancelFn()
// path lookup
path, err := exec.LookPath("ffprobe")
if err == nil {
// log.Println("ffprobe found in", path)
ffprobe.SetFFProbeBinPath(path)
} else {
// log.Println("ffprobe not found in $PATH")
// working dir
if _, err := os.Stat("ffprobe"); os.IsNotExist(err) {
ffprobe.SetFFProbeBinPath(filepath.Dir(os.Args[0]) + "/ffprobe")
}
}
data, err := ffprobe.ProbeURL(ctx, host)
data, err := ffprobe.ProbeUrl(host)
if err != nil {
c.AbortWithError(http.StatusBadRequest, fmt.Errorf("error getting data: %v", err))
return

View File

@@ -62,8 +62,9 @@ func BasicAuth(accounts gin.Accounts) gin.HandlerFunc {
pairs := processAccounts(accounts)
return func(c *gin.Context) {
user, found := pairs.searchCredential(c.Request.Header.Get("Authorization"))
if !found {
if !found { // always accessible
if strings.HasPrefix(c.FullPath(), "/stream") ||
c.FullPath() == "/site.webmanifest" ||
// https://github.com/YouROK/TorrServer/issues/172
(strings.HasPrefix(c.FullPath(), "/play") && c.FullPath() != "/playlistall/all.m3u") {
c.Set("not_auth", true)

View File

@@ -28,8 +28,7 @@ func getTorrents(c *gin.Context) {
mi := metainfo.MetaInfo{
AnnounceList: ts.Trackers,
}
mag := mi.Magnet(ts.DisplayName, ts.InfoHash)
// mag := mi.Magnet(&ts.InfoHash, &metainfo.Info{Name: ts.DisplayName})
mag := mi.Magnet(&ts.InfoHash, &metainfo.Info{Name: ts.DisplayName})
http += "<p><a href='" + mag.String() + "'>magnet:?xt=urn:btih:" + mag.InfoHash.HexString() + "</a></p>"
}
http += "</div>"

View File

@@ -82,9 +82,6 @@ var Applesplash7501334jpg []byte
//go:embed pages/apple-splash-828-1792.jpg
var Applesplash8281792jpg []byte
//go:embed pages/apple-touch-icon.png
var Appletouchiconpng []byte
//go:embed pages/asset-manifest.json
var Assetmanifestjson []byte
@@ -103,17 +100,20 @@ var Favicon16x16png []byte
//go:embed pages/favicon-32x32.png
var Favicon32x32png []byte
//go:embed pages/favicon.ico
var Faviconico []byte
//go:embed pages/icon.png
var Iconpng []byte
//go:embed pages/index.html
var Indexhtml []byte
//go:embed pages/logo.png
var Logopng []byte
//go:embed pages/manifest-icon-192.maskable.png
var Manifesticon192maskablepng []byte
//go:embed pages/manifest-icon-512.maskable.png
var Manifesticon512maskablepng []byte
//go:embed pages/mstile-150x150.png
var Mstile150x150png []byte
//go:embed pages/site.webmanifest
var Sitewebmanifest []byte
@@ -127,11 +127,11 @@ var Staticjs2d3f8d41dchunkjsLICENSEtxt []byte
//go:embed pages/static/js/2.d3f8d41d.chunk.js.map
var Staticjs2d3f8d41dchunkjsmap []byte
//go:embed pages/static/js/main.4bd54915.chunk.js
var Staticjsmain4bd54915chunkjs []byte
//go:embed pages/static/js/main.e240e160.chunk.js
var Staticjsmaine240e160chunkjs []byte
//go:embed pages/static/js/main.4bd54915.chunk.js.map
var Staticjsmain4bd54915chunkjsmap []byte
//go:embed pages/static/js/main.e240e160.chunk.js.map
var Staticjsmaine240e160chunkjsmap []byte
//go:embed pages/static/js/runtime-main.64d07802.js
var Staticjsruntimemain64d07802js []byte

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 KiB

After

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 195 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 427 KiB

After

Width:  |  Height:  |  Size: 411 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 420 KiB

After

Width:  |  Height:  |  Size: 403 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 473 KiB

After

Width:  |  Height:  |  Size: 455 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 498 KiB

After

Width:  |  Height:  |  Size: 480 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 499 KiB

After

Width:  |  Height:  |  Size: 476 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 542 KiB

After

Width:  |  Height:  |  Size: 516 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 571 KiB

After

Width:  |  Height:  |  Size: 547 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 597 KiB

After

Width:  |  Height:  |  Size: 572 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 388 KiB

After

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 564 KiB

After

Width:  |  Height:  |  Size: 535 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 778 KiB

After

Width:  |  Height:  |  Size: 734 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 625 KiB

After

Width:  |  Height:  |  Size: 595 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 564 KiB

After

Width:  |  Height:  |  Size: 537 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 657 KiB

After

Width:  |  Height:  |  Size: 624 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 711 KiB

After

Width:  |  Height:  |  Size: 675 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 629 KiB

After

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 672 KiB

After

Width:  |  Height:  |  Size: 638 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 734 KiB

After

Width:  |  Height:  |  Size: 691 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 902 KiB

After

Width:  |  Height:  |  Size: 848 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 775 KiB

After

Width:  |  Height:  |  Size: 730 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 KiB

After

Width:  |  Height:  |  Size: 137 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 243 KiB

After

Width:  |  Height:  |  Size: 236 KiB

View File

@@ -1,7 +1,7 @@
{
"files": {
"main.js": "/static/js/main.4bd54915.chunk.js",
"main.js.map": "/static/js/main.4bd54915.chunk.js.map",
"main.js": "/static/js/main.e240e160.chunk.js",
"main.js.map": "/static/js/main.e240e160.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.64d07802.js",
"runtime-main.js.map": "/static/js/runtime-main.64d07802.js.map",
"static/js/2.d3f8d41d.chunk.js": "/static/js/2.d3f8d41d.chunk.js",
@@ -12,6 +12,6 @@
"entrypoints": [
"static/js/runtime-main.64d07802.js",
"static/js/2.d3f8d41d.chunk.js",
"static/js/main.4bd54915.chunk.js"
"static/js/main.e240e160.chunk.js"
]
}

View File

@@ -3,7 +3,8 @@
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#00a300</TileColor>
<TileColor>#00a572</TileColor>
<TileImage src="/mstile-150x150.png" />
</tile>
</msapplication>
</browserconfig>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -3,28 +3,16 @@
"short_name": "TorrServer",
"icons": [
{
"src": "manifest-icon-192.maskable.png",
"src": "icon.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "manifest-icon-192.maskable.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "manifest-icon-512.maskable.png",
"src": "logo.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "manifest-icon-512.maskable.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
],
"theme_color": "#ffffff",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -113,10 +113,6 @@ func RouteWebPages(route *gin.RouterGroup) {
c.Data(200, "image/jpeg", Applesplash8281792jpg)
})
route.GET("/apple-touch-icon.png", func(c *gin.Context) {
c.Data(200, "image/png", Appletouchiconpng)
})
route.GET("/asset-manifest.json", func(c *gin.Context) {
c.Data(200, "application/json", Assetmanifestjson)
})
@@ -141,6 +137,14 @@ func RouteWebPages(route *gin.RouterGroup) {
c.Data(200, "image/png", Favicon32x32png)
})
route.GET("/favicon.ico", func(c *gin.Context) {
c.Data(200, "image/vnd.microsoft.icon", Faviconico)
})
route.GET("/icon.png", func(c *gin.Context) {
c.Data(200, "image/png", Iconpng)
})
route.GET("/index.html", func(c *gin.Context) {
c.Data(200, "text/html; charset=utf-8", Indexhtml)
})
@@ -149,12 +153,8 @@ func RouteWebPages(route *gin.RouterGroup) {
c.Data(200, "image/png", Logopng)
})
route.GET("/manifest-icon-192.maskable.png", func(c *gin.Context) {
c.Data(200, "image/png", Manifesticon192maskablepng)
})
route.GET("/manifest-icon-512.maskable.png", func(c *gin.Context) {
c.Data(200, "image/png", Manifesticon512maskablepng)
route.GET("/mstile-150x150.png", func(c *gin.Context) {
c.Data(200, "image/png", Mstile150x150png)
})
route.GET("/site.webmanifest", func(c *gin.Context) {
@@ -173,12 +173,12 @@ func RouteWebPages(route *gin.RouterGroup) {
c.Data(200, "application/json", Staticjs2d3f8d41dchunkjsmap)
})
route.GET("/static/js/main.4bd54915.chunk.js", func(c *gin.Context) {
c.Data(200, "application/javascript; charset=utf-8", Staticjsmain4bd54915chunkjs)
route.GET("/static/js/main.e240e160.chunk.js", func(c *gin.Context) {
c.Data(200, "application/javascript; charset=utf-8", Staticjsmaine240e160chunkjs)
})
route.GET("/static/js/main.4bd54915.chunk.js.map", func(c *gin.Context) {
c.Data(200, "application/json", Staticjsmain4bd54915chunkjsmap)
route.GET("/static/js/main.e240e160.chunk.js.map", func(c *gin.Context) {
c.Data(200, "application/json", Staticjsmaine240e160chunkjsmap)
})
route.GET("/static/js/runtime-main.64d07802.js", func(c *gin.Context) {

View File

@@ -48,12 +48,13 @@ func Start(port string) {
// corsCfg.AllowHeaders = []string{"*"}
// corsCfg.AllowMethods = []string{"*"}
// corsCfg.AllowPrivateNetwork = true
corsCfg := cors.DefaultConfig()
corsCfg.AllowAllOrigins = true
corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}
// corsCfg := cors.DefaultConfig()
// corsCfg.AllowAllOrigins = true
// corsCfg.AllowHeaders = []string{"Origin", "Content-Length", "Content-Type", "X-Requested-With", "Accept", "Authorization"}
route := gin.New()
route.Use(log.WebLogger(), blocker.Blocker(), gin.Recovery(), cors.New(corsCfg), location.Default())
// cors.Default() allows all origins - https://github.com/gin-contrib/cors#default-allows-all-origins
route.Use(log.WebLogger(), blocker.Blocker(), gin.Recovery(), cors.Default(), location.Default())
route.GET("/echo", echo)