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) {
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) {
@ -140,7 +140,7 @@ function action_purge(object $opts) {
if (!$collection) {
exit_error("Missing collection. Expected: purge {collection}");
}
http_post($collection."/delete", [], null)->then(
http_post($collection."/purge", [], null)->then(
function ($response) {
echo $response->getBody()->getContents();
},

View File

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