Skip to content
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

fix: Set all rich object parameter values to string #12021

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,11 @@ protected function getFileFromShare(?Participant $participant, string $shareId):
'type' => 'file',
'id' => (string) $fileId,
'name' => $name,
'size' => $size,
'size' => (string) $size,
'path' => $path,
'link' => $url,
'etag' => $node->getEtag(),
'permissions' => $node->getPermissions(),
'permissions' => (string) $node->getPermissions(),
'mimetype' => $node->getMimeType(),
'preview-available' => $isPreviewAvailable ? 'yes' : 'no',
];
Expand All @@ -814,8 +814,8 @@ protected function getFileFromShare(?Participant $participant, string $shareId):
try {
$sizeMetadata = $this->metadataCache->getMetadataPhotosSizeForFileId($fileId);
if (isset($sizeMetadata['width'], $sizeMetadata['height'])) {
$data['width'] = $sizeMetadata['width'];
$data['height'] = $sizeMetadata['height'];
$data['width'] = (string) $sizeMetadata['width'];
$data['height'] = (string) $sizeMetadata['height'];
}
} catch (FilesMetadataNotFoundException) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ export default {
* File size in bytes
*/
size: {
type: Number,
default: -1,
type: String,
default: '-1',
},
/**
* Download link
Expand All @@ -181,8 +181,8 @@ export default {
* File ETag
*/
permissions: {
type: Number,
default: 0,
type: String,
default: '0',
},
/**
* Whether a preview is available, string "yes" for yes
Expand All @@ -198,15 +198,15 @@ export default {
* If preview and metadata are available, return width
*/
width: {
type: Number,
type: String,
default: null,
},

/**
* If preview and metadata are available, return height
*/
height: {
type: Number,
type: String,
default: null,
},

Expand Down Expand Up @@ -407,12 +407,12 @@ export default {
}

const sizeMultiplicator = Math.min(
(heightConstraint > this.height ? 1 : (heightConstraint / this.height)),
(widthConstraint > this.width ? 1 : (widthConstraint / this.width))
(heightConstraint > parseInt(this.height, 10) ? 1 : (heightConstraint / parseInt(this.height, 10))),
(widthConstraint > parseInt(this.width, 10) ? 1 : (widthConstraint / parseInt(this.width, 10)))
)

return {
width: this.width * sizeMultiplicator + 'px',
width: parseInt(this.width, 10) * sizeMultiplicator + 'px',
aspectRatio: this.width + '/' + this.height,
}
},
Expand All @@ -426,7 +426,7 @@ export default {
return PREVIEW_TYPE.MIME_ICON
}
const maxGifSize = getCapabilities()?.spreed?.config?.previews?.['max-gif-size'] || 3145728
if (this.mimetype === 'image/gif' && this.size <= maxGifSize) {
if (this.mimetype === 'image/gif' && parseInt(this.size, 10) <= maxGifSize) {
return PREVIEW_TYPE.DIRECT
}

Expand Down
6 changes: 3 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ export type Participant = components['schemas']['Participant']
export type Mention = RichObject<'server'|'call-type'|'icon-url'>
export type File = RichObject<'size'|'path'|'link'|'mimetype'|'preview-available'> & {
'etag': string,
'permissions': number,
'width': number,
'height': number,
'permissions': string,
'width': string,
'height': string,
}
export type ChatMessage = components['schemas']['ChatMessageWithParent']
export type receiveMessagesParams = ApiOptions<operations['chat-receive-messages']['parameters']['query']>['params']
Expand Down
16 changes: 8 additions & 8 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,15 +679,15 @@ public function testGetFileFromShareForGuest() {
'type' => 'file',
'id' => '54',
'name' => 'name',
'size' => 65530,
'size' => '65530',
'path' => 'name',
'link' => 'absolute-link',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => 27,
'permissions' => '27',
'mimetype' => 'image/png',
'preview-available' => 'yes',
'width' => 1234,
'height' => 4567,
'width' => '1234',
'height' => '4567',
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
}

Expand Down Expand Up @@ -760,11 +760,11 @@ public function testGetFileFromShareForOwner() {
'type' => 'file',
'id' => '54',
'name' => 'name',
'size' => 65520,
'size' => '65520',
'path' => 'path/to/file/name',
'link' => 'absolute-link-owner',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => 27,
'permissions' => '27',
'mimetype' => 'httpd/unix-directory',
'preview-available' => 'no',
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
Expand Down Expand Up @@ -847,11 +847,11 @@ public function testGetFileFromShareForRecipient() {
'type' => 'file',
'id' => '54',
'name' => 'different',
'size' => 65515,
'size' => '65515',
'path' => 'Shared/different',
'link' => 'absolute-link-owner',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => 27,
'permissions' => '27',
'mimetype' => 'application/octet-stream',
'preview-available' => 'no',
], self::invokePrivate($parser, 'getFileFromShare', [$participant, '23']));
Expand Down
Loading