1
0
Fork 0
mirror of synced 2024-07-02 05:00:33 +12:00

Use compound ID for push notification image

This commit is contained in:
Jake Barnby 2024-02-20 18:25:57 +13:00
parent 42e1b0dfe3
commit 4bc6c202d9
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
2 changed files with 14 additions and 8 deletions

View file

@ -2830,7 +2830,7 @@ App::post('/v1/messaging/messages/push')
->param('targets', [], new ArrayList(new UID()), 'List of Targets IDs.', true) ->param('targets', [], new ArrayList(new UID()), 'List of Targets IDs.', true)
->param('data', null, new JSON(), 'Additional Data for push notification.', true) ->param('data', null, new JSON(), 'Additional Data for push notification.', true)
->param('action', '', new Text(256), 'Action for push notification.', true) ->param('action', '', new Text(256), 'Action for push notification.', true)
->param('image', '', new Key(), 'Image for push notification. Must be the ID of a jpeg or png image in Appwrite Storage.', true) ->param('image', '', new CompoundUID(), 'Image for push notification. Must be a compound bucket ID to file ID of a jpeg, png, or bmp image in Appwrite Storage.', true)
->param('icon', '', new Text(256), 'Icon for push notification. Available only for Android and Web Platform.', true) ->param('icon', '', new Text(256), 'Icon for push notification. Available only for Android and Web Platform.', true)
->param('sound', '', new Text(256), 'Sound for push notification. Available only for Android and IOS Platform.', true) ->param('sound', '', new Text(256), 'Sound for push notification. Available only for Android and IOS Platform.', true)
->param('color', '', new Text(256), 'Color for push notification. Available only for Android Platform.', true) ->param('color', '', new Text(256), 'Color for push notification. Available only for Android Platform.', true)
@ -2876,19 +2876,23 @@ App::post('/v1/messaging/messages/push')
} }
if (!empty($image)) { if (!empty($image)) {
$image = $dbForProject->getDocument('files', $image); [$bucketId, $fileId] = CompoundUID::parse($image);
if ($image->isEmpty()) { $bucket = $dbForProject->getDocument('buckets', $bucketId);
throw new Exception(Exception::STORAGE_FILE_NOT_FOUND); if ($bucket->isEmpty()) {
throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND);
} }
$bucket = $dbForProject->getDocument('buckets', $image->getAttribute('bucketId')); $file = $dbForProject->getDocument('bucket_' . $bucket->getInternalId(), $fileId);
if ($file->isEmpty()) {
throw new Exception(Exception::STORAGE_BUCKET_NOT_FOUND);
}
if (!\in_array(Permission::read(Role::any()), \array_merge($image->getRead(), $bucket->getRead()))) { if (!\in_array(Permission::read(Role::any()), \array_merge($file->getRead(), $bucket->getRead()))) {
throw new Exception(Exception::STORAGE_FILE_NOT_PUBLIC); throw new Exception(Exception::STORAGE_FILE_NOT_PUBLIC);
} }
if (!\in_array($image->getAttribute('mimeType'), ['image/png', 'image/jpeg'])) { if (!\in_array($file->getAttribute('mimeType'), ['image/png', 'image/jpeg'])) {
throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED); throw new Exception(Exception::STORAGE_FILE_TYPE_UNSUPPORTED);
} }
@ -2900,7 +2904,7 @@ App::post('/v1/messaging/messages/push')
throw new Exception(Exception::STORAGE_FILE_NOT_PUBLIC); throw new Exception(Exception::STORAGE_FILE_NOT_PUBLIC);
} }
$image = "{$protocol}://{$host}/v1/storage/buckets/{$bucket->getId()}/files/{$image->getId()}/view?project={$project->getId()}"; $image = "{$protocol}://{$host}/v1/storage/buckets/{$bucket->getId()}/files/{$file->getId()}/view?project={$project->getId()}";
} }
$pushData = []; $pushData = [];

View file

@ -636,6 +636,7 @@ class Messaging extends Action
$body = $message['data']['body']; $body = $message['data']['body'];
$data = $message['data']['data'] ?? null; $data = $message['data']['data'] ?? null;
$action = $message['data']['action'] ?? null; $action = $message['data']['action'] ?? null;
$image = $message['data']['image'] ?? null;
$sound = $message['data']['sound'] ?? null; $sound = $message['data']['sound'] ?? null;
$icon = $message['data']['icon'] ?? null; $icon = $message['data']['icon'] ?? null;
$color = $message['data']['color'] ?? null; $color = $message['data']['color'] ?? null;
@ -649,6 +650,7 @@ class Messaging extends Action
$data, $data,
$action, $action,
$sound, $sound,
$image,
$icon, $icon,
$color, $color,
$tag, $tag,