#include "ln_api.h"
#include <stdio.h>
+#define story_random_file_path "/user/leiniao/story/random.txt"
+
+static void ln_parse_story_random_file(void)
+{
+ printf("Starting to parse story choose file...\n");
+
+ uint32_t result = ln_parse_file_and_process_data(story_random_file_path, LN_HTTP_RECV_STORY_RANDOM);
+
+ if (result == ERRCODE_SUCC)
+ {
+ printf("Story file parsing completed successfully!\n");
+ }
+ else
+ {
+ printf("Story file parsing failed!\n");
+ }
+}
+
+
uint32_t ln_story_random_http(const char *device_id,
const char *device_token,
const char *story_theme)
return ret;
}
+ // 打开文件准备写入
+ const char *save_path_folder = "/user/leiniao/story/";
+ // 判断目录是否存在,不存在则创建
+ if (access(save_path_folder, F_OK) == -1)
+ {
+ uapi_create_folder(save_path_folder);
+ }
+ FILE *fd = fopen(story_random_file_path, "w+");
+ if (!fd)
+ {
+ printf("story choose: fopen failed for %s:\n", story_random_file_path);
+ HttpClientClse(&client);
+ HttpClientUnprepare(&clientData);
+ return ERRCODE_FAIL;
+ }
+
+ size_t total_written = 0;
do
{
HTTPC_RESULT recv_res = HttpClientRecvResponse(&client, &clientData);
// 处理接收到的数据块
if (clientData.contentBlockLen > 0)
{
- do_ln_http_server_recv_data(LN_HTTP_RECV_STORY_RANDOM,
- clientData.responseBuf, clientData.contentBlockLen);
+ size_t written = fwrite(clientData.responseBuf, 1, clientData.contentBlockLen, fd);
+ if (written != clientData.contentBlockLen)
+ {
+ printf("story random: write failed, written=%zu, expected=%d\n",
+ written, clientData.contentBlockLen);
+ HttpClientClse(&client);
+ HttpClientUnprepare(&clientData);
+ fclose(fd);
+ return ERRCODE_FAIL;
+ }
+ total_written += written;
}
}
else
HttpClientUnprepare(&clientData);
HttpClientClse(&client);
+
+ if (total_written > 0)
+ {
+ ln_parse_story_random_file();
+ }
+
return ERRCODE_SUCC;
}