Skip to content

Commit

Permalink
fix: 尝试解决多线程代理403问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdhnx committed Jan 23, 2025
1 parent 821a72c commit f562549
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ dist
/yarn.lock
/custom.json
/index.json
/vod_cache/
11 changes: 7 additions & 4 deletions controllers/mediaProxy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {base64Decode} from '../libs_drpy/crypto-util.js';
import {base64Decode, md5} from '../libs_drpy/crypto-util.js';
import '../utils/random-http-ua.js'
import {keysToLowerCase} from '../utils/utils.js';
import {ENV} from "../utils/env.js";
Expand All @@ -25,16 +25,19 @@ export default (fastify, options, done) => {
fastify.all('/mediaProxy', async (request, reply) => {
const {thread = 1, form = 'urlcode', url, header, size = '128K', randUa = 0} = request.query;

// console.log('url:', url)
// console.log('header:', header)

// Check if the URL parameter is missing
if (!url) {
return reply.code(400).send({error: 'Missing required parameter: url'});
}

try {
// Decode URL and headers based on the form type
const decodedUrl = form === 'base64' ? base64Decode(url) : decodeURIComponent(url);
const decodedUrl = form === 'base64' ? base64Decode(url) : url;
const decodedHeader = header
? JSON.parse(form === 'base64' ? base64Decode(header) : decodeURIComponent(header))
? JSON.parse(form === 'base64' ? base64Decode(header) : header)
: {};

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

0 comments on commit f562549

Please # to comment.