summaryrefslogtreecommitdiff
path: root/api
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 /api
parent84dd0735820b16b60f600284d35183d76547a71f (diff)
downloadpluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.gz
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.tar.bz2
pluralconnect-a2df9a69dcc14cb70118cda2ded499055e7ee358.zip
m. update
Diffstat (limited to 'api')
-rw-r--r--api/app-images.php43
-rw-r--r--api/cloudburst-banners.php17
-rw-r--r--api/cloudburst-data.php44
-rw-r--r--api/cloudburst.php6
-rw-r--r--api/data.php12
-rw-r--r--api/me-picture.php23
-rw-r--r--api/me.php13
-rw-r--r--api/pluralkit-integration.php36
-rw-r--r--api/raindrops-banners.php17
-rw-r--r--api/raindrops-data.php44
-rw-r--r--api/raindrops.php6
-rw-r--r--api/save.php4
-rw-r--r--api/session.php6
-rw-r--r--api/test.php4
-rw-r--r--api/token.php7
-rw-r--r--api/video.php39
16 files changed, 319 insertions, 2 deletions
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 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+global $_PROFILE;
+
+$data = [
+ "ponytown" => [],
+ "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
diff --git a/api/cloudburst-banners.php b/api/cloudburst-banners.php
new file mode 100644
index 0000000..6e1d654
--- /dev/null
+++ b/api/cloudburst-banners.php
@@ -0,0 +1,17 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php";
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/banner.php";
+if (!$isLoggedIn) header("Location: /login") and die();
+
+$data = [];
+
+foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc-members.json"), true) as $member) {
+ if ($member['name'] === "unknown") continue;
+
+ $data[$member['name']] = getMemberBannerData($member['id'], "ynmuc");
+}
+
+header("Content-Type: application/json");
+die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file
diff --git a/api/cloudburst-data.php b/api/cloudburst-data.php
new file mode 100644
index 0000000..f1bab0b
--- /dev/null
+++ b/api/cloudburst-data.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php";
+if (!$isLoggedIn) header("Location: /login") and die();
+
+$data = [];
+$data["members"] = [];
+
+foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data"), function ($i) { return !str_starts_with($i, "."); }) as $file) {
+ if (str_starts_with($file, "ynmuc-") && !(str_ends_with($file, "-members.json") || str_ends_with($file, "-fronters.json") || str_ends_with($file, "-general.json") || str_ends_with($file, "-switches.json"))) {
+ $name = substr(explode(".", $file)[0], 6);
+ $parts = explode("-", $name);
+
+ if (explode(".", $file)[1] === "json") {
+ if (strlen($parts[0]) === 5) {
+ if (!isset($data["members"][$parts[0]])) $data["members"][$parts[0]] = [
+ "metadata" => null,
+ "content" => null
+ ];
+ if ($parts[1] === "metadata") {
+ $data["members"][$parts[0]][$parts[1]] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true));
+ } else {
+ $data["members"][$parts[0]][$parts[1]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true);
+ }
+ } else {
+ $data[$name] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true);
+ }
+ } else {
+ if (strlen($parts[0]) === 5) {
+ if (!isset($data["members"][$parts[0]])) $data["members"][$parts[0]] = [
+ "metadata" => null,
+ "content" => null
+ ];
+ $data["members"][$parts[0]][$parts[1]] = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file);
+ } else {
+ $data[$name] = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file);
+ }
+ }
+ }
+}
+
+header("Content-Type: application/json");
+die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file
diff --git a/api/cloudburst.php b/api/cloudburst.php
new file mode 100644
index 0000000..3002e00
--- /dev/null
+++ b/api/cloudburst.php
@@ -0,0 +1,6 @@
+<?php
+
+header("Content-Type: text/plain");
+
+$fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc-fronters.json"), true);
+echo($fronters['members'][0]['display_name'] ?? $fronters['members'][0]['name']); \ No newline at end of file
diff --git a/api/data.php b/api/data.php
new file mode 100644
index 0000000..7ede925
--- /dev/null
+++ b/api/data.php
@@ -0,0 +1,12 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php";
+if (!$isLoggedIn) header("Location: /login") and die();
+
+if (!isset($_GET['f']) || !file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $_GET['f'])) {
+ die();
+} else {
+ header("Content-Type: " . mime_content_type($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $_GET['f']));
+ die(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $_GET['f']));
+} \ No newline at end of file
diff --git a/api/me-picture.php b/api/me-picture.php
new file mode 100644
index 0000000..408b8c8
--- /dev/null
+++ b/api/me-picture.php
@@ -0,0 +1,23 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+global $_PROFILE;
+
+header("Content-Type: application/json");
+
+$fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($_PROFILE['name'] === "Cloudburst System" ? "ynmuc" : "gdapd") . "-fronters.json"), true);
+$member = $fronters["members"][0];
+
+if (isset($member["avatar_url"])) {
+ $tempfile = "/tmp/avatar-" . rand(0, 999999) . ".jpg";
+ file_put_contents($tempfile . "-original", file_get_contents($member["avatar_url"]));
+ exec("convert -resize 256x256 -quality 50 \"" . $tempfile . "-original" . "\" \"" . $tempfile . "\"", $output);
+
+ echo("data:image/jpg;base64," . base64_encode(file_get_contents($tempfile)));
+ //echo(implode("\n", $output));
+ unlink($tempfile . "-original");
+ unlink($tempfile);
+} else {
+ die();
+} \ No newline at end of file
diff --git a/api/me.php b/api/me.php
new file mode 100644
index 0000000..048bcd4
--- /dev/null
+++ b/api/me.php
@@ -0,0 +1,13 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+global $_PROFILE;
+
+header("Content-Type: application/json");
+
+if ($_PROFILE['name'] === "Cloudburst System") {
+ die('{"name": "Cloudburst System", "id": "cloudburst", "pluralkit": "ynmuc"}');
+} else {
+ die('{"name": "Raindrops System", "id": "raindrops", "pluralkit": "gdapd"}');
+}
diff --git a/api/pluralkit-integration.php b/api/pluralkit-integration.php
new file mode 100644
index 0000000..d3f7e45
--- /dev/null
+++ b/api/pluralkit-integration.php
@@ -0,0 +1,36 @@
+<?php
+
+$user = $_GET['user'] ?? null;
+$inputJSON = file_get_contents('php://input');
+$input = json_decode($inputJSON, true);
+$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true)["webhook"];
+
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data.json", json_encode($input, JSON_PRETTY_PRINT));
+
+if ($user === null) {
+ header("HTTP/1.1 500 Internal Server Error") and die();
+}
+
+if (!in_array($user, array_keys($data))) {
+ header("HTTP/1.1 404 Not Found") and die();
+}
+
+if ($input["signing_token"] !== $data[$user]) {
+ header("HTTP/1.1 401 Unauthorized") and die();
+}
+
+if ($input['system_id'] === "7d9f543e-f742-40f6-9d07-86c3f2983124") {
+ $system = "gdapd";
+} else {
+ $system = "ynmuc";
+}
+
+if ($input["type"] === "CREATE_SWITCH" || $input["type"] === "UPDATE_SWITCH" || $input["type"] === "DELETE_SWITCH") {
+ usleep(550000);
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-fronters.json", file_get_contents("https://api.pluralkit.me/v2/systems/$input[system_id]/fronters"));
+ usleep(550000);
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-switches.json", file_get_contents("https://api.pluralkit.me/v2/systems/$input[system_id]/switches"));
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data.json-res", "affected: " . $input["type"] . " (" . gettype($input["type"]) . ")") and die();
+} else {
+ file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data.json-res", "invalid method: " . $input["type"] . " (" . gettype($input["type"]) . ")") and die();
+} \ No newline at end of file
diff --git a/api/raindrops-banners.php b/api/raindrops-banners.php
new file mode 100644
index 0000000..700786b
--- /dev/null
+++ b/api/raindrops-banners.php
@@ -0,0 +1,17 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php";
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/banner.php";
+if (!$isLoggedIn) header("Location: /login") and die();
+
+$data = [];
+
+foreach (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd-members.json"), true) as $member) {
+ if ($member['name'] === "unknown") continue;
+
+ $data[$member['name']] = getMemberBannerData($member['id'], "gdapd");
+}
+
+header("Content-Type: application/json");
+die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file
diff --git a/api/raindrops-data.php b/api/raindrops-data.php
new file mode 100644
index 0000000..6af9233
--- /dev/null
+++ b/api/raindrops-data.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.php";
+if (!$isLoggedIn) header("Location: /login") and die();
+
+$data = [];
+$data["members"] = [];
+
+foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data"), function ($i) { return !str_starts_with($i, "."); }) as $file) {
+ if (str_starts_with($file, "gdapd-") && !(str_ends_with($file, "-members.json") || str_ends_with($file, "-fronters.json") || str_ends_with($file, "-general.json") || str_ends_with($file, "-switches.json"))) {
+ $name = substr(explode(".", $file)[0], 6);
+ $parts = explode("-", $name);
+
+ if (explode(".", $file)[1] === "json") {
+ if (strlen($parts[0]) === 5) {
+ if (!isset($data["members"][$parts[0]])) $data["members"][$parts[0]] = [
+ "metadata" => null,
+ "content" => null
+ ];
+ if ($parts[1] === "metadata") {
+ $data["members"][$parts[0]][$parts[1]] = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true));
+ } else {
+ $data["members"][$parts[0]][$parts[1]] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true);
+ }
+ } else {
+ $data[$name] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file), true);
+ }
+ } else {
+ if (strlen($parts[0]) === 5) {
+ if (!isset($data["members"][$parts[0]])) $data["members"][$parts[0]] = [
+ "metadata" => null,
+ "content" => null
+ ];
+ $data["members"][$parts[0]][$parts[1]] = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file);
+ } else {
+ $data[$name] = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $file);
+ }
+ }
+ }
+}
+
+header("Content-Type: application/json");
+die(json_encode($data, JSON_PRETTY_PRINT)); \ No newline at end of file
diff --git a/api/raindrops.php b/api/raindrops.php
new file mode 100644
index 0000000..9f07aff
--- /dev/null
+++ b/api/raindrops.php
@@ -0,0 +1,6 @@
+<?php
+
+header("Content-Type: text/plain");
+
+$fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd-fronters.json"), true);
+echo($fronters['members'][0]['display_name'] ?? $fronters['members'][0]['name']); \ No newline at end of file
diff --git a/api/save.php b/api/save.php
index ef8a07d..a54a02a 100644
--- a/api/save.php
+++ b/api/save.php
@@ -24,12 +24,12 @@ if (!isset($content))
header("Location: /?error=No content") and die();
if ($member !== null && $member !== "null") {
- $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-" . $member . "-disclaimers.html";
+ $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-" . $member . "-content.html";
} else {
if ($subsystem !== null && $subsystem !== "null") {
$file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-subsystem-" . $subsystem . ".html";
} else {
- $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-disclaimers.html";
+ $file = $_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $system . "-content.html";
}
}
diff --git a/api/session.php b/api/session.php
new file mode 100644
index 0000000..3cf7cff
--- /dev/null
+++ b/api/session.php
@@ -0,0 +1,6 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+
+header("Content-Type: text/plain");
+die($isLoggedIn ? "VALID" : "ERROR"); \ No newline at end of file
diff --git a/api/test.php b/api/test.php
new file mode 100644
index 0000000..627c0e1
--- /dev/null
+++ b/api/test.php
@@ -0,0 +1,4 @@
+<?php
+
+header("Content-Type: text/plain");
+die("SUCCESS"); \ No newline at end of file
diff --git a/api/token.php b/api/token.php
new file mode 100644
index 0000000..81fe3d0
--- /dev/null
+++ b/api/token.php
@@ -0,0 +1,7 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+
+header("Content-Type: text/plain");
+die($_COOKIE['PEH2_SESSION_TOKEN']); \ No newline at end of file
diff --git a/api/video.php b/api/video.php
new file mode 100644
index 0000000..7ac32a1
--- /dev/null
+++ b/api/video.php
@@ -0,0 +1,39 @@
+<?php
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
+if (!$isLoggedIn) header("Location: /login") and die();
+
+if (isset($_GET['id'])) {
+ header("Content-Type: application/json");
+ $data = json_decode(exec("yt-dlp -q -x --no-playlist --skip-download --dump-json \"https://www.youtube.com/watch?v=" . str_replace('"', '\'', $_GET['id']) . "\""), true);
+ $qualities = array_values(array_filter(array_map(function ($i) {
+ return [
+ "quality" => $i["height"],
+ "id" => $i['format_id']
+ ];
+ }, $data["formats"]), function ($i) {
+ return !is_null($i["quality"]);
+ }));
+ $hd = array_values(array_filter($qualities, function ($i) {
+ return $i["quality"] >= 720;
+ }));
+ $selected = count($hd) > 0 ? $hd[0] : $qualities[count($qualities) - 1];
+ $stream = array_values(array_filter($data["formats"], function ($i) use ($selected) {
+ return $i["height"] === $selected["quality"] && $i["acodec"] !== null && $i["acodec"] !== "none";
+ }))[0];
+
+ echo(json_encode([
+ "title" => $data["fulltitle"],
+ "author" => $data["channel"],
+ "count" => [
+ "channel" => $data["channel_follower_count"],
+ "likes" => $data["like_count"],
+ "views" => $data["view_count"]
+ ],
+ "duration" => $data["duration"],
+ "stream" => $selected,
+ "url" => $stream["url"],
+ "duration_pretty" => $stream["duration_string"],
+ "poster" => $data["thumbnail"],
+ ], JSON_PRETTY_PRINT));
+} \ No newline at end of file