()
| 674 | return `❌ WireProxy 未运行。请先使用 <code>${htmlEscape(mainPrefix)}warp w</code> 启动 WireProxy。`; |
| 675 | } |
| 676 | |
| 677 | // 获取当前端口 |
| 678 | const socksCheck = await SystemExecutor.run("ss -tlnp | grep -i wireproxy | head -1"); |
| 679 | const portMatch = socksCheck.success ? socksCheck.output.match(/:(\d+)\b/) : null; |
| 680 | const port = portMatch ? parseInt(portMatch[1], 10) : 40000; |
| 681 | |
| 682 | // 获取程序目录并构建配置文件路径 |
| 683 | const pwdResult = await SystemExecutor.run("pwd"); |
| 684 | if (!pwdResult.success) { |
| 685 | return "❌ 无法获取当前工作目录。"; |
| 686 | } |
| 687 | |
| 688 | const programDir = pwdResult.output.trim(); |
| 689 | const configPath = `${programDir}/assets/music/music_config.json`; |
| 690 | |
| 691 | // 检查 Music 配置文件是否存在 |
| 692 | const configCheck = await SystemExecutor.run(`test -f ${configPath}`); |
| 693 | if (!configCheck.success) { |
| 694 | // 创建目录和配置文件 |
| 695 | const createDirResult = await SystemExecutor.run(`mkdir -p ${programDir}/assets/music`); |
| 696 | if (!createDirResult.success) { |
| 697 | return "❌ 无法创建 Music 配置目录。"; |
| 698 | } |
| 699 | |
| 700 | // 创建默认配置文件 |
| 701 | const defaultConfig = { |
| 702 | "music_ytdlp_proxy": `socks5://127.0.0.1:${port}` |
| 703 | }; |
| 704 | const configJson = JSON.stringify(defaultConfig, null, 2); |
| 705 | const writeCmd = `cat > ${configPath} << 'EOF'\n${configJson}\nEOF`; |
| 706 | const writeResult = await SystemExecutor.run(writeCmd); |
| 707 | |
| 708 | if (!writeResult.success) { |
| 709 | return "❌ 无法创建 Music 配置文件。"; |
| 710 | } |
| 711 | } else { |
| 712 | // 读取现有配置文件 |
| 713 | const readResult = await SystemExecutor.run(`cat ${configPath}`); |
| 714 | if (!readResult.success) { |
| 715 | return "❌ 无法读取 Music 配置文件。"; |
| 716 | } |
| 717 | |
| 718 | let config; |
| 719 | try { |
| 720 | config = JSON.parse(readResult.output); |
| 721 | } catch { |
| 722 | return "❌ Music 配置文件格式错误。"; |
| 723 | } |
| 724 | |
| 725 | // 设置代理配置 |
| 726 | config["music_ytdlp_proxy"] = `socks5://127.0.0.1:${port}`; |
| 727 | |
| 728 | // 写回配置文件 |
| 729 | const configJson = JSON.stringify(config, null, 2); |
| 730 | const writeCmd = `cat > ${configPath} << 'EOF'\n${configJson}\nEOF`; |
| 731 | const writeResult = await SystemExecutor.run(writeCmd); |
| 732 | |
| 733 | if (!writeResult.success) { |
no test coverage detected