diff --git a/README.md b/README.md index b87a2ba..be1ae0c 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,52 @@ ```conf proxy_set_header Accept-Encoding ""; -sub_filter '' ''; +sub_filter '' ''; sub_filter_once on; ``` +並加入新的 location 塊: +```conf +location /ddplay-api/ { + proxy_pass https://api.dandanplay.net/; + proxy_set_header Host $host; + + add_header Access-Control-Allow-Origin "example.com"; + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; + add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization"; + + if ($request_method = OPTIONS) { + add_header Content-Length 0; + add_header Content-Type text/plain; + return 204; + } +} + +location /ddplay-api/ { + proxy_pass https://api.dandanplay.net/; + proxy_set_header Host $host; + + add_header Access-Control-Allow-Origin "example.com"; + add_header Access-Control-Allow-Methods "GET, POST, OPTIONS"; + add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization"; + + if ($request_method = OPTIONS) { + add_header Content-Length 0; + add_header Content-Type text/plain; + return 204; + } +} + +location /ddplay-api/api/v2/login { + proxy_pass https://jellyfin-danmaku.pages.dev; + proxy_set_header Host $host; + + add_header Access-Control-Allow-Origin "example.com"; + add_header Access-Control-Allow-Methods "POST, OPTIONS"; + add_header Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization"; +} +``` + - [`完整示例`](https://github.com/Izumiko/jellyfin-danmaku/issues/8) #### 2.2 Caddy @@ -83,14 +125,30 @@ sub_filter_once on; # 网站设置 example.com { filter { - path .*/web/.* + path /web/.* search_pattern - replacement "" + replacement "" content_type text/html } reverse_proxy localhost:8096 { header_up Accept-Encoding identity } + + handle_path /ddplay-api/api/v2/login* { + reverse_proxy https://jellyfin-danmaku.pages.dev { + header_down Access-Control-Allow-Origin "example.com" + header_down Access-Control-Allow-Methods "POST, OPTIONS" + header_down Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization" + } + } + + handle_path /ddplay-api/* { + reverse_proxy https://api.dandanplay.net { + header_down Access-Control-Allow-Origin "example.com" + header_down Access-Control-Allow-Methods "GET, POST, OPTIONS" + header_down Access-Control-Allow-Headers "Origin, Content-Type, Accept, Authorization" + } + } } ``` diff --git a/ede.js b/ede.js index 858e3d6..8e624f0 100644 --- a/ede.js +++ b/ede.js @@ -3,7 +3,7 @@ // @description Jellyfin弹幕插件 // @namespace https://github.com/RyoLee // @author RyoLee -// @version 1.46 +// @version 1.47 // @copyright 2022, RyoLee (https://github.com/RyoLee) // @license MIT; https://raw.githubusercontent.com/Izumiko/jellyfin-danmaku/jellyfin/LICENSE // @icon https://github.githubassets.com/pinned-octocat.svg @@ -25,10 +25,15 @@ } // ------ configs start------ const isInTampermonkey = !(typeof GM_xmlhttpRequest === 'undefined'); + const isLocalCors = (!isInTampermonkey && document.currentScript?.src) ? new URL(document.currentScript?.src).searchParams.has("noCors") : false; const corsProxy = 'https://ddplay-api.930524.xyz/cors/'; - const apiPrefix = isInTampermonkey ? 'https://api.dandanplay.net' : corsProxy + 'https://api.dandanplay.net'; + const apiPrefix = isInTampermonkey + ? 'https://api.dandanplay.net' + : isLocalCors + ? `${window.location.origin}/ddplay-api` + : corsProxy + 'https://api.dandanplay.net'; // const apiPrefix = 'https://api.930524.xyz'; - const authPrefix = corsProxy + 'https://api.dandanplay.net'; // 在Worker上计算Hash + const authPrefix = isLocalCors ? apiPrefix : corsProxy + 'https://api.dandanplay.net'; // 在Worker上计算Hash let ddplayStatus = JSON.parse(localStorage.getItem('ddplayStatus')) || { isLogin: false, token: '', tokenExpire: 0 }; const check_interval = 200; // 0:当前状态关闭 1:当前状态打开