Merge pull request #1669 from nextcloud/avatar-4

fix remote avatar url
pull/1718/head
Louis 2023-04-06 15:52:04 +02:00 zatwierdzone przez GitHub
commit e40bcb95cd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 45 dodań i 21 usunięć

Wyświetl plik

@ -146,17 +146,17 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
*/
public function parseCacheActorsSelectSql(array $data, SocialQueryBuilder $qb): Person {
$actor = new Person();
$actor->importFromDatabase($data);
$actor->setExportFormat($qb->getFormat());
$this->assignViewerLink($qb, $actor);
try {
$icon = $qb->parseLeftJoinCacheDocuments($data);
$actor->setIcon($icon);
} catch (InvalidResourceException $e) {
}
$actor->importFromDatabase($data);
$this->assignViewerLink($qb, $actor);
$this->assignDetails($actor, $data);
return $actor;

Wyświetl plik

@ -225,6 +225,7 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
->selectAlias($alias . '.media_type', $prefix . 'media_type')
->selectAlias($alias . '.url', $prefix . 'url')
->selectAlias($alias . '.local_copy', $prefix . 'local_copy')
->selectAlias($alias . '.resized_copy', $prefix . 'resized_copy')
->selectAlias($alias . '.caching', $prefix . 'caching')
->selectAlias($alias . '.public', $prefix . 'public')
->selectAlias($alias . '.error', $prefix . 'error')

Wyświetl plik

@ -43,6 +43,8 @@ use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Object\Image;
use OCA\Social\Tools\IQueryRow;
use OCA\Social\Traits\TDetails;
use OCP\IURLGenerator;
use OCP\Server;
/**
* Class Actor
@ -184,6 +186,11 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
* @return string
*/
public function getAvatar(): string {
if ($this->hasIcon()) {
return $this->getIcon()
->getUrl();
}
return $this->avatar;
}
@ -769,6 +776,10 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
* @return array
*/
public function exportAsLocal(): array {
if ($this->hasIcon()) {
$avatar = $this->getIcon()->getMediaUrl(Server::get(IURLGenerator::class));
}
$details = $this->getDetailsAll();
$result =
[
@ -783,10 +794,10 @@ class Person extends ACore implements IQueryRow, JsonSerializable {
'created_at' => date('Y-m-d\TH:i:s', $this->getCreation()) . '.000Z',
'note' => $this->getDescription(),
'url' => $this->getId(),
'avatar' => $this->getAvatar(),
'avatar_static' => $this->getAvatar(),
'header' => $this->getHeader(),
'header_static' => $this->getHeader(),
'avatar' => $avatar ?? $this->getAvatar(),
'avatar_static' => $avatar ?? $this->getAvatar(),
'header' => $avatar ?? $this->getHeader(),
'header_static' => $avatar ?? $this->getHeader(),
'followers_count' => $this->getInt('count.followers', $details),
'following_count' => $this->getInt('count.following', $details),
'statuses_count' => $this->getInt('count.post', $details),

Wyświetl plik

@ -366,7 +366,29 @@ class Document extends ACore implements JsonSerializable {
return $result;
}
public function getMediaUrl(IURLGenerator $urlGenerator, string $mime = ''): string {
$mime = ($mime === '') ? '' : '.' . $mime;
return $urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getLocalCopy() . $mime]
);
}
public function getResizedMediaUrl(IURLGenerator $urlGenerator, string $mime = ''): string {
$mime = ($mime === '') ? '' : '.' . $mime;
return $urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getResizedCopy() . $mime]
);
}
/**
* @param IURLGenerator|null $urlGenerator
*
* @return MediaAttachment
*/
public function convertToMediaAttachment(
@ -381,25 +403,15 @@ class Document extends ACore implements JsonSerializable {
if (strpos($this->getMediaType(), '/')) {
[$type, $mime] = explode('/', $this->getMediaType(), 2);
$media->setType($type);
$mime = (strlen($mime) < 7) ? '.' . $mime : ''; // mime is ignored if too long.
}
if (!is_null($urlGenerator)) {
$media->setUrl(
$urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getLocalCopy() . $mime]
)
);
$media->setPreviewUrl(
$urlGenerator->linkToRouteAbsolute(
'social.Api.mediaOpen',
['uuid' => $this->getResizedCopy() . $mime]
)
);
$media->setRemoteUrl($this->getUrl());
$media->setUrl($this->getMediaUrl($urlGenerator, $mime));
$media->setPreviewUrl($this->getResizedMediaUrl($urlGenerator, $mime));
}
$media->setRemoteUrl($this->getUrl());
if ($this->getMeta() === null) {
$meta = new AttachmentMeta();
$meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize()))