Skip to content

Commit 7ffc168

Browse files
Merge pull request #4199 from nextcloud/feat/webp-avatars
feat: add support for webp contact avatars
2 parents d9304c8 + e41a2e1 commit 7ffc168

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/components/ContactDetails/ContactDetailsAvatar.vue

+11-3
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,20 @@ export default {
309309
*/
310310
getMimetype(uint) {
311311
const bytes = []
312-
uint.slice(0, 4).forEach((byte) => {
313-
bytes.push(byte.toString(16))
312+
uint.slice(0, 12).forEach((byte) => {
313+
bytes.push(byte.toString(16).padStart(2, '0'))
314314
})
315315
const hex = bytes.join('').toUpperCase()
316316

317-
switch (hex) {
317+
const nextcloudMajorVersion = parseInt(window.OC.config.version.split('.')[0])
318+
if (nextcloudMajorVersion >= 31
319+
&& hex.slice(0, 8) === '52494646'
320+
&& hex.slice(16, 24) === '57454250'
321+
) {
322+
return 'image/webp'
323+
}
324+
325+
switch (hex.slice(0, 8)) {
318326
case '89504E47':
319327
return 'image/png'
320328
case '47494638':

0 commit comments

Comments
 (0)