( output: string, args: string[] )
| 279 | } |
| 280 | |
| 281 | const lines = output.split("\n"); |
| 282 | |
| 283 | let answerSection: string[] = []; |
| 284 | let inAnswerSection = false; |
| 285 | |
| 286 | for (const line of lines) { |
| 287 | if (line.includes(";; ANSWER SECTION:")) { |
| 288 | inAnswerSection = true; |
| 289 | continue; |
| 290 | } |
| 291 | if (inAnswerSection) { |
| 292 | if (line.startsWith(";;") || line.trim() === "") { |
| 293 | break; |
| 294 | } |
| 295 | if (line.trim() !== "" && !line.startsWith(";")) { |
| 296 | answerSection.push(line.trim()); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | if (answerSection.length === 0) { |
| 302 | const contentLines = lines.filter((line) => { |
| 303 | const trimmed = line.trim(); |
| 304 | return ( |
| 305 | (trimmed !== "" && |
| 306 | !trimmed.startsWith(";;") && |
| 307 | !trimmed.startsWith(";") && |
| 308 | trimmed.includes("\t")) || |
| 309 | trimmed.split(/\s+/).length >= 4 |
| 310 | ); |
| 311 | }); |
| 312 | |
| 313 | answerSection = contentLines; |
| 314 | } |
| 315 | |
| 316 | const domain = extractDomainFromArgs(args); |
| 317 | let resultText = `🔍 <b>DNS 解析</b>`; |
| 318 | if (domain) { |
| 319 | resultText += ` - <code>${htmlEscape(domain)}</code>`; |
| 320 | } |
| 321 | resultText += "\n"; |
| 322 | |
| 323 | if (answerSection.length === 0) { |
| 324 | resultText += "\n\n❌ 无记录"; |
| 325 | return resultText; |
| 326 | } |
| 327 | |
| 328 | const displayLines = answerSection.slice(0, 3); |
| 329 | const hasMore = answerSection.length > 3; |
| 330 | |
| 331 | for (let i = 0; i < displayLines.length; i++) { |
| 332 | const line = displayLines[i] || ""; |
| 333 | const record = parseDnsRecord(line); |
| 334 | |
| 335 | if (record) { |
| 336 | let icon = "📋"; |
| 337 | if (record.type === "A") icon = "📍"; |
| 338 | else if (record.type === "AAAA") icon = "📍"; |
no test coverage detected