Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Oct 16, 2024
1 parent 8f038aa commit 2c42fc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions plugin/BulkEmbed/search.json.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
header('Content-Type: application/json');

if (!User::isLogged()) {
die(json_encode(['error' => 'You must be logged in to search']));
die(json_encode(['error' => true, 'msg'=>'You must be logged in to search']));
}

$query = $_POST['query'] ?? '';
$pageToken = $_POST['pageToken'] ?? '';

if (empty($query)) {
die(json_encode(['error' => 'Search query cannot be empty']));
die(json_encode(['error' => true, 'msg'=>'Search query cannot be empty']));
}

$obj = AVideoPlugin::getObjectData("BulkEmbed");
Expand All @@ -23,11 +23,17 @@
$youtubeApiUrl .= "&pageToken=" . $pageToken;
}

$response = file_get_contents($youtubeApiUrl);
$response = url_get_contents($youtubeApiUrl);
$responseData = json_decode($response, true);

if (empty($responseData) || !isset($responseData['items'])) {
die(json_encode(['error' => 'Failed to retrieve data from YouTube', $responseData]));
_error_log('Failed to retrieve data from YouTube ' . $youtubeApiUrl);
$msg = 'Failed to retrieve data from YouTube';
if(!empty($responseData['error']) && !empty($responseData['error']['message'])){
$msg .= '<br>'.$responseData['error']['message'];
}

die(json_encode(['error' => true, 'msg'=>$msg]));
}

// Prepare the result array to include the embedding status
Expand Down
2 changes: 1 addition & 1 deletion plugin/BulkEmbed/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function search(pageToken = '') {
},
success: function(response) {
if (response.error) {
avideoAlertError(response.error);
avideoAlertError(response.msg);
} else {
processData(response.data);
// Store search results globally
Expand Down

0 comments on commit 2c42fc6

Please sign in to comment.