feat(*.php, *.psql): deduplicate API code + performance improvements

This commit is contained in:
Cory Dransfeldt 2025-04-22 12:39:42 -07:00
parent cf3dac8a46
commit 4bad005e58
No known key found for this signature in database
31 changed files with 502 additions and 666 deletions

View file

@ -47,7 +47,7 @@ class SearchHandler extends BaseHandler
],
200
);
} catch (Exception $e) {
} catch (\Exception $e) {
error_log("Search API Error: " . $e->getMessage());
$this->sendErrorResponse("Invalid request. Please check your query and try again.", 400);
}
@ -55,15 +55,15 @@ class SearchHandler extends BaseHandler
private function validateAndSanitizeQuery(?string $query): string
{
if (empty($query) || !is_string($query)) throw new Exception("Invalid 'q' parameter. Must be a non-empty string.");
if (empty($query) || !is_string($query)) throw new \Exception("Invalid 'q' parameter. Must be a non-empty string.");
$query = trim($query);
if (strlen($query) > 255) throw new Exception(
if (strlen($query) > 255) throw new \Exception(
"Invalid 'q' parameter. Exceeds maximum length of 255 characters."
);
if (!preg_match('/^[a-zA-Z0-9\s\-_\'"]+$/', $query)) throw new Exception(
if (!preg_match('/^[a-zA-Z0-9\s\-_\'"]+$/', $query)) throw new \Exception(
"Invalid 'q' parameter. Contains unsupported characters."
);