kopia lustrzana https://github.com/nextcloud/social
Merge pull request #72 from nextcloud-gmbh/avatar-enpoint
Add unified avatar endpoint to quickly fetch avatarspull/79/head
commit
fd8943fdbb
|
@ -356,7 +356,7 @@
|
|||
<name>icon_id</name>
|
||||
<type>text</type>
|
||||
<length>127</length>
|
||||
<notnull>true</notnull>
|
||||
<notnull>false</notnull>
|
||||
</field>
|
||||
|
||||
<field>
|
||||
|
|
|
@ -76,6 +76,7 @@ return [
|
|||
['name' => 'Local#accountUnfollow', 'url' => '/api/v1/account/follow', 'verb' => 'DELETE'],
|
||||
['name' => 'Local#accountInfo', 'url' => '/api/v1/account/info', 'verb' => 'GET'],
|
||||
['name' => 'Local#actorInfo', 'url' => '/api/v1/actor/info', 'verb' => 'GET'],
|
||||
['name' => 'Local#actorAvatar', 'url' => '/api/v1/actor/avatar', 'verb' => 'GET'],
|
||||
['name' => 'Local#documentsCache', 'url' => '/api/v1/documents/cache', 'verb' => 'POST'],
|
||||
|
||||
['name' => 'Queue#asyncWithToken', 'url' => CurlService::ASYNC_TOKEN, 'verb' => 'POST'],
|
||||
|
|
|
@ -46,6 +46,9 @@ use OCA\Social\Service\MiscService;
|
|||
use OCA\Social\Service\PostService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\Http\FileDisplayResponse;
|
||||
use OCP\AppFramework\Http\NotFoundResponse;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
||||
|
@ -403,6 +406,27 @@ class LocalController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
* @param string $id
|
||||
* @return DataResponse
|
||||
*/
|
||||
public function actorAvatar(string $id): Response {
|
||||
try {
|
||||
$actor = $this->personService->getFromId($id);
|
||||
if ($actor->gotIcon()) {
|
||||
$avatar = $actor->getIcon();
|
||||
$document = $this->documentService->getFromCache($avatar->getId());
|
||||
return new FileDisplayResponse($document);
|
||||
}
|
||||
return new NotFoundResponse();
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* // TODO: Delete the NoCSRF check
|
||||
|
|
|
@ -112,7 +112,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
|
|||
*/
|
||||
public function getFromId(string $id): Person {
|
||||
$qb = $this->getCacheActorsSelectSql();
|
||||
$this->limitToIdString($qb, $id);
|
||||
$this->limitToIdString($qb, $id, false);
|
||||
$this->leftJoinCacheDocuments($qb, 'icon_id');
|
||||
|
||||
$cursor = $qb->execute();
|
||||
|
|
|
@ -109,9 +109,10 @@ class CoreRequestBuilder {
|
|||
*
|
||||
* @param IQueryBuilder $qb
|
||||
* @param string $id
|
||||
* @param bool $cs
|
||||
*/
|
||||
protected function limitToIdString(IQueryBuilder &$qb, string $id) {
|
||||
$this->limitToDBField($qb, 'id', $id);
|
||||
protected function limitToIdString(IQueryBuilder &$qb, string $id, bool $cs = true) {
|
||||
$this->limitToDBField($qb, 'id', $id, $cs);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -106,12 +106,9 @@ class PersonService implements ICoreService {
|
|||
$this->cacheActorsRequest->deleteFromId($actor->getId());
|
||||
}
|
||||
|
||||
try {
|
||||
$actor->setLocal(true);
|
||||
$actor->setSource(json_encode($actor, JSON_UNESCAPED_SLASHES));
|
||||
$this->parse($actor);
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
$actor->setLocal(true);
|
||||
$actor->setSource(json_encode($actor, JSON_UNESCAPED_SLASHES));
|
||||
$this->parse($actor);
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,6 +164,7 @@ class PersonService implements ICoreService {
|
|||
* @throws CacheActorDoesNotExistException
|
||||
* @throws SocialAppConfigException
|
||||
* @throws UrlCloudException
|
||||
* @throws Request410Exception
|
||||
*/
|
||||
public function getFromAccount(string $account, bool $retrieve = true): Person {
|
||||
|
||||
|
@ -239,8 +237,6 @@ class PersonService implements ICoreService {
|
|||
* This method is called when saving the Follow object
|
||||
*
|
||||
* @param ACore $person
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function parse(ACore $person) {
|
||||
/** @var Person $person */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div class="entry-content">
|
||||
<div class="post-avatar">
|
||||
<avatar v-if="item.actor_info" :size="32" :user="item.actor_info.preferredUsername" />
|
||||
<avatar :size="32" user="?" />
|
||||
<avatar :size="32" :url="avatarUrl" />
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<div class="post-author-wrapper">
|
||||
|
@ -57,6 +57,9 @@ export default {
|
|||
})
|
||||
message = this.$twemoji.parse(message)
|
||||
return message
|
||||
},
|
||||
avatarUrl: function() {
|
||||
return OC.generateUrl('/apps/social/api/v1/actor/avatar?id=' + this.item.attributedTo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue