summaryrefslogtreecommitdiff
path: root/includes/refresh.php
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-03-27 22:22:53 +0200
committerRaindropsSys <contact@minteck.org>2023-03-27 22:22:53 +0200
commite98e95d89939cdc1252d02df04ae8d91c6aa8c92 (patch)
treea5d5535f8058f1a7b45a31a1caf36ab7e24ff19d /includes/refresh.php
parent6ab243c12f2514cd0f40e80504223664755a6da4 (diff)
downloadpluralconnect-e98e95d89939cdc1252d02df04ae8d91c6aa8c92.tar.gz
pluralconnect-e98e95d89939cdc1252d02df04ae8d91c6aa8c92.tar.bz2
pluralconnect-e98e95d89939cdc1252d02df04ae8d91c6aa8c92.zip
Updated 9 files, added 9 files, deleted 3 files and renamed includes/refresh/logo.inc (automated)
Diffstat (limited to 'includes/refresh.php')
-rw-r--r--includes/refresh.php224
1 files changed, 24 insertions, 200 deletions
diff --git a/includes/refresh.php b/includes/refresh.php
index 77b51ff..9abe297 100644
--- a/includes/refresh.php
+++ b/includes/refresh.php
@@ -3,51 +3,11 @@
require_once './composer/vendor/autoload.php';
$_SERVER['DOCUMENT_ROOT'] = "..";
-use ColorThief\ColorThief;
-
$app = json_decode(file_get_contents("./app.json"), true);
-$start = microtime(true);
@mkdir("./data");
-$files = [];
-$restored = [];
-$times = [];
-
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/calendar.ics", file_get_contents($app["calendar"]));
-$currentOpStart = microtime(true);
-//file_put_contents("./data/actions/" . date('Y-m-d_H-i-s') . ".json", @file_get_contents("./data/actions/actions.json"));
-//file_put_contents("./data/toys/" . date('Y-m-d_H-i-s') . ".json", @file_get_contents("./data/toys/toys.json"));
-
-//exec('bash -c "cd /nas/web/ponies.equestria.horse/includes/data; ls -tp toys/20* | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"');
-//exec('bash -c "cd /nas/web/ponies.equestria.horse/includes/data; ls -tp actions/20* | grep -v \'/$\' | tail -n +20 | xargs -I {} rm -- {}"');
-
-$times["important_backup"] = microtime(true) - $currentOpStart;
-
-$currentOpStart = microtime(true);
-$documents = array_map(function ($i) {
- return [
- "id" => substr($i, 0, -5),
- ...(json_decode(file_get_contents("./data/docs/" . $i), true) ?? [])
- ];
-}, array_filter(scandir("./data/docs"), function ($i) {
- return !str_starts_with($i, ".") && str_ends_with($i, ".json");
-}));
-
-$deletable = array_values(array_filter($documents, function ($i) {
- return str_starts_with(strip_tags($i["contents"]), "/delete");
-}));
-
-foreach ($deletable as $item) {
- if (time() - $item["last"]["date"] > 86400) {
- unlink("./data/docs/" . $item["id"] . ".json");
- }
-}
-$times["docs_cleanup"] = microtime(true) - $currentOpStart;
-
-require_once "./refresh/cleanup.inc";
-
-$currentOpStart = microtime(true);
$version = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/version.json"), true);
$ignore = [
@@ -62,6 +22,29 @@ $ignore = [
$_SERVER['DOCUMENT_ROOT'] . "/assets",
];
+$screens = array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens"), function ($i) {
+ return !str_starts_with($i, ".");
+}));
+
+$computers = array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata"), function ($i) {
+ return !str_starts_with($i, ".");
+}));
+
+foreach ($screens as $screen) {
+ $delete = true;
+ $id = explode(".", explode("-", $screen)[2])[0];
+
+ foreach ($computers as $file) {
+ $computer = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/metadata/" . $file), true);
+
+ foreach ($computer["screens"] as $sel) {
+ if ($sel["id"] === $id) $delete = false;
+ }
+ }
+
+ if ($delete) unlink($_SERVER['DOCUMENT_ROOT'] . "/includes/data/computers/screens/" . $screen);
+}
+
function rscandir($dir) {
global $ignore;
$files = [];
@@ -109,139 +92,6 @@ if ($versionHash[0] !== $version["hash"]) {
}
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/version.json", json_encode($version));
-$times["version"] = microtime(true) - $currentOpStart;
-
-function getSystem(string $id, string $fileName = null, string $token = null) {
- global $times;
-
- if (!isset($fileName)) {
- $fileName = $id;
- }
-
- if (isset($token)) {
- $ctx = stream_context_create([
- 'http' => [
- 'method' => 'GET',
- 'header' =>
- "Authorization: " . $token . "\r\n"
- ]
- ]);
- } else {
- $ctx = stream_context_create([
- 'http' => [
- 'method' => 'GET'
- ]
- ]);
- }
-
- echo("System: $id\n");
-
- echo(" Base system info\n");
- $currentOpStart = microtime(true);
- $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id", false, $ctx);
-
- if (trim($data) !== "" && $data !== false) {
- file_put_contents("./data/$fileName/general.json", $data);
- }
- $times["system-general-" . md5($id)] = microtime(true) - $currentOpStart;
-
- echo(" System members\n");
- $currentOpStart = microtime(true);
- $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/members", false, $ctx);
-
- if (trim($data) !== "" && $data !== false) {
- $parsed = json_decode($data, true);
-
- foreach ($parsed as $index => $member) {
- if (isset($member["avatar_url"])) {
- $dominantColor = substr(ColorThief::getColor($member["avatar_url"], outputFormat: "hex"), 1);
- } else {
- $dominantColor = "ffffff";
- }
-
- $parsed[$index]["dominant_color"] = $dominantColor;
-
- if (!isset($member["color"])) {
- $parsed[$index]["color"] = $dominantColor;
- }
- }
-
- $data = json_encode($parsed, JSON_PRETTY_PRINT);
- file_put_contents("./data/$fileName/members.json", $data);
- }
- $times["system-members-" . md5($id)] = microtime(true) - $currentOpStart;
-
- echo(" Fronters\n");
- $data = file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/fronters", false, $ctx);
-
- if (trim($data) !== "" && $data !== false) {
- file_put_contents("./data/$fileName/fronters.json", $data);
- }
- $times["system-fronters-" . md5($id)] = microtime(true) - $currentOpStart;
-
- echo(" Switches\n");
- $currentOpStart = microtime(true);
-
- echo(" Part 1/6\n");
- $switches1 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches", false, $ctx), true);
-
- if (count($switches1) > 0) {
- $oldest = $switches1[count($switches1) - 1]["timestamp"];
-
- echo(" Part 2/6\n");
- $switches2 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true);
-
- if (count($switches2) > 0) {
- $oldest = $switches2[count($switches2) - 1]["timestamp"];
-
- echo(" Part 3/6\n");
- $switches3 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true);
-
- if (count($switches3) > 0) {
- $oldest = $switches3[count($switches3) - 1]["timestamp"];
-
- echo(" Part 4/6\n");
- $switches4 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true);
-
- if (count($switches4) > 0) {
- $oldest = $switches4[count($switches4) - 1]["timestamp"];
-
- echo(" Part 5/6\n");
- $switches5 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true);
-
- if (count($switches5) > 0) {
- $oldest = $switches5[count($switches5) - 1]["timestamp"];
-
- echo(" Part 6/6\n");
- $switches6 = json_decode(file_get_contents("https://pluralkit.equestria.dev/v2/systems/$id/switches?before=$oldest", false, $ctx), true);
- } else {
- $switches6 = [];
- }
- } else {
- $switches5 = $switches6 = [];
- }
- } else {
- $switches4 = $switches5 = $switches6 = [];
- }
- } else {
- $switches3 = $switches4 = $switches5 = $switches6 = [];
- }
- } else {
- $switches2 = $switches3 = $switches4 = $switches5 = $switches6 = [];
- }
-
- if ($switches1 !== null && $switches2 !== null && $switches3 !== null && $switches4 !== null && $switches5 !== null && $switches6 !== null) {
- file_put_contents("./data/$fileName/switches.json", json_encode([...$switches1, ...$switches2, ...$switches3, ...$switches4, ...$switches5, ...$switches6], JSON_PRETTY_PRINT));
- $times["system-switches-" . md5($id)] = microtime(true) - $currentOpStart;
- }
-}
-
-getSystem("gdapd"); // Raindrops
-getSystem("ynmuc"); // Cloudburst
-
-if (isset($app["other"]) && isset($app["other"]["id"]) && isset($app["other"]["token"])) {
- getSystem($app["other"]["id"], "other", $app["other"]["token"]);
-}
if (!is_link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"])) {
link($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other", $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $app["other"]["id"]);
@@ -259,39 +109,13 @@ if (time() - $lastBackup >= 3600) {
echo("Backup skipped\n");
}
-echo("Generating logo...\n");
-
-$currentOpStart = microtime(true);
-require_once "./refresh/logo.inc";
-$times["logo"] = microtime(true) - $currentOpStart;
-
-echo("Generated logo\n");
-
echo("Fetching school information...\n");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/school.json", "{}");
-$currentOpStart = microtime(true);
chdir("./external/school");
exec("node index.js");
chdir("../..");
-$times["school"] = microtime(true) - $currentOpStart;
echo("Fetched school information\n");
-echo("Downloading assets...\n");
-
-$currentOpStart = microtime(true);
-require_once "./refresh/assets.inc";
-$times["assets"] = microtime(true) - $currentOpStart;
-
-echo("Downloading assets\n");
-
-$time = array_sum($times);
-echo("Completed in " . $time . " seconds.\n");
-
-file_put_contents("./data/refresh.json", json_encode([
- "timestamp" => microtime(true),
- "duration" => $time,
- "restored" => $restored,
- "times" => $times
-])); \ No newline at end of file
+echo("Completed.\n"); \ No newline at end of file