mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 08:09:19 +00:00
29 lines
856 B
JavaScript
29 lines
856 B
JavaScript
import { exec } from 'child_process';
|
|
import path from 'path'
|
|
|
|
/**
|
|
* 执行 TDL 进行下载
|
|
* @param url
|
|
* @param curPath
|
|
* @param isOversea
|
|
* @param proxyAddr
|
|
* @returns {Promise<string>}
|
|
*/
|
|
export async function startTDL(url, curPath, isOversea, proxyAddr) {
|
|
return new Promise((resolve, reject) => {
|
|
curPath = path.resolve(curPath);
|
|
const proxyStr = isOversea ? `` : `--proxy ${ proxyAddr }`;
|
|
const command = `tdl dl -u ${url} -d ${curPath} ${proxyStr}`
|
|
exec(command, (error, stdout, stderr) => {
|
|
if (error) {
|
|
reject(`[R插件][TDL]执行出错: ${error.message}`);
|
|
return;
|
|
}
|
|
if (stderr) {
|
|
reject(`[R插件][TDL]错误信息: ${stderr}`);
|
|
return;
|
|
}
|
|
resolve(stdout);
|
|
})
|
|
})
|
|
} |