(options: InfoOptions)
| 142 | } |
| 143 | |
| 144 | export const runInfo = async (options: InfoOptions): Promise<number> => { |
| 145 | const payload = await getInfoPayload() |
| 146 | |
| 147 | if (options.torHostname) { |
| 148 | if (payload.tor.hostname) { |
| 149 | if (options.json) { |
| 150 | writeJson({ torHostname: payload.tor.hostname }) |
| 151 | return 0 |
| 152 | } |
| 153 | |
| 154 | logInfo(payload.tor.hostname) |
| 155 | return 0 |
| 156 | } |
| 157 | |
| 158 | if (options.json) { |
| 159 | process.stderr.write( |
| 160 | `${JSON.stringify({ error: { message: 'Tor hostname not found. Start with `nostream start --tor` first.', code: 1 } })}\n`, |
| 161 | ) |
| 162 | return 1 |
| 163 | } |
| 164 | |
| 165 | logError('Tor hostname not found. Start with `nostream start --tor` first.') |
| 166 | return 1 |
| 167 | } |
| 168 | |
| 169 | if (options.i2pHostname) { |
| 170 | const keysFile = getProjectPath('.nostr', 'i2p', 'data', 'nostream.dat') |
| 171 | const i2pGuidance: I2PGuidancePayload = { |
| 172 | i2pHostnames: [], |
| 173 | keysFile, |
| 174 | guidance: { |
| 175 | webConsoleUrl: 'http://127.0.0.1:7070/?page=i2p_tunnels', |
| 176 | consoleQueryCommand: |
| 177 | "docker exec i2pd wget -qO- 'http://127.0.0.1:7070/?page=i2p_tunnels' | grep -oE '[a-z2-7]{52}\\\\.b32\\\\.i2p' | sort -u", |
| 178 | }, |
| 179 | } |
| 180 | |
| 181 | if (!fs.existsSync(keysFile)) { |
| 182 | if (options.json) { |
| 183 | writeJsonError(`I2P destination keys not found. Is the i2pd container running? Expected: ${keysFile}`) |
| 184 | return 1 |
| 185 | } |
| 186 | |
| 187 | logError('I2P destination keys not found. Is the i2pd container running?') |
| 188 | logError(`Expected: ${keysFile}`) |
| 189 | return 1 |
| 190 | } |
| 191 | |
| 192 | const result = await runCommandWithOutput('docker', [ |
| 193 | 'exec', |
| 194 | 'i2pd', |
| 195 | 'wget', |
| 196 | '-qO-', |
| 197 | 'http://127.0.0.1:7070/?page=i2p_tunnels', |
| 198 | ]) |
| 199 | |
| 200 | const matches = new Set((`${result.stdout}\n${result.stderr}`).match(/[a-z2-7]{52}\.b32\.i2p/g) ?? []) |
| 201 | if (matches.size > 0) { |
no test coverage detected