|
1 | 1 | import ffmpeg from "ffmpeg-static"; |
2 | 2 | import { spawn } from "child_process"; |
3 | | -import { Agent, request } from "undici"; |
4 | 3 | import { create as contentDisposition } from "content-disposition-header"; |
5 | 4 |
|
6 | 5 | import { env } from "../config.js"; |
7 | 6 | import { destroyInternalStream } from "./manage.js"; |
8 | 7 | import { hlsExceptions } from "../processing/service-config.js"; |
9 | | -import { getHeaders, closeRequest, closeResponse, pipe, estimateTunnelLength, estimateAudioMultiplier } from "./shared.js"; |
| 8 | +import { closeResponse, pipe, estimateTunnelLength, estimateAudioMultiplier } from "./shared.js"; |
10 | 9 |
|
11 | 10 | const metadataTags = [ |
12 | 11 | "album", |
@@ -55,44 +54,6 @@ const getCommand = (args) => { |
55 | 54 | return [ffmpeg, args] |
56 | 55 | } |
57 | 56 |
|
58 | | -const defaultAgent = new Agent(); |
59 | | - |
60 | | -const proxy = async (streamInfo, res) => { |
61 | | - const abortController = new AbortController(); |
62 | | - const shutdown = () => ( |
63 | | - closeRequest(abortController), |
64 | | - closeResponse(res), |
65 | | - destroyInternalStream(streamInfo.urls) |
66 | | - ); |
67 | | - |
68 | | - try { |
69 | | - res.setHeader('Cross-Origin-Resource-Policy', 'cross-origin'); |
70 | | - res.setHeader('Content-disposition', contentDisposition(streamInfo.filename)); |
71 | | - |
72 | | - const { body: stream, headers, statusCode } = await request(streamInfo.urls, { |
73 | | - headers: { |
74 | | - ...getHeaders(streamInfo.service), |
75 | | - Range: streamInfo.range |
76 | | - }, |
77 | | - signal: abortController.signal, |
78 | | - maxRedirections: 16, |
79 | | - dispatcher: defaultAgent, |
80 | | - }); |
81 | | - |
82 | | - res.status(statusCode); |
83 | | - |
84 | | - for (const headerName of ['accept-ranges', 'content-type', 'content-length']) { |
85 | | - if (headers[headerName]) { |
86 | | - res.setHeader(headerName, headers[headerName]); |
87 | | - } |
88 | | - } |
89 | | - |
90 | | - pipe(stream, res, shutdown); |
91 | | - } catch { |
92 | | - shutdown(); |
93 | | - } |
94 | | -} |
95 | | - |
96 | 57 | const render = async (res, streamInfo, ffargs, multiplier) => { |
97 | 58 | let process; |
98 | 59 | const urls = Array.isArray(streamInfo.urls) ? streamInfo.urls : [streamInfo.urls]; |
@@ -245,7 +206,6 @@ const convertGif = async (streamInfo, res) => { |
245 | 206 | } |
246 | 207 |
|
247 | 208 | export default { |
248 | | - proxy, |
249 | 209 | remux, |
250 | 210 | convertAudio, |
251 | 211 | convertGif, |
|
0 commit comments