Skip to content

Commit f562549

Browse files
committed
fix: 尝试解决多线程代理403问题
1 parent 821a72c commit f562549

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ dist
140140
/yarn.lock
141141
/custom.json
142142
/index.json
143+
/vod_cache/

Diff for: controllers/mediaProxy.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {base64Decode} from '../libs_drpy/crypto-util.js';
1+
import {base64Decode, md5} from '../libs_drpy/crypto-util.js';
22
import '../utils/random-http-ua.js'
33
import {keysToLowerCase} from '../utils/utils.js';
44
import {ENV} from "../utils/env.js";
@@ -25,16 +25,19 @@ export default (fastify, options, done) => {
2525
fastify.all('/mediaProxy', async (request, reply) => {
2626
const {thread = 1, form = 'urlcode', url, header, size = '128K', randUa = 0} = request.query;
2727

28+
// console.log('url:', url)
29+
// console.log('header:', header)
30+
2831
// Check if the URL parameter is missing
2932
if (!url) {
3033
return reply.code(400).send({error: 'Missing required parameter: url'});
3134
}
3235

3336
try {
3437
// Decode URL and headers based on the form type
35-
const decodedUrl = form === 'base64' ? base64Decode(url) : decodeURIComponent(url);
38+
const decodedUrl = form === 'base64' ? base64Decode(url) : url;
3639
const decodedHeader = header
37-
? JSON.parse(form === 'base64' ? base64Decode(header) : decodeURIComponent(header))
40+
? JSON.parse(form === 'base64' ? base64Decode(header) : header)
3841
: {};
3942

4043
// Call the proxy function, passing the decoded URL and headers
@@ -45,7 +48,7 @@ export default (fastify, options, done) => {
4548
return await proxyStreamMediaMulti(decodedUrl, decodedHeader, request, reply, thread, size, randUa);
4649
} else {
4750
console.log('[mediaProxy] chunkStream 磁盘加速 chunkSize:', sizeToBytes('256K'));
48-
return await chunkStream(request, reply, decodedUrl, null, decodedHeader,
51+
return await chunkStream(request, reply, decodedUrl, md5(decodedUrl), decodedHeader,
4952
Object.assign({chunkSize: 1024 * 256, poolSize: 5, timeout: 1000 * 10}, {
5053
// chunkSize: sizeToBytes(size),
5154
poolSize: thread

0 commit comments

Comments
 (0)