alist-org / alist

🗂️A file list/WebDAV program that supports multiple storages, powered by Gin and Solidjs. / 一个支持多存储的文件列表/WebDAV程序,使用 Gin 和 Solidjs。
https://alist.nn.ci
GNU Affero General Public License v3.0
39.44k stars 5.12k forks source link

百度网盘动态上传域名 #6518

Open 21paradox opened 1 month ago

21paradox commented 1 month ago

Please make sure of the following things

Description of the feature / 需求描述

百度网盘分片上传前增加了一个动态获取域名的步骤,文档: https://pan.baidu.com/union/doc/nksg0s9vi

Suggested solution / 实现思路

我遇到了大文件上传80%多报错的情况,使用的10mbps云主机,百度云svip + 16 1024 1024 分块上传到80%会出现 error=31355 复现步骤是复制一个本地存储文件到百度云. 目前我是使用一个代理脚本解决

希望alist 能集成上传前动态获取域名步骤

代理脚本(上传api改成http://localhost:3100)

const httpProxy = require('http-proxy');
const http = require('http');
const https = require('https');
const url = require('url');
const fetch = require('node-fetch');
const qs = require('querystring')

const httpsAgent = new https.Agent({
    keepAlive: true,
    keepAliveMsecs: 50 * 1000,
});

const domainMap = {}

var server = http.createServer(async function (req, res) {
    const proxy = httpProxy.createProxyServer({
        target: 'http://pan.baidu.com',
        agent: httpsAgent,
        changeOrigin: true,
        toProxy: true,
        proxyTimeout: 100 * 1000,
        timeout: 100 * 1000,
    }); 

    const urlParsed = url.parse(req.url, true)
    let domain0
    if (domainMap[urlParsed.query.uploadid]) {
        domain0 = domainMap[urlParsed.query.uploadid]
    } else {
        const qstr = qs.stringify({
            method: 'locateupload',
            appid: 250528,
            access_token: urlParsed.query.access_token,
            path: urlParsed.query.path,
            uploadid: urlParsed.query.uploadid,
            upload_version: '2.0'
        });

        const locateResRaw = await fetch(`https://d.pcs.baidu.com/rest/2.0/pcs/file?${qstr}`);
        const locateRes = await locateResRaw.json()
        domain0 = locateRes.servers[0].server;

        setTimeout(() => {
            delete domainMap[urlParsed.query.uploadid]
        }, locateRes.expire * 1000 - 5000) //不确定expire是不是这个意思
    }

    console.log(domain0, urlParsed.query.uploadid)
    proxy.web(req, res, { target: domain0 }, (err) => {
        console.log(err)
    });
});

const port = 3100;
console.log(`listening on port ${port}`)
server.listen(port);

Additional context / 附件

No response

welcome[bot] commented 1 month ago

Thanks for opening your first issue here! Be sure to follow the issue template!

github-actions[bot] commented 1 month ago

See

  1. 60% #3242