codelion commited on
Commit
a85394b
·
verified ·
1 Parent(s): 6580177

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -66,7 +66,7 @@ def fetch_search_results(query):
66
 
67
  @app.route('/', methods=['GET'])
68
  def search_page():
69
- """Serve the initial page or process search with a left-to-right progress bar and URL validation."""
70
  query = request.args.get('query', '')
71
  page = request.args.get('page', '1')
72
  btn = request.args.get('btn', 'LLM Search')
@@ -335,6 +335,7 @@ def search_page():
335
  .search-result {{ margin-bottom: 28px; }}
336
  .search-result a {{ color: #1a0dab; font-size: 20px; text-decoration: none; }}
337
  .search-result a:hover {{ text-decoration: underline; }}
 
338
  .search-result .url {{ color: #006621; font-size: 14px; line-height: 20px; }}
339
  .search-result p {{ color: #4d5156; font-size: 14px; line-height: 22px; margin: 0; }}
340
  .pagination {{ text-align: center; margin: 40px 0; }}
@@ -351,7 +352,6 @@ def search_page():
351
  from {{ width: 0%; }}
352
  to {{ width: 100%; }}
353
  }}
354
- .broken {{ color: #d93025; }}
355
  </style>
356
  <script>
357
  function showProgress() {{
@@ -365,8 +365,11 @@ def search_page():
365
  for (let i = 0; i < links.length; i++) {{
366
  const url = links[i].href;
367
  try {{
368
- const response = await fetch(url, {{ method: 'HEAD', mode: 'no-cors' }});
369
- if (!response.ok && response.status !== 0) {{ // 0 indicates no-cors limitation
 
 
 
370
  links[i].textContent += ' [Broken Link]';
371
  links[i].classList.add('broken');
372
  }}
 
66
 
67
  @app.route('/', methods=['GET'])
68
  def search_page():
69
+ """Serve the initial page or process search with a progress bar and URL validation."""
70
  query = request.args.get('query', '')
71
  page = request.args.get('page', '1')
72
  btn = request.args.get('btn', 'LLM Search')
 
335
  .search-result {{ margin-bottom: 28px; }}
336
  .search-result a {{ color: #1a0dab; font-size: 20px; text-decoration: none; }}
337
  .search-result a:hover {{ text-decoration: underline; }}
338
+ .search-result a.broken {{ color: #d93025; }}
339
  .search-result .url {{ color: #006621; font-size: 14px; line-height: 20px; }}
340
  .search-result p {{ color: #4d5156; font-size: 14px; line-height: 22px; margin: 0; }}
341
  .pagination {{ text-align: center; margin: 40px 0; }}
 
352
  from {{ width: 0%; }}
353
  to {{ width: 100%; }}
354
  }}
 
355
  </style>
356
  <script>
357
  function showProgress() {{
 
365
  for (let i = 0; i < links.length; i++) {{
366
  const url = links[i].href;
367
  try {{
368
+ const controller = new AbortController();
369
+ const timeoutId = setTimeout(() => controller.abort(), 5000); // 5s timeout
370
+ const response = await fetch(url, {{ method: 'HEAD', signal: controller.signal }});
371
+ clearTimeout(timeoutId);
372
+ if (!response.ok) {{
373
  links[i].textContent += ' [Broken Link]';
374
  links[i].classList.add('broken');
375
  }}