diff --git a/README.md b/README.md index ecddf89..6771fe5 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mobizt/FirebaseClient/.github%2Fworkflows%2Fcompile_library.yml?logo=github&label=compile) [![Github Stars](https://img.shields.io/github/stars/mobizt/FirebaseClient?logo=github)](https://github.com/mobizt/FirebaseClient/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/FirebaseClient?logo=github) -![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.3.8-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient) +![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.3.9-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient) [![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt) -Revision `2024-07-27T09:57:58Z` +Revision `2024-07-30T02:59:34Z` ## Table of Contents @@ -336,6 +336,8 @@ board_build.filesystem_size = 1m See this Arduino-Pico SDK [documentation](https://arduino-pico.readthedocs.io/en/latest/) for more information. +> [!NOTE] +> You cannot install Arduino IDE and Arduino library in Microsoft's `OneDrive` folder because the `OneDrive` folder is the sandbox or virtual folder instead of real folder which causes the path error when compilation. ## Usages diff --git a/library.json b/library.json index 385986e..cdb2917 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "FirebaseClient", - "version": "1.3.8", + "version": "1.3.9", "keywords": "communication, REST, esp32, esp8266, arduino", "description": "Async Firebase Client library for Arduino.", "repository": { diff --git a/library.properties b/library.properties index 65aa4c6..0fb1465 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=FirebaseClient -version=1.3.8 +version=1.3.9 author=Mobizt diff --git a/src/cloud_storage/CloudStorage.h b/src/cloud_storage/CloudStorage.h index 1b88234..ef92e17 100644 --- a/src/cloud_storage/CloudStorage.h +++ b/src/cloud_storage/CloudStorage.h @@ -1,5 +1,5 @@ /** - * Created July 27, 2024 + * Created July 30, 2024 * * The MIT License (MIT) * Copyright (c) 2024 K. Suwatchai (Mobizt) @@ -466,16 +466,15 @@ class CloudStorage options.extras += uut.encode(parent.getObject()); size_t sz = 0; - +#if defined(ENABLE_FS) if (file && file->cb && file->filename.length()) { -#if defined(ENABLE_FS) file->cb(file->file, file->filename.c_str(), file_mode_open_read); sz = file->file.size(); file->file.close(); -#endif } - else if (file && file->data_size) +#endif + if (file && file->data_size) sz = file->data_size; options.extras += "&uploadType="; @@ -571,7 +570,6 @@ class CloudStorage if (request.options->payload.length()) { -#if defined(ENABLE_FS) if (request.options->extras.indexOf("uploadType=resumable") > -1) { sData->request.val[req_hndlr_ns::payload] = request.options->payload; @@ -585,7 +583,6 @@ class CloudStorage sData->request.file_data.resumable.setSize(sData->request.file_data.file_size ? sData->request.file_data.file_size : sData->request.file_data.data_size); sData->request.file_data.resumable.updateRange(); } -#endif } else { diff --git a/src/core/AsyncClient/AsyncClient.h b/src/core/AsyncClient/AsyncClient.h index 286c78d..0163349 100644 --- a/src/core/AsyncClient/AsyncClient.h +++ b/src/core/AsyncClient/AsyncClient.h @@ -280,8 +280,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase { function_return_type ret = function_return_type_continue; -#if defined(ENABLE_FS) - size_t totalLen = sData->request.file_data.file_size; bool fileopen = sData->request.payloadIndex == 0; @@ -290,6 +288,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase if (fileopen) { +#if defined(ENABLE_FS) if (sData->request.file_data.filename.length() > 0) { if (sData->request.file_data.file_status == file_config_data::file_status_closed) @@ -302,7 +301,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase } } } - +#endif if (sData->request.base64) { ret = send(sData, reinterpret_cast("\""), 1, totalLen, async_state_send_payload); @@ -313,25 +312,32 @@ class AsyncClientClass : public ResultBase, RTDBResultBase uint8_t *buf = nullptr; int toSend = 0; +#if defined(ENABLE_FS) if (sData->request.file_data.filename.length() > 0 ? sData->request.file_data.file.available() : sData->request.file_data.data_pos < sData->request.file_data.data_size) +#else + if (sData->request.file_data.data_pos < sData->request.file_data.data_size) +#endif { if (sData->request.base64) { toSend = FIREBASE_BASE64_CHUNK_SIZE; +#if defined(ENABLE_FS) if (sData->request.file_data.filename.length() > 0) { if (sData->request.file_data.file.available() < toSend) toSend = sData->request.file_data.file.available(); } - else +#endif + if (sData->request.file_data.data && sData->request.file_data.data_size) { if ((int)(sData->request.file_data.data_size - sData->request.file_data.data_pos) < toSend) toSend = sData->request.file_data.data_size - sData->request.file_data.data_pos; } buf = reinterpret_cast(mem.alloc(toSend)); +#if defined(ENABLE_FS) if (sData->request.file_data.filename.length() > 0) { toSend = sData->request.file_data.file.read(buf, toSend); @@ -343,7 +349,8 @@ class AsyncClientClass : public ResultBase, RTDBResultBase goto exit; } } - else if (sData->request.file_data.data) +#endif + if (sData->request.file_data.data && sData->request.file_data.data_size) { memcpy(buf, sData->request.file_data.data + sData->request.file_data.data_pos, toSend); sData->request.file_data.data_pos += toSend; @@ -365,6 +372,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase buf = reinterpret_cast(mem.alloc(toSend)); +#if defined(ENABLE_FS) if (sData->request.file_data.filename.length() > 0) { toSend = sData->request.file_data.file.read(buf, toSend); @@ -376,7 +384,8 @@ class AsyncClientClass : public ResultBase, RTDBResultBase goto exit; } } - else if (sData->request.file_data.data) +#endif + if (sData->request.file_data.data && sData->request.file_data.data_size) { memcpy(buf, sData->request.file_data.data + sData->request.file_data.data_pos, toSend); } @@ -393,7 +402,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase if (buf) mem.release(&buf); -#endif return ret; } @@ -419,19 +427,17 @@ class AsyncClientClass : public ResultBase, RTDBResultBase sData->request.dataIndex += toSend; sData->request.payloadIndex += toSend; -#if defined(ENABLE_FS) if (sData->upload && sData->upload_progress_enabled && sData->request.file_data.file_size) { sData->aResult.upload_data.total = sData->request.file_data.file_size > size ? sData->request.file_data.file_size : size; sData->aResult.upload_data.uploaded = sData->request.payloadIndex; returnResult(sData, false); } -#endif if (sData->request.dataIndex == len) sData->request.dataIndex = 0; -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) if (sData->request.file_data.resumable.isEnabled() && sData->request.file_data.resumable.isUpload()) { @@ -489,7 +495,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase else if (state == async_state_send_payload) sData->state = async_state_read_response; -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) if (sData->upload) { if (sData->request.file_data.resumable.isEnabled()) @@ -593,7 +599,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase if (sData->response.httpCode == 0) return function_return_type_continue; -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) if (sData->request.file_data.resumable.isEnabled() && sData->request.file_data.resumable.getLocation().length() && !sData->response.flags.header_remaining && !sData->response.flags.payload_remaining) { @@ -944,7 +950,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase sData->response.flags.http_response = true; clear(sData->response.val[res_hndlr_ns::etag]); String temp[5]; -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) if (sData->upload) parseRespHeader(sData, sData->response.val[res_hndlr_ns::header], sData->request.file_data.resumable.getLocationRef(), "Location"); #else @@ -977,7 +983,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase clear(sData); -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) if (sData->upload && sData->request.file_data.resumable.isEnabled()) { sData->request.file_data.resumable.setHeaderState(); @@ -1849,18 +1855,20 @@ class AsyncClientClass : public ResultBase, RTDBResultBase void setFileContentLength(async_data_item_t *sData, int headerLen = 0, const String &customHeader = "") { + size_t sz = 0; + #if defined(ENABLE_FS) - if ((sData->request.file_data.cb && sData->request.file_data.filename.length()) || (sData->request.file_data.data_size && sData->request.file_data.data)) + if (sData->request.file_data.cb && sData->request.file_data.filename.length()) { - size_t sz = 0; - if (sData->request.file_data.cb) - { - sData->request.file_data.cb(sData->request.file_data.file, sData->request.file_data.filename.c_str(), file_mode_open_read); - sz = sData->request.file_data.file.size(); - } - else - sz = sData->request.file_data.data_size; + sData->request.file_data.cb(sData->request.file_data.file, sData->request.file_data.filename.c_str(), file_mode_open_read); + sz = sData->request.file_data.file.size(); + } +#endif + if (sData->request.file_data.data_size && sData->request.file_data.data) + sz = sData->request.file_data.data_size; + if (sz > 0) + { sData->request.file_data.file_size = sData->request.base64 ? 2 + b64ut.getBase64Len(sz) : sz; if (customHeader.length()) { @@ -1874,7 +1882,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase closeFile(sData); } -#endif } uint8_t slotCount() const { return sVec.size(); } @@ -1947,7 +1954,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase String getHost(async_data_item_t *sData, bool fromReq, String *ext = nullptr) { -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) String url = fromReq ? sData->request.val[req_hndlr_ns::url] : sData->request.file_data.resumable.getLocation(); #else String url = fromReq ? sData->request.val[req_hndlr_ns::url] : sData->response.val[res_hndlr_ns::location]; diff --git a/src/core/Core.h b/src/core/Core.h index 64a1bc2..d98a5c1 100644 --- a/src/core/Core.h +++ b/src/core/Core.h @@ -7,7 +7,7 @@ #undef FIREBASE_CLIENT_VERSION #endif -#define FIREBASE_CLIENT_VERSION "1.3.8" +#define FIREBASE_CLIENT_VERSION "1.3.9" static void sys_idle() { diff --git a/src/core/FileConfig.h b/src/core/FileConfig.h index d46e814..680133f 100644 --- a/src/core/FileConfig.h +++ b/src/core/FileConfig.h @@ -1,5 +1,5 @@ /** - * Created July 27, 2024 + * Created July 30, 2024 * * The MIT License (MIT) * Copyright (c) 2024 K. Suwatchai (Mobizt) @@ -82,7 +82,7 @@ struct firebase_blob_writer typedef void (*FileConfigCallback)(FILEOBJ &file, const char *filename, file_operating_mode mode); #endif -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) struct file_upload_resumable_data { @@ -207,7 +207,7 @@ struct file_config_data String filename; size_t file_size = 0; -#if defined(ENABLE_FS) && defined(ENABLE_CLOUD_STORAGE) +#if defined(ENABLE_CLOUD_STORAGE) file_upload_resumable_data resumable; #endif #if defined(ENABLE_FS)