From a2df9a69dcc14cb70118cda2ded499055e7ee358 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 21 Aug 2022 17:31:56 +0200 Subject: m. update --- api/app-images.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 api/app-images.php (limited to 'api/app-images.php') diff --git a/api/app-images.php b/api/app-images.php new file mode 100644 index 0000000..edab3c9 --- /dev/null +++ b/api/app-images.php @@ -0,0 +1,43 @@ + [], + "profile" => [], + "misc" => [] +]; + +$data["misc"]["systems"] = [ + "cloudburst.png" => "data:image/png;base64," . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/cloudburst.png")), + "raindrops.png" => "data:image/png;base64," . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/raindrops.png")) +]; + +foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads"), function ($i) { return str_starts_with($i, "ss-") && str_ends_with($i, ".png"); }) as $file) { + $data["misc"]["systems"][$file] = "data:image/png;base64," . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/" . $file)); +} + +$data["misc"]["species"] = []; + +foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/assets/species"), function ($i) { return !str_starts_with($i, "."); }) as $file) { + $name = substr($file, 0, strlen($file) - 4); + $data["misc"]["species"][$name] = "data:" . mime_content_type($_SERVER['DOCUMENT_ROOT'] . "/assets/species/" . $file) . ";base64," . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/assets/species/" . $file)); +} + +foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/images"), function ($i) { return !str_starts_with($i, "."); }) as $file) { + $name = explode(".", $file)[0]; + $parts = explode("-", $name); + $type = mime_content_type($_SERVER['DOCUMENT_ROOT'] . "/includes/data/images/" . $file); + $category = match ($parts[0]) { + "pt" => "ponytown", + "pf" => "profile" + }; + + if (!isset($data[$category][$parts[1]])) $data[$category][$parts[1]] = []; + $data[$category][$parts[1]][$parts[2]] = "data:" . $type . ";base64," . base64_encode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/images/" . $file)); +} + +header("Content-Type: application/json"); +die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file -- cgit