refactor: remove web components remote manifest checking

This commit is contained in:
Zack Spear
2023-06-26 13:43:38 -07:00
committed by Zack Spear
parent 8733921b6b
commit aa8a6f1934

View File

@@ -21,51 +21,6 @@ connect-user-profile {
// Set the path for the local manifest file
$localManifestFile = '/usr/local/emhttp/plugins/dynamix.my.servers/connect-components/manifest.json';
// Define the remote resource URL
$remoteResourceUrl = 'https://components.myunraid.com/';
// Check if session cookie exists
if (!isset($_COOKIE['manifest_last_checked']) || time() - $_COOKIE['manifest_last_checked'] >= 300) {
// Get the remote manifest JSON
$remoteManifestJson = file_get_contents($remoteResourceUrl . 'manifest.json');
// Compare the remote and local manifest versions
$remoteManifest = json_decode($remoteManifestJson, true);
$localManifest = json_decode(file_get_contents($localManifestFile), true);
if ($remoteManifest && $localManifest && $remoteManifest !== $localManifest) {
// Update the local manifest
file_put_contents($localManifestFile, $remoteManifestJson);
// Download the file contents for the search value
$searchText = 'connect-components.client.mjs';
$fileValue = null;
foreach ($remoteManifest as $key => $value) {
if (strpos($key, $searchText) !== false && isset($value["file"])) {
$fileValue = file_get_contents($remoteResourceUrl . $value["file"]);
break;
}
}
if ($fileValue !== null) {
// Extract the directory path from the URL
$directoryPath = pathinfo($value["file"], PATHINFO_DIRNAME);
// Set the local file path
$localFilePath = '/usr/local/emhttp/plugins/dynamix.my.servers' . $directoryPath;
// Create the directory if it doesn't exist
if (!is_dir($localFilePath)) {
mkdir($localFilePath, 0777, true);
}
// Save the file contents to a local file
file_put_contents($localFilePath . '/' . basename($value["file"]), $fileValue);
}
}
// Set the session cookie with the current timestamp
setcookie('manifest_last_checked', time(), time() + 300); // Expire in 5 minutes
}
// Load the local manifest
$localManifest = json_decode(file_get_contents($localManifestFile), true);
@@ -83,6 +38,5 @@ if ($fileValue !== null) {
$prefixedPath = '/plugins/dynamix.my.servers/connect-components/';
echo '<script src="' . $prefixedPath . $fileValue . '"></script>';
} else {
echo '<script>console.error("%cUnraid Connect • No matching key containing \'' . $searchText . '\' found in manfiest.json.", "font-weight: bold; color: white; background-color: red");</script>';
}
?>
echo '<script>console.error("%cNo matching key containing \'' . $searchText . '\' found.", "font-weight: bold; color: white; background-color: red");</script>';
}