Skip to content

Commit

Permalink
Refactor class.action.quickPick.php: add rebuildQuickpickJson call if…
Browse files Browse the repository at this point in the history
… local file doesn't exist; simplify JSON sanitization logic
  • Loading branch information
N6REJ committed Aug 3, 2024
1 parent e64c269 commit d390220
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1,003 deletions.
10 changes: 4 additions & 6 deletions core/classes/actions/class.action.quickPick.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function checkQuickpickJson()
// Get the creation time of the local file if it exists
if ( file_exists( $this->jsonFilePath ) ) {
$localFileCreationTime = filectime( $this->jsonFilePath );
} else {
$result = $this->rebuildQuickpickJson();
}

// Get the creation time of the remote file
Expand Down Expand Up @@ -160,12 +162,8 @@ public function getQuickpickJson(): array

return ['error' => 'Error fetching JSON file'];
}
// file has extra spaces in key data, time to sanitise the data

$j = $content;
$j = str_replace( "\" ", "\"", $j ); // remove "<space>data
$j = str_replace( " \"", "\"", $j ); // remove data<space>"
$data = json_decode( $j, true );
$data = json_decode( $content, true );
if ( json_last_error() !== JSON_ERROR_NONE ) {
Util::logError( 'Error decoding JSON content: ' . json_last_error_msg() );

Expand Down Expand Up @@ -549,7 +547,7 @@ public function getQuickpickMenu(array $modules, array $versions, string $images
<div class = "progress" id = "progress" tabindex = "-1" style = "width:260px;display:none"
aria-labelledby = "progressbar" aria-hidden = "true">
<div class = "progress-bar" id = "progress-bar" role = "progressbar" aria-valuenow = "0" aria-valuemin = "0" aria-valuemax = "100" data-module = "Module"
data-version = "0.0.0" width = "0">0%
data-version = "0.0.0">0%
</div>
<div id = "download-module" style = "display: none">ModuleName</div>
<div id = "download-version" style = "display: none">Version</div>
Expand Down
Loading

0 comments on commit d390220

Please sign in to comment.