(msg: Api.Message)
| 737 | // If DB is missing password but has username (e.g. after setuser), use config password (if available/valid) |
| 738 | const finalPass = dbPass || configPass; |
| 739 | |
| 740 | if (finalUser && finalPass) { |
| 741 | // Auto-sync if we had to combine sources |
| 742 | if (!dbUser || !dbPass) { |
| 743 | await this.updateStoredCredentials(finalUser, finalPass); |
| 744 | } |
| 745 | return { username: finalUser, password: finalPass }; |
| 746 | } |
| 747 | |
| 748 | return null; |
| 749 | } |
| 750 | |
| 751 | private async getOpenListToken(username: string, password: string): Promise<string> { |
| 752 | try { |
| 753 | const response = await axios.post("http://127.0.0.1:5244/api/auth/login", { |
| 754 | username, |
| 755 | password |
| 756 | }); |
| 757 | if (response.data && response.data.code === 200) { |
| 758 | return response.data.data.token; |
| 759 | } |
| 760 | throw new Error(response.data?.message || "Login failed"); |
| 761 | } catch (error) { |
| 762 | throw error; |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | private async handleStatus(msg: Api.Message) { |
| 767 | try { |
| 768 | if (process.platform !== "linux") { |
| 769 | await msg.edit({ text: "仅支持 Linux(systemd)环境" }); |
| 770 | return; |
| 771 | } |
| 772 | const installPath = await this.detectInstalledPath(); |
| 773 | const installed = await this.fileExists(`${installPath}/openlist`); |
| 774 | const { stdout: activeOut } = await execAsync( |
| 775 | `bash -lc 'systemctl is-active openlist 2>/dev/null || true'` |
| 776 | ); |
| 777 | const status = (activeOut || "").trim() || "unknown"; |
| 778 | |
| 779 | const { stdout: portOut } = await execAsync( |
| 780 | `bash -lc '(ss -tlnp 2>/dev/null || netstat -tlnp 2>/dev/null) | grep -q ":5244" && echo listen || echo closed'` |
| 781 | ); |
| 782 | const port = (portOut || "").trim(); |
| 783 | |
| 784 | let version = ""; |
| 785 | if (installed) { |
| 786 | try { |
| 787 | const { stdout: verOut } = await execAsync( |
| 788 | `bash -lc '"${installPath}/openlist" version 2>&1 | grep -E "^Version:" || true'` |
| 789 | ); |
| 790 | const m = verOut.match(/Version:\s*([^\s]+)/); |
| 791 | version = m ? m[1] : ""; |
| 792 | } catch {} |
| 793 | } |
| 794 | |
| 795 | let publicIp = ""; |
| 796 | try { |
no test coverage detected