diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-03-30 23:40:33 +0100 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-03-30 23:40:33 +0100 |
commit | 6b796258d413f00e498ce7f80f73a9f6c061f29c (patch) | |
tree | 49e64a5dd4cde2acff7f0a93ed3f8e20e1cb2dc8 /includes/jobs/UpdateAssets.php | |
parent | 5860551daa0f60103ad24e93da29f401a653f144 (diff) | |
download | pluralconnect-6b796258d413f00e498ce7f80f73a9f6c061f29c.tar.gz pluralconnect-6b796258d413f00e498ce7f80f73a9f6c061f29c.tar.bz2 pluralconnect-6b796258d413f00e498ce7f80f73a9f6c061f29c.zip |
Updated 5 files, added 2 files, deleted 495 files and renamed 7 files (automated)
Diffstat (limited to 'includes/jobs/UpdateAssets.php')
-rw-r--r-- | includes/jobs/UpdateAssets.php | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/includes/jobs/UpdateAssets.php b/includes/jobs/UpdateAssets.php deleted file mode 100644 index 5c5c288..0000000 --- a/includes/jobs/UpdateAssets.php +++ /dev/null @@ -1,110 +0,0 @@ -<?php - -$options = json_decode($argv[1], true); -$_SERVER['DOCUMENT_ROOT'] = "../.."; -require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/composer/vendor/autoload.php'; -use ColorThief\ColorThief; - -echo("Loading...\n"); - -$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); - -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars"); -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners"); -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads"); -if (!file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies")) mkdir("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies"); - -function downloadAssets($system, $path = null) { - global $options; - - if (!isset($path)) { - $path = $system; - } - - $general = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$path/general.json"), true); - - if ($options["type"] === "system") { - echo("Download system assets\n"); - if (isset($general["avatar_url"])) { - $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]); - echo(" /avatars/$id.webp\n"); - file_put_contents("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION), file_get_contents($general['avatar_url'])); - exec("nice -n 19 convert -resize 512x512 \"" . "/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($general['avatar_url'], PATHINFO_EXTENSION)); - } - - if (isset($general["banner"])) { - $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]); - echo(" /banners/$id.webp\n"); - file_put_contents("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION), file_get_contents($general['banner'])); - exec("nice -n 19 convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION) ."\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($general['banner'], PATHINFO_EXTENSION)); - } - } - - $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$path/members.json"), true); - - foreach ($members as $member) { - $id = preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $general["uuid"]) . preg_replace("/^([\da-f]{8})-([\da-f]{4})-([\da-f]{4})-([\da-f]{4})-([\da-f]{12})$/", "$1$2$3$4$5", $member["uuid"]); - - if ($options["type"] === "members") { - echo("Downloading member assets (" . ($member["display_name"] ?? $member["name"]) . ", " . $member["id"] . ")\n"); - if (isset($member["avatar_url"])) { - echo(" /avatars/$id.webp\n"); - file_put_contents("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION), file_get_contents($member['avatar_url'])); - exec("nice -n 19 convert -resize 512x512 \"" . "/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/avatars/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($member['avatar_url'], PATHINFO_EXTENSION)); - } - - echo(" /banners/$id.webp\n"); - - if (isset($member["banner"])) { - file_put_contents("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION), file_get_contents($member['banner'])); - exec("nice -n 19 convert -resize 2048x2048 \"" . "/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION) . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp"); - unlink("/tmp/img." . pathinfo($member['banner'], PATHINFO_EXTENSION)); - } else { - $img = imagecreate(2048, 1024); - - if (isset($member["color"])) { - imagecolorallocate($img, hexdec(substr($member["color"], 0, 2)) / 2, hexdec(substr($member["color"], 2, 2)) / 2, hexdec(substr($member["color"], 4, 2)) / 2); - } else { - imagecolorallocate($img, 0, 0, 0); - } - - imagejpeg($img, "/tmp/img.jpeg", 100); - imagedestroy($img); - exec("nice -n 19 convert -resize 2048x2048 \"/tmp/img.jpeg\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/banners/" . $id . ".webp"); - unlink("/tmp/img.jpeg"); - } - } - - if ($options["type"] === "ponytown") { - echo("Downloading Pony Town assets (" . ($member["display_name"] ?? $member["name"]) . ", " . $member["id"] . ")\n"); - if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png")) { - $url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member["name"] . ".png"; - } else { - $url = "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt.png"; - } - echo(" /heads/$id.png\n"); - exec("nice -n 19 convert \"" . $url . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/heads/" . $id . ".png"); - - if (file_exists("" . $_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png")) { - echo(" /bodies/$id.png\n"); - exec("nice -n 19 convert \"" . "" . $_SERVER['DOCUMENT_ROOT'] . "/assets/ponies/" . $member["id"] . ".png" . "\" " . $_SERVER['DOCUMENT_ROOT'] . "/assets/bodies/" . $id . ".png"); - } - } - } -} - -echo("Downloading for gdapd\n"); -downloadAssets("gdapd"); - -echo("Downloading for hrbom\n"); -downloadAssets("hrbom"); - -if (isset($app["other"]) && isset($app["other"]["id"]) && isset($app["other"]["token"])) { - echo("Downloading for other\n"); - downloadAssets($app["other"]["id"], "other"); -} - -require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/maintenance/deleteUnusedAssets.php";
\ No newline at end of file |