Skip to content

Commit 4b4d30c

Browse files
committed
WIP HEIC display
1 parent 10f72c8 commit 4b4d30c

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

client/MessageHEIC.coffee

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, {useEffect, useRef, useState} from 'react'
2+
import {useTracker} from 'meteor/react-meteor-data'
3+
4+
import {ErrorBoundary} from './ErrorBoundary'
5+
6+
heic = null # will become import of 'libheif-web'
7+
8+
export MessageHEIC = ({file}) ->
9+
<ErrorBoundary>
10+
<WrappedMessageHEIC file={file}/>
11+
</ErrorBoundary>
12+
MessageHEIC.displayName = 'MessageHEIC'
13+
14+
WrappedMessageHEIC = React.memo ({file}) ->
15+
[pngBlob, setPngBlob] = useState()
16+
[url, setUrl] = useState()
17+
18+
useTracker =>
19+
## Load libheif-web
20+
unless heic?
21+
Session.set 'heicLoading', true
22+
Session.get 'heicLoading' # rerun tracker once libheif-web loaded
23+
return import('libheif-web').then (imported) ->
24+
heic = window.heic = imported
25+
heic.useUrl '/libheif.min.js'
26+
Session.set 'heicLoading', false
27+
## Load HEIC file
28+
fileData = findFile file
29+
return unless fileData?
30+
fetch urlToInternalFile file
31+
.then (response) => response.blob()
32+
.then (blob) =>
33+
heic.convertHeif blob, file.filename + '.png', 'image/png'
34+
.then (png) => setPngBlob png
35+
, [file]
36+
useEffect =>
37+
return unless pngBlob?
38+
url = setUrl URL.createObjectURL pngBlob
39+
=> URL.revokeObjectURL url
40+
, [pngBlob]
41+
42+
if url
43+
<img src={url}/>
44+
else
45+
null
46+
WrappedMessageHEIC.displayName = 'WrappedMessageHEIC'

client/message.coffee

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {Credits} from './layout.coffee'
1313
import {ErrorBoundary} from './ErrorBoundary'
1414
import {FormatDate, formatDate} from './lib/date'
1515
import {ignoreKey} from './keyboard'
16+
import {MessageHEIC} from './MessageHEIC'
1617
import {MessageImage, imageTransform, messageRotate} from './MessageImage'
1718
import {MessagePDF} from './MessagePDF'
1819
import {TagEdit} from './TagEdit'
@@ -2858,8 +2859,11 @@ export WrappedSubmessage = React.memo ({message, read}) ->
28582859
menu={can.edit} tabindex={tabindex0+9}/>
28592860
}
28602861
<div className="bodyFile">
2861-
{if messageFileType == 'pdf'
2862-
<MessagePDF file={historified.file}/>
2862+
{switch messageFileType
2863+
when 'pdf'
2864+
<MessagePDF file={historified.file}/>
2865+
when 'heic'
2866+
<MessageHEIC file={historified.file}/>
28632867
}
28642868
{if historified.file
28652869
<>

lib/files.coffee

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ export messageFileUrlPrefixPattern =
9393
switch file?.contentType
9494
when 'image/gif', 'image/jpeg', 'image/png', 'image/svg+xml', 'image/webp', 'image/x-icon'
9595
'image'
96+
when 'image/heic', 'image/heif'#, 'image/heic-sequence', 'image/heif-sequence'
97+
'heic'
9698
when 'video/mp4', 'video/ogg', 'video/webm'
9799
'video'
98100
when 'application/pdf'

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
"dompurify": "2.5.8",
4242
"exif-parser": "^0.1.12",
4343
"file-saver": "^2.0.5",
44+
"heic-to": "1.1.5",
4445
"highlight.js": "^10.7.2",
4546
"jquery": "^3.5.1",
4647
"js-cookie": "^2.2.1",
4748
"jsdom": "^19.0.0",
4849
"jszip": "^3.2.2",
4950
"katex": "0.16.21",
51+
"libheif-web": "^1.0.2",
5052
"markdown-it": "13.0.1",
5153
"markdown-it-anchor": "8.6.4",
5254
"markdown-it-replacements": "1.0.2",

0 commit comments

Comments
 (0)