()
| 667 | // 移除多余的斜杠 |
| 668 | fullPath = fullPath.replace(/\/+/g, "/"); |
| 669 | |
| 670 | await msg.edit({ text: `正在上传到: ${codeTag(fullPath)}`, parseMode: "html" }); |
| 671 | |
| 672 | const apiUrl = "http://127.0.0.1:5244/api/fs/put"; |
| 673 | |
| 674 | // 注意:Header 中的中文路径需要编码 |
| 675 | await axios.put(apiUrl, buffer, { |
| 676 | headers: { |
| 677 | "Authorization": token, |
| 678 | "File-Path": encodeURIComponent(fullPath), |
| 679 | "path": encodeURIComponent(fullPath), |
| 680 | "Content-Type": "application/octet-stream", |
| 681 | "As-Task": "false" |
| 682 | }, |
| 683 | maxBodyLength: Infinity, |
| 684 | maxContentLength: Infinity |
| 685 | }); |
| 686 | |
| 687 | await msg.edit({ text: `✅ 文件已上传到 OpenList: ${codeTag(fullPath)}`, parseMode: "html" }); |
| 688 | |
| 689 | } catch (error: any) { |
| 690 | console.error("OpenList Upload Error:", error); |
| 691 | const errMsg = error?.response?.data?.message || error.message || "未知错误"; |
| 692 | throw new Error(`上传失败: ${errMsg}`); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | private async getOpenListCredentials() { |
| 697 | // 1. Get DB credentials |
| 698 | let dbUser = ""; |
| 699 | let dbPass = ""; |
| 700 | try { |
| 701 | const db = await this.getDb(); |
| 702 | dbUser = db.data.username; |
| 703 | dbPass = db.data.password; |
| 704 | } catch (e) {} |
| 705 | |
| 706 | // 2. Get Config credentials |
| 707 | let configUser = ""; |
| 708 | let configPass = ""; |
| 709 | const installPath = await this.detectInstalledPath(); |
| 710 | const configPath = `${installPath}/data/config.json`; |
| 711 | |
| 712 | if (await this.fileExists(configPath)) { |
| 713 | try { |
| 714 | let configContent = ""; |
| 715 | try { |
| 716 | configContent = await fs.readFile(configPath, "utf-8"); |
| 717 | } catch { |
| 718 | const { stdout } = await execAsync(`cat "${configPath}" 2>/dev/null`); |
| 719 | configContent = stdout; |
| 720 | } |
| 721 | |
| 722 | if (configContent) { |
| 723 | const config = JSON.parse(configContent); |
| 724 | if (config.users && config.users.length > 0) { |
| 725 | configUser = config.users[0].username; |
no test coverage detected