jblanked 1 год назад
Родитель
Сommit
05ff1a2f0d
3 измененных файлов с 43 добавлено и 10 удалено
  1. 39 1
      callback/web_crawler_callback.c
  2. 2 2
      html/html_furi.c
  3. 2 7
      html/html_furi.h

+ 39 - 1
callback/web_crawler_callback.c

@@ -746,7 +746,45 @@ static char *web_crawler_parse(DataLoaderModel *model)
         if (strstr(http_method, "BROWSE") != NULL)
         {
             // parse HTML then return response
-            return "HTML response parsed.\nPress BACK to return.";
+            FuriString *returned_data = flipper_http_load_from_file(model->fhttp->file_path);
+            if (returned_data == NULL)
+            {
+                return "Failed to load HTML response.\nPress BACK to return.";
+            }
+            // parse HTML response
+            FuriString *h1_tag = html_furi_parse("<h1>", returned_data, 0);
+            FuriString *p_tag = html_furi_parse("<p>", returned_data, 0);
+            furi_string_free(returned_data);
+            if (p_tag == NULL && h1_tag == NULL)
+            {
+                return "Failed to find <h1> or <p> tag.\nPress BACK to return.";
+            }
+            else if (p_tag && h1_tag)
+            {
+                FuriString *combined = furi_string_alloc_printf("%s\n%s", furi_string_get_cstr(h1_tag), furi_string_get_cstr(p_tag));
+                if (combined)
+                {
+                    furi_string_free(h1_tag);
+                    furi_string_free(p_tag);
+                    return (char *)furi_string_get_cstr(combined);
+                }
+                else
+                {
+                    furi_string_free(h1_tag);
+                    furi_string_free(p_tag);
+                    return "Failed to combine <h1> and <p> tags.\nPress BACK to return.";
+                }
+            }
+            else if (h1_tag != NULL)
+            {
+                furi_string_free(p_tag);
+                return (char *)furi_string_get_cstr(h1_tag);
+            }
+            else if (p_tag != NULL)
+            {
+                furi_string_free(h1_tag);
+                return (char *)furi_string_get_cstr(p_tag);
+            }
         }
     }
     return "Data saved to file.\nPress BACK to return.";

+ 2 - 2
html/html_furi.c

@@ -42,7 +42,7 @@ static bool furi_string_sub_equals(FuriString *str, int pos, const char *needle)
  * @return A newly allocated FuriString containing the parsed content,
  *         or an empty FuriString if the tag is not found.
  */
-FuriString *html_furi_parse(const char *tag, FuriString *html)
+FuriString *html_furi_parse(const char *tag, FuriString *html, size_t index)
 {
     int tag_len = strlen(tag);
 
@@ -72,7 +72,7 @@ FuriString *html_furi_parse(const char *tag, FuriString *html)
     // Locate the first occurrence of the opening tag.
     int html_len = furi_string_size(html);
     int open_tag_index = -1;
-    for (int i = 0; i <= html_len - tag_len; i++)
+    for (int i = index; i <= html_len - tag_len; i++)
     {
         if (furi_string_sub_equals(html, i, tag))
         {

+ 2 - 7
html/html_furi.h

@@ -1,10 +1,5 @@
 #pragma once
 #include <furi.h>
 #include <furi_hal.h>
-/*
- * @brief Parse a Furigana string from an HTML tag
- * @param tag The HTML tag to parse
- * @param html The HTML string to parse
- * @return A Furigana string containing the parsed Furigana
- */
-FuriString *html_furi_parse(const char *tag, FuriString *html);
+
+FuriString *html_furi_parse(const char *tag, FuriString *html, size_t index);