UPSTREAM BASELINE: nextcloud/spreed v22.0.12 (без изменений)
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Type checking / changes (push) Has been cancelled
Type checking / test (push) Has been cancelled
Type checking / typescript-summary (push) Has been cancelled
Node tests / changes (push) Has been cancelled
Node tests / test (push) Has been cancelled
Node tests / test-summary (push) Has been cancelled
Источник: https://github.com/nextcloud/spreed/archive/refs/tags/v22.0.12.tar.gz С этого коммита ветка официального Nextcloud Talk отрезана (решение владельца 2026-07-06). Все дальнейшие изменения — только наши; версии релизов: 22.0.12-f7.N.
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Talk\Federation\Proxy\TalkV1\Controller;
|
||||
|
||||
use OCA\Talk\Exceptions\CannotReachRemoteException;
|
||||
use OCA\Talk\Federation\Proxy\TalkV1\ProxyRequest;
|
||||
use OCA\Talk\Model\Invitation;
|
||||
use OCA\Talk\Participant;
|
||||
use OCA\Talk\ResponseDefinitions;
|
||||
use OCA\Talk\Room;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\FileDisplayResponse;
|
||||
use OCP\Files\SimpleFS\InMemoryFile;
|
||||
|
||||
/**
|
||||
* @psalm-import-type TalkChatMentionSuggestion from ResponseDefinitions
|
||||
* @psalm-import-type TalkChatMessageWithParent from ResponseDefinitions
|
||||
*/
|
||||
class AvatarController {
|
||||
public function __construct(
|
||||
protected ProxyRequest $proxy,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \OCA\Talk\Controller\AvatarController::getAvatar()
|
||||
*
|
||||
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>
|
||||
* @throws CannotReachRemoteException
|
||||
*
|
||||
* 200: Room avatar returned
|
||||
*/
|
||||
public function getAvatar(Room $room, ?Participant $participant, ?Invitation $invitation, bool $darkTheme): FileDisplayResponse {
|
||||
if ($participant === null && $invitation === null) {
|
||||
throw new CannotReachRemoteException('Must receive either participant or invitation');
|
||||
}
|
||||
|
||||
$proxy = $this->proxy->get(
|
||||
$participant ? $participant->getAttendee()->getInvitedCloudId() : $invitation->getLocalCloudId(),
|
||||
$participant ? $participant->getAttendee()->getAccessToken() : $invitation->getAccessToken(),
|
||||
$room->getRemoteServer() . '/ocs/v2.php/apps/spreed/api/v1/room/' . $room->getRemoteToken() . '/avatar' . ($darkTheme ? '/dark' : ''),
|
||||
);
|
||||
|
||||
if ($proxy->getStatusCode() !== Http::STATUS_OK) {
|
||||
$this->proxy->logUnexpectedStatusCode(__METHOD__, $proxy->getStatusCode(), (string)$proxy->getBody());
|
||||
throw new CannotReachRemoteException('Avatar request had unexpected status code');
|
||||
}
|
||||
|
||||
$content = $proxy->getBody();
|
||||
if ($content === '') {
|
||||
throw new CannotReachRemoteException('No avatar content received');
|
||||
}
|
||||
|
||||
$file = new InMemoryFile($room->getToken(), $content);
|
||||
|
||||
$response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
|
||||
// Cache for 1 day
|
||||
$response->cacheFor(60 * 60 * 24, false, true);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see \OCA\Talk\Controller\AvatarController::getUserProxyAvatar()
|
||||
*
|
||||
* @return FileDisplayResponse<Http::STATUS_OK, array{Content-Type: string}>
|
||||
* @throws CannotReachRemoteException
|
||||
*
|
||||
* 200: User avatar returned
|
||||
*/
|
||||
public function getUserProxyAvatar(string $remoteServer, string $user, int $size, bool $darkTheme): FileDisplayResponse {
|
||||
$proxy = $this->proxy->get(
|
||||
null,
|
||||
null,
|
||||
$remoteServer . '/index.php/avatar/' . $user . '/' . $size . ($darkTheme ? '/dark' : ''),
|
||||
);
|
||||
|
||||
if ($proxy->getStatusCode() !== Http::STATUS_OK) {
|
||||
if ($proxy->getStatusCode() !== Http::STATUS_NOT_FOUND) {
|
||||
$this->proxy->logUnexpectedStatusCode(__METHOD__, $proxy->getStatusCode(), (string)$proxy->getBody());
|
||||
}
|
||||
throw new CannotReachRemoteException('Avatar request had unexpected status code');
|
||||
}
|
||||
|
||||
$content = $proxy->getBody();
|
||||
if ($content === '') {
|
||||
throw new CannotReachRemoteException('No avatar content received');
|
||||
}
|
||||
|
||||
$file = new InMemoryFile($user, $content);
|
||||
|
||||
$response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
|
||||
// Cache for 1 day
|
||||
$response->cacheFor(60 * 60 * 24, false, true);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user