Skip to content

Commit b5cf1ba

Browse files
committed
Allow delete method
1 parent c806d7a commit b5cf1ba

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Endpoints/VerifiedEndpoint.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function handleRequest(string $method, ServerRequestInterface|string $req
2626
$this->handleGet($response, $content_type, $body);
2727
break;
2828
case 'POST':
29+
case 'DELETE':
2930
$this->handlePost($request, $response, $content_type, $body, $this->state->getJsonPath());
3031
break;
3132
default:
@@ -107,8 +108,10 @@ private function handlePost(ServerRequestInterface|string $request, int|string &
107108

108109
switch ($methodType) {
109110
case 'delete':
111+
$existingIndex = array_search($ckey, array_column($list, 'ss13'));
112+
if ($existingIndex === false) $existingIndex = array_search($discord, array_column($list, 'discord'));
110113
$this->handleDelete(
111-
array_search($discord, array_column($list, 'discord')),
114+
$existingIndex,
112115
$list,
113116
$response,
114117
$content_type,
@@ -147,10 +150,12 @@ private function handleDelete(int|string|false $existingIndex, array &$list, int
147150
$body = 'Not Found';
148151
return;
149152
}
150-
array_splice($list, $existingIndex, 1);
153+
$splice = array_splice($list, $existingIndex, 1);
151154
PersistentState::writeJson($this->state->getJsonPath(), $list);
152155
$this->state->setVerifyList($list);
153-
$content_type = ['Content-Type' => 'text/plain'];
156+
$response = Response::STATUS_OK;
157+
$content_type = ['Content-Type' => 'application/json'];
158+
$body = json_encode($splice);
154159
}
155160

156161
/**
@@ -186,6 +191,7 @@ public function handleDefault(array &$list, string $ckey, string $discord, int|s
186191
PersistentState::writeJson($this->state->getJsonPath(), $list);
187192
$this->state->setVerifyList($list);
188193
$response = Response::STATUS_OK;
189-
$content_type = ['Content-Type' => 'text/plain'];
194+
$content_type = ['Content-Type' => 'application/json'];
195+
$body = json_encode($list);
190196
}
191197
}

0 commit comments

Comments
 (0)