A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: webserver /delete API backward compatibility (#1475)

## Summary

* **What is the goal of this PR?** (e.g., Implements the new feature for
file uploading.)

This fixes #682 by restoring API compatibility for external users, eg
deleting on-device books in bulk via calibre using the crosspoint plugin
works now.

* **What changes are included?**

The `/delete` webserver API now accepts the old `path` argument and maps
it to a JSON array element. It is made an error to provide both
arguments.

## Additional Context

* Add any other information that might be helpful for the reviewer
(e.g., performance implications, potential risks,
specific areas to focus on).

I have compiled, flashed, and tested this on master at commit
0245972132b54563976525a5841a0e9c49e8e498. Before this change, calibre
cannot delete books, either individually or in bulk.

After this change, it can do so successfully.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**< NO >**_

authored by

Diana and committed by
GitHub
05f8e6e1 405ce0c3

+20 -5
+20 -5
src/network/CrossPointWebServer.cpp
··· 959 959 } 960 960 961 961 void CrossPointWebServer::handleDelete() const { 962 - // Check if 'paths' argument is provided 963 - if (!server->hasArg("paths")) { 964 - server->send(400, "text/plain", "Missing paths"); 962 + // To ensure backwards compatibility, plain `path` is mapped 963 + // to a single element JSON array. 964 + bool hasPathArg = server->hasArg("path"); 965 + bool hasPathsArg = server->hasArg("paths"); 966 + // Check 'paths' or `path` argument is provided 967 + if (!(hasPathArg || hasPathsArg)) { 968 + server->send(400, "text/plain", "Missing `path` or `paths` argument"); 969 + return; 970 + } 971 + if (hasPathArg && hasPathsArg) { 972 + server->send(400, "text/plain", "Provide either 'path' or 'paths', not both"); 965 973 return; 966 974 } 967 975 968 976 // Parse paths 969 - String pathsArg = server->arg("paths"); 977 + String pathsArg; 970 978 JsonDocument doc; 971 - DeserializationError error = deserializeJson(doc, pathsArg); 979 + DeserializationError error = DeserializationError(DeserializationError::Code::Ok); 980 + if (hasPathsArg) { 981 + pathsArg = server->arg("paths"); 982 + error = deserializeJson(doc, pathsArg); 983 + } else { 984 + pathsArg = server->arg("path"); 985 + doc.add(pathsArg); 986 + } 972 987 if (error) { 973 988 server->send(400, "text/plain", "Invalid paths format"); 974 989 return;