更新文件: README.txt, docker-compose.yml, webdav_simulator.amd64, embysim.tar.xz, nginx/conf.d/emby.conf 等6个文件

This commit is contained in:
ZJP Monitor
2025-07-28 21:55:25 +08:00
parent 9a5c20df32
commit 28a03a58d9
6 changed files with 123 additions and 74 deletions

View File

@ -1,12 +1,13 @@
# Load the njs script
js_path /etc/nginx/conf.d/;
js_import addExternalUrl from externalUrl.js;
js_shared_dict_zone zone=path_cache:10m;
server{
gzip on;
listen 80;
server_name default;
set $emby http://172.17.0.1:8096; #emby address
set $emby http://172.17.0.1:8097; #emby address
# Proxy sockets traffic for jellyfin-mpv-shim and webClient
location ~ /(socket|embywebsocket) {
@ -23,6 +24,25 @@ server{
proxy_set_header X-Forwarded-Host $http_host;
}
# 代理 Emby 的 PlaybackInfo 请求
location ~* /Items/(\d+)/PlaybackInfo {
#proxy_buffering off;
js_body_filter addExternalUrl.rewritePlaybackInfo buffer_type=string;
proxy_pass $emby;
#proxy_pass_request_body off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 使用 JavaScript 模块处理响应
#js_body_filter rewritePlaybackInfo;
}
location ~* /videos/(\d+)/original {
js_content addExternalUrl.cacheRedirect;
}
location ~* /Users/(.*)/Items/(\d+)$ {
proxy_buffering off;
js_body_filter addExternalUrl.addExternalUrl buffer_type=string;
@ -58,4 +78,4 @@ server{
# Disable buffering when the nginx proxy gets very resource heavy upon streaming
proxy_buffering off;
}
}
}

View File

@ -212,6 +212,68 @@ const redirectUrl = (r) => {
const link = Buffer.from(baseLink, 'base64').toString('utf8');
r.return(302, link);
}
const rewritePlaybackInfo = async (r, data, flags) => {
// 获取响应体
//let body = r.responseText;
r.error("Original response body: " + r.responseText);
if (flags.last === false) {
oriData += data;
r.error(`flags.last: ${flags.last} , data.length: ${data.length}`);
return;
} else {
r.error(`flags.last: ${flags.last}`);
data = JSON.parse(oriData);
r.error(`data.length: ${JSON.stringify(data).length}`);
}
// try {
// 解析 JSON 响应
//let data = JSON.parse(body);
// 检查是否存在 MediaSources 数组
if (data.MediaSources && Array.isArray(data.MediaSources)) {
// 遍历 MediaSources 数组,替换 DirectStreamUrl 为 Path
data.MediaSources.forEach(source => {
if (source.Path && typeof source.Path === 'string') {
//source.DirectStreamUrl = source.Path;
ngx.shared.path_cache.set(source.Id, source.Path);
let tmppath=ngx.shared.path_cache.get(source.Id);
//r.error(`set cache item:${source.Id}=>${tmppath}`);
}
});
}
// 返回修改后的 JSON
// r.return(200, JSON.stringify(data));
// } catch (e) {
// // 如果 JSON 解析失败,返回原始响应并记录错误
// r.warn('Failed to parse JSON: ' + e);
// r.return(200, body);
// }
// r.error(`addUrldata.length: ${JSON.stringify(data).length}`)
r.sendBuffer(JSON.stringify(data), flags);
r.done();
}
function cacheRedirect(r) {
// Extract MediaSourceId from query parameters
let mediaSourceId = r.variables.arg_MediaSourceId;
if (!mediaSourceId) {
r.return(400, "Missing MediaSourceId parameter");
return;
}
// Look up the path in the shared dictionary
let cachedPath = ngx.shared.path_cache.get(mediaSourceId);
if (cachedPath) {
// Return 302 redirect to the cached path
r.return(302, cachedPath);
} else {
// Return 404 if no path is found
r.return(404, "No path found for MediaSourceId: " + mediaSourceId);
}
}
export default { addExternalUrl, redirectUrl, HeaderFilter };
export default { addExternalUrl, redirectUrl, HeaderFilter, rewritePlaybackInfo, cacheRedirect };