Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Hammacher <bmasterc@gmail.com>2022-02-06 19:16:29 +0300
committerChristian Hammacher <bmasterc@gmail.com>2022-02-06 19:16:29 +0300
commitb8b63b24eeced90323f38ce6c71cf65a28aaf4c3 (patch)
treebad85952c676a2b8fccc81de4b917d452020d019 /src
parent435628494d4c4ee40979ff102de5b245bd6c2e1b (diff)
Fixed inconsistency with err code of rr_thumbnail
Diffstat (limited to 'src')
-rw-r--r--src/GCodes/GCodes2.cpp2
-rw-r--r--src/Networking/HttpResponder.cpp2
-rw-r--r--src/Platform/RepRap.cpp12
-rw-r--r--src/Platform/RepRap.h2
4 files changed, 12 insertions, 6 deletions
diff --git a/src/GCodes/GCodes2.cpp b/src/GCodes/GCodes2.cpp
index ba21bcb1..91afae7e 100644
--- a/src/GCodes/GCodes2.cpp
+++ b/src/GCodes/GCodes2.cpp
@@ -1148,7 +1148,7 @@ bool GCodes::HandleMcode(GCodeBuffer& gb, const StringRef& reply) THROWS(GCodeEx
gb.GetQuotedString(filename.GetRef(), false);
gb.MustSee('S');
const FilePosition offset = gb.GetUIValue();
- outBuf = reprap.GetThumbnailResponse(filename.c_str(), offset);
+ outBuf = reprap.GetThumbnailResponse(filename.c_str(), offset, true);
if (outBuf == nullptr)
{
return false; // cannot allocate an output buffer, try again later
diff --git a/src/Networking/HttpResponder.cpp b/src/Networking/HttpResponder.cpp
index e7d77150..c176d0c8 100644
--- a/src/Networking/HttpResponder.cpp
+++ b/src/Networking/HttpResponder.cpp
@@ -596,7 +596,7 @@ bool HttpResponder::GetJsonResponse(const char *_ecv_array request, OutputBuffer
if (nameVal != nullptr && offsetVal != nullptr && (offset = StrToU32(offsetVal)) != 0)
{
OutputBuffer::ReleaseAll(response);
- response = reprap.GetThumbnailResponse(nameVal, offset);
+ response = reprap.GetThumbnailResponse(nameVal, offset, false);
}
else
{
diff --git a/src/Platform/RepRap.cpp b/src/Platform/RepRap.cpp
index 1da497d2..afedce45 100644
--- a/src/Platform/RepRap.cpp
+++ b/src/Platform/RepRap.cpp
@@ -2267,7 +2267,8 @@ OutputBuffer *RepRap::GetFilelistResponse(const char *dir, unsigned int startAt)
// 'offset' is the offset into the file of the thumbnail data that the caller wants.
// It is up to the caller to get the offset right, however we must fail gracefully if the caller passes us a bad offset.
// The offset should always be either the initial offset or the 'next' value passed in a previous call, so it should always be the start of a line.
-OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition offset) noexcept
+// 'encapsulateThumbnail' defines whether the thumbnail shall be encapsulated as a "thumbnail" property of the root object
+OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition offset, bool encapsulateThumbnail) noexcept
{
constexpr unsigned int ThumbnailMaxDataSize = 1024;
static_assert(ThumbnailMaxDataSize % 4 == 0, "must be a multiple of to guarantee base64 alignment");
@@ -2279,7 +2280,12 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of
return nullptr;
}
- response->printf("{\"thumbnail\":{\"fileName\":\"%.s\",\"offset\":%" PRIu32 ",", filename, offset);
+ if (encapsulateThumbnail)
+ {
+ response->cat("{\"thumbnail\":");
+ }
+ response->catf("{\"fileName\":\"%.s\",\"offset\":%" PRIu32 ",", filename, offset);
+
FileStore *const f = platform->OpenFile(platform->GetGCodeDir(), filename, OpenMode::read);
unsigned int err = 0;
if (f != nullptr)
@@ -2353,7 +2359,7 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of
err = 1;
}
- response->catf("\"err\":%u}}\n", err);
+ response->catf(encapsulateThumbnail ? "\"err\":%u}}\n" : "\"err\":%u}\n", err);
return response;
}
diff --git a/src/Platform/RepRap.h b/src/Platform/RepRap.h
index ca3c4cba..d620d811 100644
--- a/src/Platform/RepRap.h
+++ b/src/Platform/RepRap.h
@@ -148,7 +148,7 @@ public:
#if HAS_MASS_STORAGE || HAS_EMBEDDED_FILES
OutputBuffer *GetFilesResponse(const char* dir, unsigned int startAt, bool flagsDirs) noexcept;
OutputBuffer *GetFilelistResponse(const char* dir, unsigned int startAt) noexcept;
- OutputBuffer *GetThumbnailResponse(const char *filename, FilePosition offset) noexcept;
+ OutputBuffer *GetThumbnailResponse(const char *filename, FilePosition offset, bool encapsulateThumbnail) noexcept;
#endif
GCodeResult GetFileInfoResponse(const char *filename, OutputBuffer *&response, bool quitEarly) noexcept;