new filetag endpoint and config.php update
This commit is contained in:
@@ -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)
|
||||
|
||||
42
getFileTag.php
Normal file
42
getFileTag.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// getFileTag.php
|
||||
|
||||
require_once 'config.php';
|
||||
|
||||
// Set security and content headers
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
|
||||
$metadataPath = META_DIR . 'createdTags.json';
|
||||
|
||||
// Check if the metadata file exists and is readable
|
||||
if (!file_exists($metadataPath) || !is_readable($metadataPath)) {
|
||||
error_log('Metadata file does not exist or is not readable: ' . $metadataPath);
|
||||
http_response_code(200); // Return empty array with HTTP 200 so the client can handle it gracefully
|
||||
echo json_encode([]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = file_get_contents($metadataPath);
|
||||
if ($data === false) {
|
||||
error_log('Failed to read metadata file: ' . $metadataPath);
|
||||
http_response_code(500);
|
||||
echo json_encode(["error" => "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;
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user