Skip to content

Commit 4164b51

Browse files
authored
Merge pull request #351 from nextcloud/fix/noid/audio-attachment-check
Prevent accessing array index on null
2 parents 2434125 + 1131753 commit 4164b51

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

lib/Controller/ChattyLLMController.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,9 @@ public function generateForSession(int $sessionId, int $agencyConfirm = 0): JSON
500500

501501
$lastAttachments = $lastUserMessage->jsonSerialize()['attachments'];
502502
$audioAttachment = $lastAttachments[0] ?? null;
503-
$audioAttachment = $audioAttachment['type'] === 'Audio' ? $audioAttachment : null;
504503
if ($audioAttachment !== null
504+
&& isset($audioAttachment['type'])
505+
&& $audioAttachment['type'] === 'Audio'
505506
&& class_exists('OCP\\TaskProcessing\\TaskTypes\\ContextAgentAudioInteraction')
506507
&& isset($this->taskProcessingManager->getAvailableTaskTypes()[\OCP\TaskProcessing\TaskTypes\ContextAgentAudioInteraction::ID])
507508
) {
@@ -535,13 +536,9 @@ public function generateForSession(int $sessionId, int $agencyConfirm = 0): JSON
535536

536537
$lastAttachments = $lastUserMessage->jsonSerialize()['attachments'];
537538
$audioAttachment = $lastAttachments[0] ?? null;
538-
$audioAttachment = $audioAttachment['type'] === 'Audio' ? $audioAttachment : null;
539-
/* php 8.4 allows:
540-
$audioAttachment = array_find($lastAttachments, static function (array $attachment) {
541-
return $attachment['type'] === 'Audio';
542-
});
543-
*/
544539
if ($audioAttachment !== null
540+
&& isset($audioAttachment['type'])
541+
&& $audioAttachment['type'] === 'Audio'
545542
&& class_exists('OCP\\TaskProcessing\\TaskTypes\\AudioToAudioChat')
546543
&& isset($this->taskProcessingManager->getAvailableTaskTypes()[\OCP\TaskProcessing\TaskTypes\AudioToAudioChat::ID])
547544
) {

0 commit comments

Comments
 (0)