mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
Merge branch 'master' into old-engine
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/url"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"server/rutor"
|
||||
"server/rutor/models"
|
||||
)
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type cors struct {
|
||||
allowAllOrigins bool
|
||||
allowCredentials bool
|
||||
allowOriginFunc func(string) bool
|
||||
allowOrigins []string
|
||||
exposeHeaders []string
|
||||
normalHeaders http.Header
|
||||
preflightHeaders http.Header
|
||||
wildcardOrigins [][]string
|
||||
}
|
||||
|
||||
var (
|
||||
DefaultSchemas = []string{
|
||||
"http://",
|
||||
"https://",
|
||||
}
|
||||
ExtensionSchemas = []string{
|
||||
"chrome-extension://",
|
||||
"safari-extension://",
|
||||
"moz-extension://",
|
||||
"ms-browser-extension://",
|
||||
}
|
||||
FileSchemas = []string{
|
||||
"file://",
|
||||
}
|
||||
WebSocketSchemas = []string{
|
||||
"ws://",
|
||||
"wss://",
|
||||
}
|
||||
)
|
||||
|
||||
func newCors(config Config) *cors {
|
||||
if err := config.Validate(); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
return &cors{
|
||||
allowOriginFunc: config.AllowOriginFunc,
|
||||
allowAllOrigins: config.AllowAllOrigins,
|
||||
allowCredentials: config.AllowCredentials,
|
||||
allowOrigins: normalize(config.AllowOrigins),
|
||||
normalHeaders: generateNormalHeaders(config),
|
||||
preflightHeaders: generatePreflightHeaders(config),
|
||||
wildcardOrigins: config.parseWildcardRules(),
|
||||
}
|
||||
}
|
||||
|
||||
func (cors *cors) applyCors(c *gin.Context) {
|
||||
origin := c.Request.Header.Get("Origin")
|
||||
if len(origin) == 0 {
|
||||
// request is not a CORS request
|
||||
return
|
||||
}
|
||||
host := c.Request.Host
|
||||
|
||||
if origin == "http://"+host || origin == "https://"+host {
|
||||
// request is not a CORS request but have origin header.
|
||||
// for example, use fetch api
|
||||
return
|
||||
}
|
||||
|
||||
if !cors.validateOrigin(origin) {
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
cors.handlePreflight(c)
|
||||
defer c.AbortWithStatus(http.StatusNoContent) // Using 204 is better than 200 when the request status is OPTIONS
|
||||
} else {
|
||||
cors.handleNormal(c)
|
||||
}
|
||||
|
||||
if !cors.allowAllOrigins {
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
}
|
||||
}
|
||||
|
||||
func (cors *cors) validateWildcardOrigin(origin string) bool {
|
||||
for _, w := range cors.wildcardOrigins {
|
||||
if w[0] == "*" && strings.HasSuffix(origin, w[1]) {
|
||||
return true
|
||||
}
|
||||
if w[1] == "*" && strings.HasPrefix(origin, w[0]) {
|
||||
return true
|
||||
}
|
||||
if strings.HasPrefix(origin, w[0]) && strings.HasSuffix(origin, w[1]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (cors *cors) validateOrigin(origin string) bool {
|
||||
if cors.allowAllOrigins {
|
||||
return true
|
||||
}
|
||||
for _, value := range cors.allowOrigins {
|
||||
if value == origin {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if len(cors.wildcardOrigins) > 0 && cors.validateWildcardOrigin(origin) {
|
||||
return true
|
||||
}
|
||||
if cors.allowOriginFunc != nil {
|
||||
return cors.allowOriginFunc(origin)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (cors *cors) handlePreflight(c *gin.Context) {
|
||||
header := c.Writer.Header()
|
||||
for key, value := range cors.preflightHeaders {
|
||||
header[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
func (cors *cors) handleNormal(c *gin.Context) {
|
||||
header := c.Writer.Header()
|
||||
for key, value := range cors.normalHeaders {
|
||||
header[key] = value
|
||||
}
|
||||
}
|
||||
@@ -1,174 +0,0 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Config represents all available options for the middleware.
|
||||
type Config struct {
|
||||
AllowAllOrigins bool
|
||||
|
||||
// AllowOrigins is a list of origins a cross-domain request can be executed from.
|
||||
// If the special "*" value is present in the list, all origins will be allowed.
|
||||
// Default value is []
|
||||
AllowOrigins []string
|
||||
|
||||
// AllowOriginFunc is a custom function to validate the origin. It take the origin
|
||||
// as argument and returns true if allowed or false otherwise. If this option is
|
||||
// set, the content of AllowOrigins is ignored.
|
||||
AllowOriginFunc func(origin string) bool
|
||||
|
||||
// AllowMethods is a list of methods the client is allowed to use with
|
||||
// cross-domain requests. Default value is simple methods (GET and POST)
|
||||
AllowMethods []string
|
||||
|
||||
// AllowHeaders is list of non simple headers the client is allowed to use with
|
||||
// cross-domain requests.
|
||||
AllowHeaders []string
|
||||
|
||||
// AllowCredentials indicates whether the request can include user credentials like
|
||||
// cookies, HTTP authentication or client side SSL certificates.
|
||||
AllowCredentials bool
|
||||
|
||||
// AllowPrivateNetwork
|
||||
AllowPrivateNetwork bool
|
||||
|
||||
// ExposedHeaders indicates which headers are safe to expose to the API of a CORS
|
||||
// API specification
|
||||
ExposeHeaders []string
|
||||
|
||||
// MaxAge indicates how long (in seconds) the results of a preflight request
|
||||
// can be cached
|
||||
MaxAge time.Duration
|
||||
|
||||
// Allows to add origins like http://some-domain/*, https://api.* or http://some.*.subdomain.com
|
||||
AllowWildcard bool
|
||||
|
||||
// Allows usage of popular browser extensions schemas
|
||||
AllowBrowserExtensions bool
|
||||
|
||||
// Allows usage of WebSocket protocol
|
||||
AllowWebSockets bool
|
||||
|
||||
// Allows usage of file:// schema (dangerous!) use it only when you 100% sure it's needed
|
||||
AllowFiles bool
|
||||
}
|
||||
|
||||
// AddAllowMethods is allowed to add custom methods
|
||||
func (c *Config) AddAllowMethods(methods ...string) {
|
||||
c.AllowMethods = append(c.AllowMethods, methods...)
|
||||
}
|
||||
|
||||
// AddAllowHeaders is allowed to add custom headers
|
||||
func (c *Config) AddAllowHeaders(headers ...string) {
|
||||
c.AllowHeaders = append(c.AllowHeaders, headers...)
|
||||
}
|
||||
|
||||
// AddExposeHeaders is allowed to add custom expose headers
|
||||
func (c *Config) AddExposeHeaders(headers ...string) {
|
||||
c.ExposeHeaders = append(c.ExposeHeaders, headers...)
|
||||
}
|
||||
|
||||
func (c Config) getAllowedSchemas() []string {
|
||||
allowedSchemas := DefaultSchemas
|
||||
if c.AllowBrowserExtensions {
|
||||
allowedSchemas = append(allowedSchemas, ExtensionSchemas...)
|
||||
}
|
||||
if c.AllowWebSockets {
|
||||
allowedSchemas = append(allowedSchemas, WebSocketSchemas...)
|
||||
}
|
||||
if c.AllowFiles {
|
||||
allowedSchemas = append(allowedSchemas, FileSchemas...)
|
||||
}
|
||||
return allowedSchemas
|
||||
}
|
||||
|
||||
func (c Config) validateAllowedSchemas(origin string) bool {
|
||||
allowedSchemas := c.getAllowedSchemas()
|
||||
for _, schema := range allowedSchemas {
|
||||
if strings.HasPrefix(origin, schema) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Validate is check configuration of user defined.
|
||||
func (c *Config) Validate() error {
|
||||
if c.AllowAllOrigins && (c.AllowOriginFunc != nil || len(c.AllowOrigins) > 0) {
|
||||
return errors.New("conflict settings: all origins are allowed. AllowOriginFunc or AllowOrigins is not needed")
|
||||
}
|
||||
if !c.AllowAllOrigins && c.AllowOriginFunc == nil && len(c.AllowOrigins) == 0 {
|
||||
return errors.New("conflict settings: all origins disabled")
|
||||
}
|
||||
for _, origin := range c.AllowOrigins {
|
||||
if origin == "*" {
|
||||
c.AllowAllOrigins = true
|
||||
return nil
|
||||
} else if !strings.Contains(origin, "*") && !c.validateAllowedSchemas(origin) {
|
||||
return errors.New("bad origin: origins must contain '*' or include " + strings.Join(c.getAllowedSchemas(), ","))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c Config) parseWildcardRules() [][]string {
|
||||
var wRules [][]string
|
||||
|
||||
if !c.AllowWildcard {
|
||||
return wRules
|
||||
}
|
||||
|
||||
for _, o := range c.AllowOrigins {
|
||||
if !strings.Contains(o, "*") {
|
||||
continue
|
||||
}
|
||||
|
||||
if c := strings.Count(o, "*"); c > 1 {
|
||||
panic(errors.New("only one * is allowed").Error())
|
||||
}
|
||||
|
||||
i := strings.Index(o, "*")
|
||||
if i == 0 {
|
||||
wRules = append(wRules, []string{"*", o[1:]})
|
||||
continue
|
||||
}
|
||||
if i == (len(o) - 1) {
|
||||
wRules = append(wRules, []string{o[:i-1], "*"})
|
||||
continue
|
||||
}
|
||||
|
||||
wRules = append(wRules, []string{o[:i], o[i+1:]})
|
||||
}
|
||||
|
||||
return wRules
|
||||
}
|
||||
|
||||
// DefaultConfig returns a generic default configuration mapped to localhost.
|
||||
func DefaultConfig() Config {
|
||||
return Config{
|
||||
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
|
||||
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
|
||||
AllowCredentials: false,
|
||||
MaxAge: 12 * time.Hour,
|
||||
}
|
||||
}
|
||||
|
||||
// Default returns the location middleware with default configuration.
|
||||
func Default() gin.HandlerFunc {
|
||||
config := DefaultConfig()
|
||||
config.AllowAllOrigins = true
|
||||
return New(config)
|
||||
}
|
||||
|
||||
// New returns the location middleware with user-defined custom configuration.
|
||||
func New(config Config) gin.HandlerFunc {
|
||||
cors := newCors(config)
|
||||
return func(c *gin.Context) {
|
||||
cors.applyCors(c)
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package cors
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type converter func(string) string
|
||||
|
||||
func generateNormalHeaders(c Config) http.Header {
|
||||
headers := make(http.Header)
|
||||
if c.AllowCredentials {
|
||||
headers.Set("Access-Control-Allow-Credentials", "true")
|
||||
}
|
||||
if c.AllowPrivateNetwork {
|
||||
headers.Set("Access-Control-Allow-Private-Network", "true")
|
||||
}
|
||||
if len(c.ExposeHeaders) > 0 {
|
||||
exposeHeaders := convert(normalize(c.ExposeHeaders), http.CanonicalHeaderKey)
|
||||
headers.Set("Access-Control-Expose-Headers", strings.Join(exposeHeaders, ","))
|
||||
}
|
||||
if c.AllowAllOrigins {
|
||||
headers.Set("Access-Control-Allow-Origin", "*")
|
||||
} else {
|
||||
headers.Set("Vary", "Origin")
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func generatePreflightHeaders(c Config) http.Header {
|
||||
headers := make(http.Header)
|
||||
if c.AllowCredentials {
|
||||
headers.Set("Access-Control-Allow-Credentials", "true")
|
||||
}
|
||||
if len(c.AllowMethods) > 0 {
|
||||
allowMethods := convert(normalize(c.AllowMethods), strings.ToUpper)
|
||||
value := strings.Join(allowMethods, ",")
|
||||
headers.Set("Access-Control-Allow-Methods", value)
|
||||
}
|
||||
if len(c.AllowHeaders) > 0 {
|
||||
allowHeaders := convert(normalize(c.AllowHeaders), http.CanonicalHeaderKey)
|
||||
value := strings.Join(allowHeaders, ",")
|
||||
headers.Set("Access-Control-Allow-Headers", value)
|
||||
}
|
||||
if c.MaxAge > time.Duration(0) {
|
||||
value := strconv.FormatInt(int64(c.MaxAge/time.Second), 10)
|
||||
headers.Set("Access-Control-Max-Age", value)
|
||||
}
|
||||
if c.AllowAllOrigins {
|
||||
headers.Set("Access-Control-Allow-Origin", "*")
|
||||
} else {
|
||||
// Always set Vary headers
|
||||
// see https://github.com/rs/cors/issues/10,
|
||||
// https://github.com/rs/cors/commit/dbdca4d95feaa7511a46e6f1efb3b3aa505bc43f#commitcomment-12352001
|
||||
|
||||
headers.Add("Vary", "Origin")
|
||||
headers.Add("Vary", "Access-Control-Request-Method")
|
||||
headers.Add("Vary", "Access-Control-Request-Headers")
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
func normalize(values []string) []string {
|
||||
if values == nil {
|
||||
return nil
|
||||
}
|
||||
distinctMap := make(map[string]bool, len(values))
|
||||
normalized := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
value = strings.TrimSpace(value)
|
||||
value = strings.ToLower(value)
|
||||
if _, seen := distinctMap[value]; !seen {
|
||||
normalized = append(normalized, value)
|
||||
distinctMap[value] = true
|
||||
}
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
func convert(s []string, c converter) []string {
|
||||
var out []string
|
||||
for _, i := range s {
|
||||
out = append(out, c(i))
|
||||
}
|
||||
return out
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,234 +0,0 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>TorrServer Interaction Plugin</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="author" content="damiva" />
|
||||
<script type="text/javascript" src="tvx.js"></script>
|
||||
<script type="text/javascript">
|
||||
/*******************************************/
|
||||
/* TorrServer Interaction Plugin by damiva */
|
||||
/*******************************************/
|
||||
var ADR = window.location.origin, VRS = "", TZN = false;
|
||||
function TAU(n){
|
||||
var x = [
|
||||
["3g2","3gp","aaf","asf","avchd","avi","drc","flv","m2ts","ts","m2v","m4p","m4v","mkv","mng","mov","mp2","mp4","mpe","mpeg","mpg","mpv","mxf","nsv","ogg","ogv","qt","rm","rmvb","roq","svi",".vob","webm","wmv","yuv"],
|
||||
["aac","aiff","ape","au","flac","gsm","it","m3u","m4a","mid","mod","mp3","mpa","pls","ra","s3m","sid","wav","wma","xm"]
|
||||
];
|
||||
var i = n.lastIndexOf(".");
|
||||
if(i >= 0){
|
||||
n = n.substr(i + 1);
|
||||
for(var e = 0; e < x.length; e++) if(x[e].indexOf(n) >= 0) return e;
|
||||
}
|
||||
return -1
|
||||
}
|
||||
function LNG(s){
|
||||
var i = s == 0 ? 0 : Math.floor(Math.log(s) / Math.log(1024));
|
||||
return (s / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
|
||||
}
|
||||
function PRS(t){
|
||||
return "{ico:msx-white:north} " + (t.active_peers || 0) + " ⋅ " + (t.pending_peers || 0) + " / " + (t.total_peers || 0);
|
||||
}
|
||||
function STR(i, c){
|
||||
var v = TVXServices.storage.getBool(i, false);
|
||||
if(c) TVXServices.storage.set(i, v = !v);
|
||||
return v;
|
||||
}
|
||||
function AJX(u, d, o, e){
|
||||
console.log(u);
|
||||
if(typeof d != "object") TVXServices.ajax.get(ADR + u, {success: o, error: e}, {dataType: d ? "json" : "text"});
|
||||
else TVXServices.ajax.post(ADR + u, JSON.stringify(d), {success: o, error: e || TVXInteractionPlugin.error}, {dataType: e ? "json" : "text"});
|
||||
}
|
||||
function OPS(){
|
||||
var k = ["red", "green", "yellow"],
|
||||
r = {caption: "{dic:caption:options|Options}:", template: {enumerate: false, type: "control", layout: "0,0,8,1"}, items: []};
|
||||
r.headline = r.caption;
|
||||
for(var i = 0; i < 3; i++){
|
||||
var a = arguments[i];
|
||||
if(a){
|
||||
a.key = k[i];
|
||||
a.icon = "msx-" + a.key + ":stop";
|
||||
r.items.push(a);
|
||||
r.caption += "{tb}{ico:" + a.icon + "} " + a.label;
|
||||
}
|
||||
}
|
||||
r.items.push(
|
||||
{icon: "msx-blue:menu", label: "{dic:caption:menu|Menu}", action: "[cleanup|menu]"},
|
||||
{icon: "format-size", label: arguments[3] ? "{dic:lfont|Larger font size}" : "{dic:sfont|Smaller font size}", action: "[cleanup|interaction:commit:message:compress|reload:content]"}
|
||||
)
|
||||
if(arguments[4] !== undefined) r.items.push({icon: "translate", label: arguments[4] ? "Switch to English" : "Перевести на русский", action: "[interaction:commit:message:russian|reload]"});
|
||||
return r;
|
||||
}
|
||||
function TDB(d, c, r){return {
|
||||
type: "list", reuse: false, cache: false, restore: false, compress: c, headline: "TorrServer", extension: VRS,
|
||||
template: {
|
||||
imageWidth: 1.3, imageFiller: "height", icon: "msx-glass:bolt", layout: c ? "0,0,8,2" : "0,0,6,2", options: OPS(
|
||||
{label: "{dic:rem|Remove}", action: "[cleanup|interaction:commit:message:rem]", data: "{context:id}"},
|
||||
{label: "{dic:drop|Drop}", action: "[cleanup|interaction:commit:message:drop]", data: "{context:id}"},
|
||||
{label: "{dic:refresh|Refresh}", action: "[cleanup|reload:content]"},
|
||||
c, r
|
||||
)
|
||||
},
|
||||
items: d.map(function(t){return {
|
||||
id: t.hash,
|
||||
headline: t.title,
|
||||
image: t.poster || null,
|
||||
titleFooter: "{ico:msx-white:attach-file} " + LNG(t.torrent_size),
|
||||
stamp: t.stat < 5 ? PRS(t) : null,
|
||||
stampColor: t.stat == 4 ? "msx-red" : t.stat == 3 ? "msx-green" : "msx-yellow",
|
||||
action: "content:request:interaction:" + t.hash + "@" + window.location.href
|
||||
}})
|
||||
}}
|
||||
function TFS(d, c){
|
||||
var fs = [], is = [], sf = TVXServices.storage.getBool("folders", false);
|
||||
d.file_stats.forEach(function(f){
|
||||
var a = TAU(f.path);
|
||||
if(a >= 0){
|
||||
var b = f.path.indexOf("/"),
|
||||
e = f.path.lastIndexOf("/"),
|
||||
p = b < e && e > 0 ? f.path.substr(b + 1, e - b - 1) : ""
|
||||
i = d.hash + "-" + f.id,
|
||||
u = ADR + "/play/" + d.hash + "/" + f.id;
|
||||
if(p && (fs.length == 0 || fs[fs.length - 1].label != p)){
|
||||
fs.push({label: p, action: "[cleanup|focus:" + i + "]"});
|
||||
if(sf) is.push({type: "space", label: "{col:msx-yellow}{ico:folder} " + p});
|
||||
}
|
||||
is.push({
|
||||
id: i,
|
||||
label: f.path.substr(e + 1),
|
||||
extensionLabel: LNG(f.length),
|
||||
folder: p ? ("{ico:msx-yellow:folder} " + p + "{br}") : "",
|
||||
icon: "msx-white-soft:" + (a ? "audiotrack" : "movie"),
|
||||
group: a ? "{dic:label:audio|Audio}" : "{dic:label:video|Video}",
|
||||
action: (a ? "audio:" : "video:") + (a || TZN ? u : ("plugin:" + window.location.origin + "/msx/html5x?url=" + encodeURIComponent(u)))
|
||||
});
|
||||
}
|
||||
});
|
||||
return {
|
||||
type: "list", compress: c, items: is,
|
||||
extension: "{ico:msx-white:attach-file} " + LNG(d.torrent_size), headline: d.title,
|
||||
options: OPS(
|
||||
{label: "{dic:continue|Continue}", action: "[cleanup|interaction:commit:message:continue]", data: d.hash},
|
||||
fs.length > 1 ? {label: "{dic:folder|Select folder}", action: "panel:data", data: {
|
||||
type: "list", compress: true, headline: "{dic:folder|Go to folder}:", items: fs,
|
||||
template: {type: "control", icon: "msx-yellow:folder", layout: "0,0,10,1"},
|
||||
}} : null,
|
||||
fs.length > 0 ? {label: STR("folders") ? "{dic:hfolders|Hide folders}" : "{dic:sfolders|Show folders}", action: "[cleanup|interaction:commit:message:folders|reload:content]"} : null,
|
||||
c
|
||||
),
|
||||
template: {type: "control", layout: c ? "0,0,16,1" : "0,0,12,1", progress: -1, playerLabel: d.title,
|
||||
live: {type: "playback", action: "player:show"}, properties: {
|
||||
"info:text": "{context:folder}{ico:msx-green:play-arrow} {context:label}",
|
||||
"info:image": d.poster || "default",
|
||||
"control:type": "extended",
|
||||
"resume:key": "id",
|
||||
"trigger:complete": "[player:auto:next|resume:cancel]",
|
||||
"trigger:player": "interaction:commit:message:" + d.hash
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
function PLG(){
|
||||
var W = new TVXBusyService(), S = "";
|
||||
this.ready = function(){
|
||||
ADR = TVXServices.urlParams.getFullStr("addr", ADR);
|
||||
if(TVXServices.urlParams.has("link")){
|
||||
TVXServices.urlParams.remove("addr");
|
||||
S = TVXServices.urlParams.build(true, "&");
|
||||
}
|
||||
W.start();
|
||||
TVXInteractionPlugin.onValidatedSettings(function(){
|
||||
console.log(TVXSettings);
|
||||
TZN = TVXSettings.PLATFORM == "tizen";
|
||||
AJX("/echo", false, function(v){VRS = v; W.stop()}, function(){W.stop()});
|
||||
});
|
||||
};
|
||||
this.handleEvent = function(d){
|
||||
if(d.event == "video:load"){
|
||||
switch(d.info.type){
|
||||
case "video":
|
||||
TVXInteractionPlugin.executeAction("player:button:content:setup", {
|
||||
icon: "build",
|
||||
action: TZN ? ("content:request:interaction:init@" + window.location.origin + "/msx/tizen") : "panel:request:player:options"
|
||||
});
|
||||
break;
|
||||
case "audio":
|
||||
TVXInteractionPlugin.executeAction("interaction:commit:message:background", true);
|
||||
}
|
||||
TVXInteractionPlugin.executeAction("interaction:commit:message:" + d.info.id.split("-")[0]);
|
||||
}
|
||||
};
|
||||
this.handleRequest = function(i, _, f){W.onReady(function(){
|
||||
var e = function(m){TVXInteractionPlugin.error(m); f();},
|
||||
c = STR("compress"),
|
||||
r = STR("russian");
|
||||
switch(i){
|
||||
case "init":
|
||||
f({
|
||||
name: "TorrServer Plugin",
|
||||
version: "0.0.1",
|
||||
reference: "request:interaction:db@" + window.location.href,
|
||||
dictionary: r ? (window.location.origin + "/msx/russian.json") : null
|
||||
});
|
||||
break;
|
||||
case "sdb": r = undefined;
|
||||
case "db":
|
||||
AJX("/torrents", {action: "list"}, function(d){f(TDB(d, c, r))}, e);
|
||||
break;
|
||||
default:
|
||||
AJX("/stream/?stat&" + (S || ("link=" + i)), true, function(d){f(TFS(d, c, S && S.indexOf("&save_to_db") < 0))}, e);
|
||||
}
|
||||
})};
|
||||
this.handleData = function(d){
|
||||
var r = function(){TVXInteractionPlugin.executeAction("reload:content")}
|
||||
switch(d.message){
|
||||
case "rem":
|
||||
case "drop":
|
||||
AJX("/torrents", {action: d.message, hash: d.data}, r);
|
||||
break;
|
||||
case "compress":
|
||||
case "folders":
|
||||
case "russian":
|
||||
STR(d.message, true);
|
||||
break;
|
||||
case "background":
|
||||
var b = STR(d.message, !d.data);
|
||||
TVXInteractionPlugin.executeAction("player:button:content:setup", {
|
||||
icon: (b ? "hide-" : "") + "image",
|
||||
action: "interaction:commit:message:" + d.message
|
||||
});
|
||||
TVXInteractionPlugin.executeAction("player:background:" + (b
|
||||
? ("https://source.unsplash.com/random/" + TVXSettings.WIDTH + "x" + TVXSettings.HEIGHT + "/?ts=" + TVXDateTools.getTimestamp())
|
||||
: "none"
|
||||
));
|
||||
break;
|
||||
case "continue":
|
||||
AJX(
|
||||
"/viewed",
|
||||
{action: "list", hash: d.data},
|
||||
function(v){
|
||||
var l = 1;
|
||||
v.forEach(function(i){if(i.file_index > l) l = i.file_index});
|
||||
TVXInteractionPlugin.executeAction("focus:" + d.data + "-" + l);
|
||||
},
|
||||
function(){TVXInteractionPlugin.executeAction("focus:" + d.data + "-" + l)}
|
||||
);
|
||||
break;
|
||||
default:
|
||||
if(d.message) AJX("/cache", {action: "get", hash: d.message}, function(v){
|
||||
TVXInteractionPlugin.executeAction("player:label:position:{VALUE}{tb}{tb}" + PRS(v.Torrent));
|
||||
}, function(){});
|
||||
}
|
||||
};
|
||||
}
|
||||
TVXPluginTools.onReady(function() {
|
||||
TVXInteractionPlugin.setupHandler(new PLG());
|
||||
TVXInteractionPlugin.init();
|
||||
});
|
||||
/*******************************************/
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,6 +2,9 @@ package msx
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"server/version"
|
||||
|
||||
@@ -9,60 +12,87 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed assets/tvx.js.gz
|
||||
tvx []byte
|
||||
//go:embed assets/tizen.js.gz
|
||||
tzn []byte
|
||||
//go:embed assets/torrents.js.gz
|
||||
trs []byte
|
||||
//go:embed assets/torrent.js.gz
|
||||
trn []byte
|
||||
//go:embed assets/html5x.html.gz
|
||||
h5x []byte
|
||||
//go:embed assets/russian.json.gz
|
||||
//go:embed russian.min.gz
|
||||
rus []byte
|
||||
//go:embed torrents.min.gz
|
||||
trs []byte
|
||||
//go:embed torrent.min.gz
|
||||
trn []byte
|
||||
//go:embed ts.min.gz
|
||||
its []byte
|
||||
|
||||
idb = new(sync.Mutex)
|
||||
ids = make(map[string]string)
|
||||
)
|
||||
|
||||
func ass(c *gin.Context, b []byte, t string) {
|
||||
func asset(c *gin.Context, t string, d []byte) {
|
||||
c.Header("Content-Encoding", "gzip")
|
||||
c.Data(200, t+"; charset=UTF-8", b)
|
||||
c.Data(200, t+"; charset=UTF-8", d)
|
||||
}
|
||||
|
||||
func SetupRoute(r *gin.RouterGroup) {
|
||||
r.GET("/msx/:pth", func(c *gin.Context) {
|
||||
s := []string{"tvx", "tizen"}
|
||||
js := []string{"http://msx.benzac.de/js/tvx-plugin.min.js"}
|
||||
switch p := c.Param("pth"); p {
|
||||
case "start.json":
|
||||
c.JSON(200, gin.H{
|
||||
c.JSON(200, map[string]string{
|
||||
"name": "TorrServer",
|
||||
"version": version.Version,
|
||||
"parameter": "content:request:interaction:init@{PREFIX}{SERVER}/msx/torrents",
|
||||
"parameter": "menu:request:interaction:init@{PREFIX}{SERVER}/msx/ts",
|
||||
})
|
||||
case "russian.json":
|
||||
ass(c, rus, "application.json")
|
||||
case "html5x":
|
||||
ass(c, h5x, "text/html")
|
||||
case "tvx.js":
|
||||
ass(c, tvx, "text/javascript")
|
||||
case "tizen.js":
|
||||
ass(c, tzn, "text/javascript")
|
||||
asset(c, "application/json", rus)
|
||||
case "torrents.js":
|
||||
ass(c, trs, "text/javascript")
|
||||
asset(c, "text/javascript", trs)
|
||||
case "torrent.js":
|
||||
ass(c, trn, "text/javascript")
|
||||
asset(c, "text/javascript", trn)
|
||||
case "ts.js":
|
||||
asset(c, "text/javascript", its)
|
||||
case "torrents":
|
||||
s = append(s, p)
|
||||
js = append(js, p+".js")
|
||||
p = "torrent"
|
||||
fallthrough
|
||||
case "torrent":
|
||||
s = append(s, p)
|
||||
b := []byte("<!DOCTYPE html>\n<html>\n<head>\n<title>TorrServer Interaction Plugin</title>\n<meta charset='UTF-8' />\n")
|
||||
for _, j := range s {
|
||||
b = append(b, "<script type='text/javascript' src='"+j+".js'></script>\n"...)
|
||||
if c.Query("platform") == "tizen" {
|
||||
js = append(js, "http://msx.benzac.de/interaction/js/tizen-player.js")
|
||||
}
|
||||
c.Data(200, "text/html", append(b, "</head>\n<body></body>\n</html>"...))
|
||||
fallthrough
|
||||
case "ts":
|
||||
b := []byte("<!DOCTYPE html>\n<html>\n<head>\n<title>TorrServer Plugin</title>\n<meta charset='UTF-8'>\n")
|
||||
for _, j := range append(js, p+".js") {
|
||||
b = append(b, "<script type='text/javascript' src='"+j+"'></script>\n"...)
|
||||
}
|
||||
c.Data(200, "text/html; charset=UTF-8", append(b, "</head>\n<body></body>\n</html>"...))
|
||||
default:
|
||||
c.AbortWithStatus(404)
|
||||
c.AbortWithStatus(400)
|
||||
}
|
||||
})
|
||||
r.GET("/msx/imdb", func(c *gin.Context) {
|
||||
idb.Lock()
|
||||
defer idb.Unlock()
|
||||
l := len(ids)
|
||||
ids = make(map[string]string)
|
||||
c.JSON(200, l)
|
||||
})
|
||||
r.GET("/msx/imdb/:id", func(c *gin.Context) {
|
||||
idb.Lock()
|
||||
defer idb.Unlock()
|
||||
p := c.Param("id")
|
||||
i, o := ids[p]
|
||||
if !o {
|
||||
if r, e := http.Get("https://v2.sg.media-imdb.com/suggestion/h/" + p + ".json"); e == nil {
|
||||
defer r.Body.Close()
|
||||
if r.StatusCode == 200 {
|
||||
var j struct {
|
||||
D []struct{ I struct{ ImageUrl string } }
|
||||
}
|
||||
if e = json.NewDecoder(r.Body).Decode(&j); e == nil && len(j.D) > 0 {
|
||||
i = j.D[0].I.ImageUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
ids[p] = i
|
||||
}
|
||||
c.JSON(200, i)
|
||||
})
|
||||
}
|
||||
|
||||
BIN
server/web/msx/russian.min.gz
Normal file
BIN
server/web/msx/russian.min.gz
Normal file
Binary file not shown.
BIN
server/web/msx/torrent.min.gz
Normal file
BIN
server/web/msx/torrent.min.gz
Normal file
Binary file not shown.
BIN
server/web/msx/torrents.min.gz
Normal file
BIN
server/web/msx/torrents.min.gz
Normal file
Binary file not shown.
BIN
server/web/msx/ts.min.gz
Normal file
BIN
server/web/msx/ts.min.gz
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user