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

feat: Added blurhash to image metadata #13009

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin
$data['width'] = (string) $sizeMetadata['width'];
$data['height'] = (string) $sizeMetadata['height'];
}

if (isset($sizeMetadata['blurhash'])) {
$data['blurhash'] = $sizeMetadata['blurhash'];
nickvergessen marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (FilesMetadataNotFoundException) {
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
* permissions?: string,
* width?: string,
* height?: string,
* blurhash?: string,
* }
*
* @psalm-type TalkBaseMessage = array{
Expand Down
10 changes: 8 additions & 2 deletions lib/Share/Helper/FilesMetadataCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use OCP\FilesMetadata\Model\IFilesMetadata;

class FilesMetadataCache {
/** @var array<int, ?array{width: int, height: int}> */
/** @var array<int, ?array{width: int, height: int, blurhash?: string}> */
protected array $filesSizeData = [];

public function __construct(
Expand All @@ -41,7 +41,7 @@ public function preloadMetadata(array $fileIds): void {
/**
* @param int $fileId
* @return array
* @psalm-return array{width: int, height: int}
* @psalm-return array{width: int, height: int, blurhash?: string}
* @throws FilesMetadataNotFoundException
*/
public function getMetadataPhotosSizeForFileId(int $fileId): array {
Expand Down Expand Up @@ -75,6 +75,12 @@ protected function cachePhotosSize(int $fileId, IFilesMetadata $metadata): void
'width' => $sizeMetadata['width'],
'height' => $sizeMetadata['height'],
];

// Retrieve Blurhash from metadata (if present)
if ($metadata->hasKey('blurhash')) {
$dimensions['blurhash'] = $metadata->getString('blurhash');
}

$this->filesSizeData[$fileId] = $dimensions;
} else {
$this->filesSizeData[$fileId] = null;
Expand Down
3 changes: 3 additions & 0 deletions openapi-backend-sipbridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@
},
"height": {
"type": "string"
},
"blurhash": {
"type": "string"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions openapi-federation.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,9 @@
},
"height": {
"type": "string"
},
"blurhash": {
"type": "string"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,9 @@
},
"height": {
"type": "string"
},
"blurhash": {
"type": "string"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,9 @@
},
"height": {
"type": "string"
},
"blurhash": {
"type": "string"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-backend-sipbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export type components = {
permissions?: string;
width?: string;
height?: string;
blurhash?: string;
};
Room: {
actorId: string;
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export type components = {
permissions?: string;
width?: string;
height?: string;
blurhash?: string;
};
Room: {
actorId: string;
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@ export type components = {
permissions?: string;
width?: string;
height?: string;
blurhash?: string;
};
Room: {
actorId: string;
Expand Down
1 change: 1 addition & 0 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ export type components = {
permissions?: string;
width?: string;
height?: string;
blurhash?: string;
};
Room: {
actorId: string;
Expand Down
77 changes: 77 additions & 0 deletions tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,83 @@ public function testGetFileFromShareForGuest(): void {
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
}

public function testGetFileFromShareForGuestWithBlurhash(): void {
$room = $this->createMock(Room::class);
$node = $this->createMock(Node::class);
$node->expects($this->once())
->method('getId')
->willReturn(54);
$node->expects($this->once())
->method('getName')
->willReturn('name');
$node->expects($this->atLeastOnce())
->method('getMimeType')
->willReturn('image/png');
$node->expects($this->once())
->method('getSize')
->willReturn(65530);
$node->expects($this->once())
->method('getEtag')
->willReturn(md5('etag'));
$node->expects($this->once())
->method('getPermissions')
->willReturn(27);

$share = $this->createMock(IShare::class);
$share->expects($this->once())
->method('getNode')
->willReturn($node);
$share->expects($this->once())
->method('getToken')
->willReturn('token');

$this->shareProvider->expects($this->once())
->method('getShareById')
->with('23')
->willReturn($share);

$this->url->expects($this->once())
->method('linkToRouteAbsolute')
->with('files_sharing.sharecontroller.showShare', [
'token' => 'token',
])
->willReturn('absolute-link');

$this->previewManager->expects($this->once())
->method('isAvailable')
->with($node)
->willReturn(true);

$this->filesMetadataCache->expects($this->once())
->method('getMetadataPhotosSizeForFileId')
->with(54)
->willReturn([
'width' => 1234,
'height' => 4567,
'blurhash' => 'LEHV9uae2yk8pyo0adR*.7kCMdnj'
]);

$participant = $this->createMock(Participant::class);

$parser = $this->getParser();

$this->assertSame([
'type' => 'file',
'id' => '54',
'name' => 'name',
'size' => '65530',
'path' => 'name',
'link' => 'absolute-link',
'etag' => '1872ade88f3013edeb33decd74a4f947',
'permissions' => '27',
'mimetype' => 'image/png',
'preview-available' => 'yes',
'width' => '1234',
'height' => '4567',
'blurhash' => 'LEHV9uae2yk8pyo0adR*.7kCMdnj',
], self::invokePrivate($parser, 'getFileFromShare', [$room, $participant, '23']));
}

public function testGetFileFromShareForOwner(): void {
$room = $this->createMock(Room::class);
$node = $this->createMock(Node::class);
Expand Down
Loading