From 4360f2830a2766a8e80d955a2c0a18158e3ba9d5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 10 Apr 2025 10:33:13 -0400 Subject: [PATCH] new filetag endpoint and config.php update --- config.php | 9 ++++++--- getFileTag.php | 42 ++++++++++++++++++++++++++++++++++++++++++ js/fileTags.js | 2 +- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 getFileTag.php diff --git a/config.php b/config.php index a9ae36a..47a2c81 100644 --- a/config.php +++ b/config.php @@ -48,9 +48,12 @@ function decryptData($encryptedData, $encryptionKey) } // Load encryption key from environment (override in production). -$encryptionKey = getenv('PERSISTENT_TOKENS_KEY') ?: 'default_please_change_this_key'; -if (!$encryptionKey) { - die('Encryption key for persistent tokens is not set.'); +$envKey = getenv('PERSISTENT_TOKENS_KEY'); +if ($envKey === false || $envKey === '') { + $encryptionKey = 'default_please_change_this_key'; + error_log('WARNING: Using default encryption key. Please set PERSISTENT_TOKENS_KEY in your environment.'); +} else { + $encryptionKey = $envKey; } function loadUserPermissions($username) diff --git a/getFileTag.php b/getFileTag.php new file mode 100644 index 0000000..9cd2bf3 --- /dev/null +++ b/getFileTag.php @@ -0,0 +1,42 @@ + "Unable to read metadata file."]); + exit; +} + +// Decode the JSON data to check for validity +$jsonData = json_decode($data, true); +if (json_last_error() !== JSON_ERROR_NONE) { + error_log('Invalid JSON in metadata file: ' . $metadataPath . ' Error: ' . json_last_error_msg()); + http_response_code(500); + echo json_encode(["error" => "Metadata file contains invalid JSON."]); + exit; +} + +// Output the re-encoded JSON to ensure well-formed output +echo json_encode($jsonData); +exit; \ No newline at end of file diff --git a/js/fileTags.js b/js/fileTags.js index 9724bb0..ea55231 100644 --- a/js/fileTags.js +++ b/js/fileTags.js @@ -305,7 +305,7 @@ if (localStorage.getItem('globalTags')) { // New function to load global tags from the server's persistent JSON. export function loadGlobalTags() { - fetch("metadata/createdTags.json", { credentials: "include" }) + fetch("getFileTag.php", { credentials: "include" }) .then(response => { if (!response.ok) { // If the file doesn't exist, assume there are no global tags.