(text)
| 754 | } |
| 755 | |
| 756 | async function parseContent(text) { |
| 757 | text = text.trim() |
| 758 | if (text.startsWith("{") && text.endsWith("}")) { |
| 759 | try { |
| 760 | const task = JSON.parse(text) |
| 761 | if (!("reqBody" in task)) { |
| 762 | // support the format saved to the disk, by the UI |
| 763 | task.reqBody = Object.assign({}, task) |
| 764 | } |
| 765 | restoreTaskToUI(task) |
| 766 | return true |
| 767 | } catch (e) { |
| 768 | console.warn(`JSON text content couldn't be parsed.`, e) |
| 769 | } |
| 770 | return false |
| 771 | } |
| 772 | // Normal txt file. |
| 773 | const task = parseTaskFromText(text) |
| 774 | if (text.toLowerCase().includes("seed:") && task) { |
| 775 | // only parse valid task content |
| 776 | restoreTaskToUI(task) |
| 777 | return true |
| 778 | } else { |
| 779 | console.warn(`Raw text content couldn't be parsed.`) |
| 780 | promptField.value = text |
| 781 | return false |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | async function readFile(file, i) { |
| 786 | console.log(`Event %o reading file[${i}]:${file.name}...`) |
no test coverage detected