Skip to content

Commit

Permalink
Fix ENABLE_FS compiler flag related issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 30, 2024
1 parent e1f31bf commit 0a6363b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=FirebaseClient

version=1.3.8
version=1.3.9

author=Mobizt

Expand Down
11 changes: 4 additions & 7 deletions src/cloud_storage/CloudStorage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created July 27, 2024
* Created July 30, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -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=";
Expand Down Expand Up @@ -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;
Expand All @@ -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
{
Expand Down
57 changes: 32 additions & 25 deletions src/core/AsyncClient/AsyncClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -302,7 +301,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
}
}
}

#endif
if (sData->request.base64)
{
ret = send(sData, reinterpret_cast<const uint8_t *>("\""), 1, totalLen, async_state_send_payload);
Expand All @@ -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<uint8_t *>(mem.alloc(toSend));
#if defined(ENABLE_FS)
if (sData->request.file_data.filename.length() > 0)
{
toSend = sData->request.file_data.file.read(buf, toSend);
Expand All @@ -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;
Expand All @@ -365,6 +372,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

buf = reinterpret_cast<uint8_t *>(mem.alloc(toSend));

#if defined(ENABLE_FS)
if (sData->request.file_data.filename.length() > 0)
{
toSend = sData->request.file_data.file.read(buf, toSend);
Expand All @@ -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);
}
Expand All @@ -393,7 +402,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

if (buf)
mem.release(&buf);
#endif

return ret;
}
Expand All @@ -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())
{
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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())
{
Expand All @@ -1874,7 +1882,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase

closeFile(sData);
}
#endif
}

uint8_t slotCount() const { return sVec.size(); }
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 3 additions & 3 deletions src/core/FileConfig.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created July 27, 2024
* Created July 30, 2024
*
* The MIT License (MIT)
* Copyright (c) 2024 K. Suwatchai (Mobizt)
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0a6363b

Please sign in to comment.