|
1 | 1 | //[llms-txt-valid] |
2 | | -return fetch('/llms.txt') |
| 2 | + |
| 3 | +const fetchWithTimeout = (url) => { |
| 4 | + var controller = new AbortController(); |
| 5 | + setTimeout(() => {controller.abort()}, 5000); |
| 6 | + return fetch(url, {signal: controller.signal}); |
| 7 | +} |
| 8 | + |
| 9 | +return fetchWithTimeout('/llms.txt') |
3 | 10 | .then(response => { |
4 | | - if (!response.ok) return JSON.stringify({valid:0, error: "Non OK status code"}); |
| 11 | + if (!response.ok) return JSON.stringify({valid:0, message:response.status, error: "Non OK status code"}); |
5 | 12 | const ct = response.headers.get('Content-Type')||''; |
6 | 13 | if (!ct.toLowerCase().includes('text/plain')) return JSON.stringify({valid:0,error: "Invalid content type"}); |
7 | 14 | return response.text().then(text => { |
8 | 15 | const m = s=> (text.match(new RegExp(`\\${s}`,'g'))||[]).length; |
9 | | - if ((text.match(/```/g)||[]).length %2) return JSON.stringify({valid:0,error:""}); |
10 | | - if (m('[')!==m(']')||m('(')!==m(')')) return JSON.stringify({valid:0,error:""}); |
| 16 | + if ((text.match(/```/g)||[]).length %2) return JSON.stringify({valid:0, error:"Invalid markdown fences"}); |
| 17 | + if (m('[')!==m(']')||m('(')!==m(')')) return JSON.stringify({valid:0, error:"Unmatch braces"}); |
11 | 18 | return JSON.stringify({valid:1}); |
12 | 19 | }); |
13 | 20 | }) |
14 | 21 | .catch(error => { |
15 | | - return JSON.stringify({valid:0,message: error.message, error: error}); |
| 22 | + return JSON.stringify({valid:0, message: error.message, error: error}); |
16 | 23 | }); |
0 commit comments