-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Make possible for apps to define their own avatar types #24579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b553b43
184742e
2cc22a0
1552add
b4b3276
1de8dc3
bcce5a6
2522439
b190431
63cbd7b
a31a7fd
92c9fc0
a836608
95e0177
f04a16a
ebf242a
bf9169e
1e13309
6e43ce7
90ac35d
5d0102e
ab910ec
a2c63ff
76e4bd2
612dbe6
0e953eb
0bb311f
611881b
6c99a9a
6079793
bcd2074
23f4c1d
e88d3b6
4a26943
fa0342a
ebc3f14
03eed3e
1348cab
8d69a4e
4368ec0
6b8f290
68b298e
cc7cd18
6ed5fde
65c8c22
135d14b
330fac8
68fa045
601d741
6391a2b
029d22c
3a4b926
6895199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,9 @@ | |
|
|
||
| use OCP\AppFramework\OCSController; | ||
| use OCP\AppFramework\Http; | ||
| use OCP\AppFramework\Http\DataResponse; | ||
| use OCP\AppFramework\Http\FileDisplayResponse; | ||
| use OCP\AppFramework\Http\JSONResponse; | ||
| use OCP\AppFramework\Http\Response; | ||
| use OCP\IAvatarManager; | ||
| use OCP\IL10N; | ||
| use OCP\ILogger; | ||
|
|
@@ -64,9 +65,9 @@ public function __construct($appName, | |
| * @param string $avatarType | ||
| * @param string $avatarId | ||
| * @param int $size | ||
| * @return JSONResponse|FileDisplayResponse | ||
| * @return DataResponse|FileDisplayResponse | ||
| */ | ||
| public function getAvatar(string $avatarType, string $avatarId, int $size) { | ||
| public function getAvatar(string $avatarType, string $avatarId, int $size): Response { | ||
| // min/max size | ||
| if ($size > 2048) { | ||
| $size = 2048; | ||
|
|
@@ -86,7 +87,7 @@ public function getAvatar(string $avatarType, string $avatarId, int $size) { | |
| ] | ||
| ); | ||
| } catch (\Exception $e) { | ||
|
||
| return new JSONResponse([], Http::STATUS_NOT_FOUND); | ||
| return new DataResponse([], Http::STATUS_NOT_FOUND); | ||
| } | ||
|
|
||
| return $response; | ||
|
|
@@ -96,13 +97,13 @@ public function getAvatar(string $avatarType, string $avatarId, int $size) { | |
| * @PublicPage | ||
| * | ||
| * @param string $path | ||
| * @return JSONResponse | ||
| * @return DataResponse | ||
| */ | ||
| public function setAvatar(string $avatarType, string $avatarId) { | ||
| public function setAvatar(string $avatarType, string $avatarId): DataResponse { | ||
| $files = $this->request->getUploadedFile('files'); | ||
|
|
||
| if (is_null($files)) { | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['data' => ['message' => $this->l->t('No file provided')]], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
|
|
@@ -113,14 +114,14 @@ public function setAvatar(string $avatarType, string $avatarId) { | |
| !is_uploaded_file($files['tmp_name'][0]) || | ||
| \OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0]) | ||
| ) { | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['data' => ['message' => $this->l->t('Invalid file provided')]], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
| } | ||
|
|
||
| if ($files['size'][0] > 20 * 1024 * 1024) { | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['data' => ['message' => $this->l->t('File is too big')]], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
|
|
@@ -135,17 +136,17 @@ public function setAvatar(string $avatarType, string $avatarId) { | |
| try { | ||
| $avatar = $this->avatarManager->getGenericAvatar($avatarType, $avatarId); | ||
| $avatar->set($image); | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['status' => 'success'] | ||
| ); | ||
| } catch (\OC\NotSquareException $e) { | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['data' => ['message' => $this->l->t('Crop is not square')]], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
| } catch (\Exception $e) { | ||
| $this->logger->logException($e, ['app' => 'core']); | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
|
|
@@ -155,16 +156,16 @@ public function setAvatar(string $avatarType, string $avatarId) { | |
| /** | ||
| * @PublicPage | ||
| * | ||
| * @return JSONResponse | ||
| * @return DataResponse | ||
| */ | ||
| public function deleteAvatar(string $avatarType, string $avatarId) { | ||
| public function deleteAvatar(string $avatarType, string $avatarId): DataResponse { | ||
| try { | ||
| $avatar = $this->avatarManager->getGenericAvatar($avatarType, $avatarId); | ||
| $avatar->remove(); | ||
| return new JSONResponse(); | ||
| return new DataResponse(); | ||
| } catch (\Exception $e) { | ||
| $this->logger->logException($e, ['app' => 'core']); | ||
| return new JSONResponse( | ||
| return new DataResponse( | ||
| ['data' => ['message' => $this->l->t('An error occurred. Please contact your admin.')]], | ||
| Http::STATUS_BAD_REQUEST | ||
| ); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can even use the
min/maxfunctions for this 😉There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but not for <= 0 use 64.
On the other side @rullzer always wanted to limit the formats anyway.
I would suggest to only allow: 64, 128, 256 and 512 as sizes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I have realized that this (which is a shameless copy/paste from the old controller :-P ) does not allow to use -1 to get an avatar with the original size (which is documented in
IAvatar). Should we allow that in the new controller?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only 64, 128, 256, 512 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no real preference on the set of sizes, although limiting it to only a specific set sounds like a good idea to prevent an unneeded use of disk space if a "funny" user does something like
for i in {64..512}; do curl .../avatar/user0/$i; done. Thus I have added a commit for that.I still wonder about the "-1" to get the original size; it could be used for example if a user wants to check her current avatar exactly like it was uploaded.