summaryrefslogtreecommitdiff
path: root/includes/refresh.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
committerMinteck <contact@minteck.org>2022-08-21 17:31:56 +0200
commita2df9a69dcc14cb70118cda2ded499055e7ee358 (patch)
tree6dd283e4e9452d38bce81ddaaae49b5335755842 /includes/refresh.php
parent84dd0735820b16b60f600284d35183d76547a71f (diff)
downloadpluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.gz
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.bz2
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.zip
m. update
Diffstat (limited to 'includes/refresh.php')
-rw-r--r--includes/refresh.php90
1 files changed, 87 insertions, 3 deletions
diff --git a/includes/refresh.php b/includes/refresh.php
index c29136f..83745fb 100644
--- a/includes/refresh.php
+++ b/includes/refresh.php
@@ -1,35 +1,119 @@
<?php
-$start = time();
+$start = microtime(true);
@mkdir("./data");
+$files = [];
+$restored = [];
+$times = [];
+
+$currentOpStart = microtime(true);
+foreach (array_filter(scandir("./data"), function ($i) {
+ return !str_starts_with($i, ".") && $i !== "backup" && is_file("./data/" . $i);
+}) as $file) {
+ $files[] = $file;
+}
+
+@mkdir("./data/backup");
+foreach ($files as $file) {
+ copy("./data/" . $file, "./data/backup/" . $file);
+}
+
function getSystem(string $id) {
+ global $times;
echo("System: $id\n");
echo(" Base system info\n");
+ $currentOpStart = microtime(true);
file_put_contents("./data/$id-general.json", file_get_contents("https://api.pluralkit.me/v2/systems/$id"));
sleep(1);
+ $times["system-general-$id"] = microtime(true) - $currentOpStart;
echo(" System members\n");
+ $currentOpStart = microtime(true);
file_put_contents("./data/$id-members.json", file_get_contents("https://api.pluralkit.me/v2/systems/$id/members"));
sleep(1);
+ $times["system-members-$id"] = microtime(true) - $currentOpStart;
echo(" Fronters\n");
+ $currentOpStart = microtime(true);
file_put_contents("./data/$id-fronters.json", file_get_contents("https://api.pluralkit.me/v2/systems/$id/fronters"));
sleep(1);
+ $times["system-fronters-$id"] = microtime(true) - $currentOpStart;
echo(" Switches\n");
+ $currentOpStart = microtime(true);
file_put_contents("./data/$id-switches.json", file_get_contents("https://api.pluralkit.me/v2/systems/$id/switches"));
sleep(1);
+ $times["system-switches-$id"] = microtime(true) - $currentOpStart;
}
getSystem("gdapd"); // Raindrops
getSystem("ynmuc"); // Cloudburst
-$time = (time() - $start);
+echo("Downloading images.\n");
+if (!file_exists("./data/images")) mkdir("./data/images");
+
+$currentOpStart = microtime(true);
+foreach (json_decode(file_get_contents("./data/gdapd-members.json"), true) as $member) {
+ $currentOpStart2 = microtime(true);
+ echo(" " . $member['id'] . "\n");
+
+ if (isset($member['avatar_url'])) {
+ echo(" Profile picture\n");
+ exec("convert -resize 128x128 -quality 50 \"" . $member['avatar_url'] . "\" \"./data/images/pf-gdapd-" . $member['id'] . ".webp\"");
+ }
+
+ echo(" Pony Town character\n");
+ if (file_exists("../assets/uploads/pt-" . $member['name'] . ".png")) {
+ exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt-" . $member['name'] . ".png\" \"./data/images/pt-gdapd-" . $member['id'] . ".png\"");
+ } else {
+ exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt.png\" \"./data/images/pt-gdapd-" . $member['id'] . ".png\"");
+ }
+ $times["images-gdapd-" . $member['id']] = microtime(true) - $currentOpStart2;
+}
+$times["images-gdapd"] = microtime(true) - $currentOpStart;
+
+$currentOpStart = microtime(true);
+foreach (json_decode(file_get_contents("./data/ynmuc-members.json"), true) as $member) {
+ $currentOpStart2 = microtime(true);
+ echo(" " . $member['id'] . "\n");
+
+ if (isset($member['avatar_url'])) {
+ echo(" Profile picture\n");
+ exec("convert -resize 128x128 -quality 50 \"" . $member['avatar_url'] . "\" \"./data/images/pf-ynmuc-" . $member['id'] . ".webp\"");
+ }
+
+ echo(" Pony Town character\n");
+ if (file_exists("../assets/uploads/pt-" . $member['name'] . ".png")) {
+ exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt-" . $member['name'] . ".png\" \"./data/images/pt-ynmuc-" . $member['id'] . ".png\"");
+ } else {
+ exec("convert -resize 64x64 -quality 50 \"../assets/uploads/pt.png\" \"./data/images/pt-ynmuc-" . $member['id'] . ".png\"");
+ }
+ $times["images-ynmuc-" . $member['id']] = microtime(true) - $currentOpStart2;
+}
+$times["images-ynmuc"] = microtime(true) - $currentOpStart;
+
+$currentOpStart = microtime(true);
+function isJson($string): bool {
+ json_decode($string);
+ return (json_last_error() === JSON_ERROR_NONE);
+}
+
+foreach ($files as $file) {
+ if (trim(file_get_contents("./data/" . $file)) === "" || (isJson(trim(file_get_contents("./data/" . $file))) && isset(json_decode(trim(file_get_contents("./data/" . $file)), true)["message"]))) {
+ $restored[] = $file;
+ copy("./data/backup/" . $file, "./data/" . $file);
+ }
+}
+$times["restore"] = microtime(true) - $currentOpStart;
+
+$time = (microtime(true) - $start);
echo("Completed in " . $time . " seconds.\n");
file_put_contents("./data/refresh.json", json_encode([
"timestamp" => time(),
- "duration" => $time
+ "duration" => $time,
+ "restored" => $restored,
+ "times" => $times
])); \ No newline at end of file