Skip to content

Commit

Permalink
Merge pull request #59 from lekoOwO/jellyfin
Browse files Browse the repository at this point in the history
在使用反代的時候避免使用公開的 CORS Proxy
  • Loading branch information
Izumiko authored Oct 6, 2024
2 parents eb5dd27 + 4b81f34 commit 62a7544
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
64 changes: 61 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,52 @@

```conf
proxy_set_header Accept-Encoding "";
sub_filter '</body>' '<script src="https://jellyfin-danmaku.pages.dev/ede.user.js" defer></script></body>';
sub_filter '</body>' '<script src="https://jellyfin-danmaku.pages.dev/ede.user.js?noCors=1" defer></script></body>';
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
Expand All @@ -83,14 +125,30 @@ sub_filter_once on;
# 网站设置
example.com {
filter {
path .*/web/.*
path /web/.*
search_pattern </body>
replacement "<script src=\"https://jellyfin-danmaku.pages.dev/ede.user.js\" defer></script></body>"
replacement "<script src=\"https://jellyfin-danmaku.pages.dev/ede.user.js?noCors=1\" defer></script></body>"
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"
}
}
}
```

Expand Down
11 changes: 8 additions & 3 deletions ede.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:当前状态打开
Expand Down

0 comments on commit 62a7544

Please sign in to comment.