chore(query.php): rename proxy endpoint to query to better reflect how it's used
This commit is contained in:
parent
92a3730e61
commit
aa33cd72df
4 changed files with 42 additions and 34 deletions
|
@ -5,7 +5,7 @@ use App\Classes\BaseHandler;
|
||||||
require __DIR__ . '/../server/utils/init.php';
|
require __DIR__ . '/../server/utils/init.php';
|
||||||
require __DIR__ . "/Classes/BaseHandler.php";
|
require __DIR__ . "/Classes/BaseHandler.php";
|
||||||
|
|
||||||
class ProxyHandler extends BaseHandler
|
class QueryHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -55,23 +55,13 @@ class ProxyHandler extends BaseHandler
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->fetchFromApi($data, $query);
|
$response = $this->fetchFromApi($data, $query);
|
||||||
$markdownFields = $_GET['markdown'] ?? [];
|
$markdownFields = $this->getMarkdownFieldsFromQuery();
|
||||||
$markdownFields = is_array($markdownFields)
|
|
||||||
? $markdownFields
|
|
||||||
: explode(',', $markdownFields);
|
|
||||||
$markdownFields = array_map('trim', array_filter($markdownFields));
|
|
||||||
|
|
||||||
if (!empty($response) && !empty($markdownFields)) {
|
if (!empty($response) && !empty($markdownFields)) $response = $this->parseMarkdownFields($response, $markdownFields);
|
||||||
foreach ($markdownFields as $field) {
|
|
||||||
if (!empty($response[0][$field])) $response[0]["{$field}_html"] = parseMarkdown($response[0][$field]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$json = json_encode($response);
|
$json = json_encode($response);
|
||||||
|
|
||||||
if ($this->cache) {
|
if ($this->cache) $this->cache->setex($cacheKey, $cacheDuration, $json);
|
||||||
$this->cache->setex($cacheKey, $cacheDuration, $json);
|
|
||||||
}
|
|
||||||
|
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
echo $json;
|
echo $json;
|
||||||
|
@ -84,7 +74,25 @@ class ProxyHandler extends BaseHandler
|
||||||
{
|
{
|
||||||
return "proxy_{$data}" . ($id ? "_{$id}" : "");
|
return "proxy_{$data}" . ($id ? "_{$id}" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getMarkdownFieldsFromQuery(): array {
|
||||||
|
$fields = $_GET['markdown'] ?? [];
|
||||||
|
|
||||||
|
if (!is_array($fields)) $fields = explode(',', $fields);
|
||||||
|
|
||||||
|
return array_map('trim', array_filter($fields));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseMarkdownFields(array $data, array $fields): array {
|
||||||
|
foreach ($data as &$item) {
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if (!empty($item[$field])) $item["{$field}_html"] = parseMarkdown($item[$field]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$handler = new ProxyHandler();
|
$handler = new QueryHandler();
|
||||||
$handler->handleRequest();
|
$handler->handleRequest();
|
34
package-lock.json
generated
34
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "3.4.2",
|
"version": "3.4.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "3.4.2",
|
"version": "3.4.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"html-minifier-terser": "7.2.0",
|
"html-minifier-terser": "7.2.0",
|
||||||
|
@ -378,9 +378,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@asamuzakjp/css-color": {
|
"node_modules/@asamuzakjp/css-color": {
|
||||||
"version": "3.1.5",
|
"version": "3.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.1.7.tgz",
|
||||||
"integrity": "sha512-w7AmVyTTiU41fNLsFDf+gA2Dwtbx2EJtn2pbJNAGSRAg50loXy1uLXA3hEpD8+eydcomTurw09tq5/AyceCaGg==",
|
"integrity": "sha512-Ok5fYhtwdyJQmU1PpEv6Si7Y+A4cYb8yNM9oiIJC9TzXPMuN9fvdonKJqcnz9TbFqV6bQ8z0giRq0iaOpGZV2g==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -983,9 +983,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/browserslist": {
|
"node_modules/browserslist": {
|
||||||
"version": "4.24.4",
|
"version": "4.24.5",
|
||||||
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.4.tgz",
|
"resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.5.tgz",
|
||||||
"integrity": "sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A==",
|
"integrity": "sha512-FDToo4Wo82hIdgc1CQ+NQD0hEhmpPjrZ3hiUgwgOG6IuTdlpr8jdjyG24P6cNP1yJpTLzS5OcGgSw0xmDU1/Tw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
@ -1003,10 +1003,10 @@
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"caniuse-lite": "^1.0.30001688",
|
"caniuse-lite": "^1.0.30001716",
|
||||||
"electron-to-chromium": "^1.5.73",
|
"electron-to-chromium": "^1.5.149",
|
||||||
"node-releases": "^2.0.19",
|
"node-releases": "^2.0.19",
|
||||||
"update-browserslist-db": "^1.1.1"
|
"update-browserslist-db": "^1.1.3"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"browserslist": "cli.js"
|
"browserslist": "cli.js"
|
||||||
|
@ -1805,9 +1805,9 @@
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/electron-to-chromium": {
|
"node_modules/electron-to-chromium": {
|
||||||
"version": "1.5.148",
|
"version": "1.5.149",
|
||||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.148.tgz",
|
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.149.tgz",
|
||||||
"integrity": "sha512-8uc1QXwwqayD4mblcsQYZqoi+cOc97A2XmKSBOIRbEAvbp6vrqmSYs4dHD2qVygUgn7Mi0qdKgPaJ9WC8cv63A==",
|
"integrity": "sha512-UyiO82eb9dVOx8YO3ajDf9jz2kKyt98DEITRdeLPstOEuTlLzDA4Gyq5K9he71TQziU5jUVu2OAu5N48HmQiyQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
@ -4975,9 +4975,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.18.1",
|
"version": "8.18.2",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.1.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.2.tgz",
|
||||||
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
|
"integrity": "sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "3.4.2",
|
"version": "3.4.3",
|
||||||
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
"description": "The source for my personal site. Built using 11ty (and other tools).",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -18,7 +18,7 @@ window.addEventListener("load", () => {
|
||||||
if (isDynamic && !isLoaded) {
|
if (isDynamic && !isLoaded) {
|
||||||
const markdownFields = dialog.dataset.markdown || "";
|
const markdownFields = dialog.dataset.markdown || "";
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/proxy.php?data=${isDynamic}&id=${dialogId}&markdown=${encodeURIComponent(markdownFields)}`);
|
const res = await fetch(`/api/query.php?data=${isDynamic}&id=${dialogId}&markdown=${encodeURIComponent(markdownFields)}`);
|
||||||
const [data] = await res.json();
|
const [data] = await res.json();
|
||||||
const firstField = markdownFields.split(",")[0]?.trim();
|
const firstField = markdownFields.split(",")[0]?.trim();
|
||||||
const html = data?.[`${firstField}_html`] || "<p>No notes available.</p>";
|
const html = data?.[`${firstField}_html`] || "<p>No notes available.</p>";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue