From 59b56c2283c12c8a82144a836faee4f12b15e5c1 Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Thu, 27 Apr 2023 13:32:25 +0200 Subject: Updated 5 files and deleted 2 files (automated) --- includes/external/jobs/index.js | 26 +++-- includes/external/matrix/index.js | 40 ++++++- includes/fragments/metadata.inc | 228 ++++++++++++++++++++++++++++++++++---- includes/util/functions.inc | 6 +- pages/api/plex-thumb.php | 11 -- pages/api/plex.php | 88 --------------- pages/jobs.inc | 11 ++ 7 files changed, 271 insertions(+), 139 deletions(-) delete mode 100644 pages/api/plex-thumb.php delete mode 100644 pages/api/plex.php diff --git a/includes/external/jobs/index.js b/includes/external/jobs/index.js index 39b7de5..0f44cc9 100644 --- a/includes/external/jobs/index.js +++ b/includes/external/jobs/index.js @@ -1,13 +1,21 @@ const fs = require('fs'); const child_process = require('child_process'); -let jobs = require('../../data/jobs.json'); +let jobsList = []; +let jobs = []; let history = require('../../data/history.json'); +fs.writeFileSync("../../data/running.json", "null"); + setInterval(() => { - if (JSON.stringify(JSON.parse(fs.readFileSync("../../data/jobs.json").toString())) !== JSON.stringify(jobs)) { + if (JSON.stringify(fs.readdirSync("../../data/jobs")) !== JSON.stringify(jobsList)) { console.log("Updating the jobs list..."); - jobs = JSON.parse(fs.readFileSync("../../data/jobs.json").toString()); + jobs = fs.readdirSync("../../data/jobs").map((i) => { + let obj = JSON.parse(fs.readFileSync("../../data/jobs/" + i).toString()); + obj["_id"] = i; + return obj; + }); + jobsList = fs.readdirSync("../../data/jobs"); } }, 1000); @@ -20,11 +28,13 @@ setTimeout(() => { console.log("\nRunning jobs:"); for (let job of jobs) { - console.log(" " + job.name); + console.log(" " + job.name + " [" + job._id + "]"); let output; let start; let end; + fs.writeFileSync("../../data/running.json", JSON.stringify(job._id)); + try { start = new Date(); output = child_process.execFileSync("php", [job.name + ".php", JSON.stringify(job.options)], { cwd: "../../jobs" }); @@ -37,8 +47,7 @@ setTimeout(() => { description = "," + name + "=" + JSON.stringify(job.options[name]); } - jobs.splice(jobs.indexOf(job), 1); - fs.writeFileSync("../../data/jobs.json", JSON.stringify(jobs)); + fs.unlinkSync("../../data/jobs/" + job._id); history.unshift({ completed: true, @@ -58,6 +67,7 @@ setTimeout(() => { history = history.slice(0, 200); fs.writeFileSync("../../data/history.json", JSON.stringify(history)); + fs.writeFileSync("../../data/running.json", "null"); } catch (e) { end = start ? new Date() : null; console.log(" Failed to process job"); @@ -70,8 +80,7 @@ setTimeout(() => { description = "," + name + "=" + JSON.stringify(job.options[name]); } - jobs.splice(jobs.indexOf(job), 1); - fs.writeFileSync("../../data/jobs.json", JSON.stringify(jobs)); + fs.unlinkSync("../../data/jobs/" + job._id); history.unshift({ completed: false, @@ -91,6 +100,7 @@ setTimeout(() => { history = history.slice(0, 200); fs.writeFileSync("../../data/history.json", JSON.stringify(history)); + fs.writeFileSync("../../data/running.json", "null"); } } diff --git a/includes/external/matrix/index.js b/includes/external/matrix/index.js index 5149005..1bfb8d4 100644 --- a/includes/external/matrix/index.js +++ b/includes/external/matrix/index.js @@ -1,5 +1,6 @@ const user = process.argv[2]; const info = require('../../app.json')['matrix'][user]; +const fs = require('fs'); if (typeof info !== "object") throw new Error("Unable to find info"); @@ -7,6 +8,7 @@ const token = info.token; const sdk = require("matrix-js-sdk"); const axios = require("axios"); +const child_process = require("child_process"); const client = sdk.createClient({ baseUrl: "https://chat.equestria.dev", accessToken: token, @@ -24,13 +26,16 @@ client.once("sync", async function (state, prevState, res) { console.log(fronters.members.length + " member(s) at front"); let name = system.name; - let avatar = system.avatar_url; + let avatar1 = system.avatar_url; + let avatar2 = null; - if (fronters.members.length === 1) { + if (fronters.members.length === 1 || (fronters.members.length === 2 && (fronters.members[0].name === "scootaloo" && fronters.members[1].name === "rainbowdash"))) { name = fronters.members[0].display_name ?? fronters.members[0].name; - avatar = fronters.members[0].avatar_url ?? avatar; - } else if (fronters.members.length >= 2) { + avatar1 = fronters.members[0].avatar_url ?? avatar1; + } else if (fronters.members.length >= 2 && !(fronters.members[0].name === "scootaloo" && fronters.members[1].name === "rainbowdash")) { name = (fronters.members[0].display_name ?? fronters.members[0].name) + " and " + (fronters.members[1].display_name ?? fronters.members[1].name); + avatar1 = fronters.members[0].avatar_url ?? avatar1; + avatar2 = fronters.members[1].avatar_url ?? avatar2; } await client.setDeviceDetails(info.device, { @@ -52,7 +57,32 @@ client.once("sync", async function (state, prevState, res) { }); console.log("Uploading avatar"); - let res = await client.uploadContent((await axios.get(avatar, {responseType: "arraybuffer"})).data); + let pfp; + + if (avatar2) { + let img1 = (await axios.get(avatar1, {responseType: "arraybuffer"})).data; + let img2 = (await axios.get(avatar2, {responseType: "arraybuffer"})).data; + + fs.writeFileSync("/tmp/chm-" + user + "-1", img1); + fs.writeFileSync("/tmp/chm-" + user + "-2", img2); + + child_process.execSync("convert /tmp/chm-" + user + "-1 -gravity center -crop 50%x100% /tmp/chm-" + user + "-1.webp"); + child_process.execSync("convert /tmp/chm-" + user + "-2 -gravity center -crop 50%x100% /tmp/chm-" + user + "-2.webp"); + child_process.execSync("montage -mode concatenate -tile x1 /tmp/chm-" + user + "-1.webp /tmp/chm-" + user + "-2.webp /tmp/chm-" + user + ".webp"); + + pfp = fs.readFileSync("/tmp/chm-" + user + ".webp"); + + fs.unlinkSync("/tmp/chm-" + user + "-1"); + fs.unlinkSync("/tmp/chm-" + user + "-2"); + fs.unlinkSync("/tmp/chm-" + user + "-1.webp"); + fs.unlinkSync("/tmp/chm-" + user + "-2.webp"); + fs.unlinkSync("/tmp/chm-" + user + ".webp"); + } else { + pfp = (await axios.get(avatar1, {responseType: "arraybuffer"})).data; + } + + let res = await client.uploadContent(pfp); + await axios.put("https://chat.equestria.dev/_matrix/client/r0/profile/%40" + user + "%3Aequestria.dev/avatar_url", { avatar_url: res.content_uri }, { diff --git a/includes/fragments/metadata.inc b/includes/fragments/metadata.inc index 0d2187c..719abbc 100644 --- a/includes/fragments/metadata.inc +++ b/includes/fragments/metadata.inc @@ -6,9 +6,51 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member ?> + +
-
-

">

+
+

">

@@ -94,28 +136,166 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member

Relationships

- -

- Sexfriends (full IDs, comma-separated)
- "> -

- -

- Marefriends (full IDs, comma-separated)
- "> -

-

- Sisters (full IDs, comma-separated)
- "> -

-

- Caretakers (full IDs, comma-separated)
- "> -

-

- Friends (full IDs, comma-separated)
- "> -

+ + + + + + +

+
+ "> + + + + +

+
diff --git a/includes/util/functions.inc b/includes/util/functions.inc index 79a47c6..fe97980 100644 --- a/includes/util/functions.inc +++ b/includes/util/functions.inc @@ -3,17 +3,17 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/score.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.inc"; require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/homepage.inc"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/random.inc"; if (!function_exists("createJob")) { function createJob($title, $options) { - $jobs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs.json"), true); - $jobs[] = [ + $job = [ "name" => $title, "options" => $options, "date" => date('c') ]; - file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs.json", json_encode($jobs)); + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs/" . round(microtime(true) * 1000) . "-" . random() . ".json", json_encode($job)); } } diff --git a/pages/api/plex-thumb.php b/pages/api/plex-thumb.php deleted file mode 100644 index 4009871..0000000 --- a/pages/api/plex-thumb.php +++ /dev/null @@ -1,11 +0,0 @@ - "Plex", - "avatar_url" => "https://support.plex.tv/wp-content/themes/plex/assets/img/favicons/plex-192.png", - "embeds" => [ - [ - "title" => formatTitle($payload["Metadata"]), - "type" => "rich", - "description" => formatSubtitle($payload["Metadata"]), - "color" => hexdec( "2b2d31" ), - "thumbnail" => [ - "url" => "https://ponies.equestria.horse/assets/cache/" . $id . ".jpg" - ], - "footer" => [ - "text" => $payload["Account"]["title"] . " ยท Playing from " . $payload["Player"]["title"], - "icon_url" => $payload["Account"]["thumb"] - ] - ] - ] - - ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); -} - -if (isset($hookObject)) { - $ch = curl_init(); - - curl_setopt_array( $ch, [ - CURLOPT_URL => $app["webhook"]["plex"], - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => $hookObject, - CURLOPT_HTTPHEADER => [ - "Content-Type: application/json" - ] - ]); - - $response = curl_exec( $ch ); - curl_close( $ch ); -} \ No newline at end of file diff --git a/pages/jobs.inc b/pages/jobs.inc index 6723175..c00e35c 100644 --- a/pages/jobs.inc +++ b/pages/jobs.inc @@ -4,6 +4,7 @@ require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; gl require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/util/functions.inc'; $history = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/history.json"), true); +$running = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/running.json"), true); if (isset($_GET["enqueue"]) && isset($history[(int)$_GET["enqueue"]])) { createJob(explode("(", $history[(int)$_GET["enqueue"]]["name"])[0], $history[(int)$_GET["enqueue"]]["options"]); @@ -73,6 +74,16 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/components/header.inc';
+ $file): $item = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/jobs/" . $file), true); ?> +
+
( $value): echo($name . "=" . json_encode($value)); endforeach; ?>)
+
+
RunningPending
+
+ + $item): ?>
-- cgit