Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-08-30 14:27:21 +0300
committerCarl Schwan <carl@carlschwan.eu>2022-09-09 14:37:51 +0300
commitf98ae2b5b0567f28a875106724c0475d6395f3c5 (patch)
treebc21874832e15741f4c5a9545138b3044f7c340b /core
parent76f42e121b7aee17508feeb8e86ded55b9b78736 (diff)
Avatar new style
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Diffstat (limited to 'core')
-rw-r--r--core/Controller/AvatarController.php40
-rw-r--r--core/routes.php1
2 files changed, 40 insertions, 1 deletions
diff --git a/core/Controller/AvatarController.php b/core/Controller/AvatarController.php
index 5fcd2a9abbe..804000bf2a7 100644
--- a/core/Controller/AvatarController.php
+++ b/core/Controller/AvatarController.php
@@ -84,6 +84,44 @@ class AvatarController extends Controller {
$this->timeFactory = $timeFactory;
}
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @NoSameSiteCookieRequired
+ * @PublicPage
+ *
+ * @return JSONResponse|FileDisplayResponse
+ */
+ public function getAvatarDark(string $userId, int $size) {
+ if ($size <= 64) {
+ if ($size !== 64) {
+ $this->logger->debug('Avatar requested in deprecated size ' . $size);
+ }
+ $size = 64;
+ } else {
+ if ($size !== 512) {
+ $this->logger->debug('Avatar requested in deprecated size ' . $size);
+ }
+ $size = 512;
+ }
+
+ try {
+ $avatar = $this->avatarManager->getAvatar($userId);
+ $avatarFile = $avatar->getFile($size, true);
+ $response = new FileDisplayResponse(
+ $avatarFile,
+ Http::STATUS_OK,
+ ['Content-Type' => $avatarFile->getMimeType(), 'X-NC-IsCustomAvatar' => (int)$avatar->isCustomAvatar()]
+ );
+ } catch (\Exception $e) {
+ return new JSONResponse([], Http::STATUS_NOT_FOUND);
+ }
+
+ // Cache for 1 day
+ $response->cacheFor(60 * 60 * 24, false, true);
+ return $response;
+ }
+
/**
* @NoAdminRequired
@@ -93,7 +131,7 @@ class AvatarController extends Controller {
*
* @return JSONResponse|FileDisplayResponse
*/
- public function getAvatar(string $userId, int $size) {
+ public function getAvatar(string $userId, int $size, bool $darkTheme = false) {
if ($size <= 64) {
if ($size !== 64) {
$this->logger->debug('Avatar requested in deprecated size ' . $size);
diff --git a/core/routes.php b/core/routes.php
index b75cb0f6b3b..ee5fbb34a4c 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -45,6 +45,7 @@ $application->registerRoutes($this, [
['name' => 'lost#setPassword', 'url' => '/lostpassword/set/{token}/{userId}', 'verb' => 'POST'],
['name' => 'ProfilePage#index', 'url' => '/u/{targetUserId}', 'verb' => 'GET'],
['name' => 'user#getDisplayNames', 'url' => '/displaynames', 'verb' => 'POST'],
+ ['name' => 'avatar#getAvatarDark', 'url' => '/avatar/{userId}/{size}/dark', 'verb' => 'GET'],
['name' => 'avatar#getAvatar', 'url' => '/avatar/{userId}/{size}', 'verb' => 'GET'],
['name' => 'avatar#deleteAvatar', 'url' => '/avatar/', 'verb' => 'DELETE'],
['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],