Fix deletion of key/value over HTTP

This commit is contained in:
2024-09-27 17:26:46 +02:00
parent 5ec45a5dec
commit 6d240acdb4
2 changed files with 3 additions and 4 deletions

View File

@ -87,7 +87,7 @@ function http_get(string $url, array $headers) {
function http_post(string $url, array $headers, ?string $body = null) { function http_post(string $url, array $headers, ?string $body = null) {
global $opts,$http; global $opts,$http;
return $http->post("http://{$opts->server}/{$url}", $headers, $body); return $http->post("http://{$opts->server}/{$url}", $headers, $body??'');
} }
function action_get(object $opts) { function action_get(object $opts) {
@ -140,7 +140,7 @@ function action_purge(object $opts) {
if (!$collection) { if (!$collection) {
exit_error("Missing collection. Expected: purge {collection}"); exit_error("Missing collection. Expected: purge {collection}");
} }
http_post($collection."/delete", [], null)->then( http_post($collection."/purge", [], null)->then(
function ($response) { function ($response) {
echo $response->getBody()->getContents(); echo $response->getBody()->getContents();
}, },

View File

@ -113,7 +113,6 @@ class Daemon
return Response::json([ 'error' => "Invalid request method" ]); return Response::json([ 'error' => "Invalid request method" ]);
} }
try { try {
$ids = json_decode($request->getBody()->getContents(), true);
$this->opCollectionPurge($collectionName); $this->opCollectionPurge($collectionName);
} catch (\Exception $e) { } catch (\Exception $e) {
return Response::json([ 'error' => "No such collection" ])->withStatus(404); return Response::json([ 'error' => "No such collection" ])->withStatus(404);
@ -155,7 +154,7 @@ class Daemon
try { try {
$collection = $this->db->getCollection($collectionName); $collection = $this->db->getCollection($collectionName);
foreach ($ids as $id) { foreach ($ids as $id) {
if (is_int($id)) { if (intval($id) > 0) {
$collection->deleteValue(intval($id)); $collection->deleteValue(intval($id));
} else { } else {
$collection->deleteKey($id); $collection->deleteKey($id);