@@ -17,18 +17,22 @@ limitations under the License.
17
17
// Pull in the encryption lib so that we can decrypt attachments.
18
18
import encrypt from 'browser-encrypt-attachment' ;
19
19
import { mediaFromContent } from "../customisations/Media" ;
20
- import { IEncryptedFile } from "../customisations/models/IMediaEventContent" ;
20
+ import { IEncryptedFile , IMediaEventInfo } from "../customisations/models/IMediaEventContent" ;
21
21
import { getBlobSafeMimeType } from "./blobs" ;
22
22
23
23
/**
24
24
* Decrypt a file attached to a matrix event.
25
- * @param {IEncryptedFile } file The json taken from the matrix event.
25
+ * @param {IEncryptedFile } file The encrypted file information taken from the matrix event.
26
26
* This passed to [link]{@link https://github.com/matrix-org/browser-encrypt-attachments}
27
27
* as the encryption info object, so will also have the those keys in addition to
28
28
* the keys below.
29
+ * @param {IMediaEventInfo } info The info parameter taken from the matrix event.
29
30
* @returns {Promise<Blob> } Resolves to a Blob of the file.
30
31
*/
31
- export function decryptFile ( file : IEncryptedFile ) : Promise < Blob > {
32
+ export function decryptFile (
33
+ file : IEncryptedFile ,
34
+ info ?: IMediaEventInfo ,
35
+ ) : Promise < Blob > {
32
36
const media = mediaFromContent ( { file } ) ;
33
37
// Download the encrypted file as an array buffer.
34
38
return media . downloadSource ( ) . then ( ( response ) => {
@@ -44,7 +48,7 @@ export function decryptFile(file: IEncryptedFile): Promise<Blob> {
44
48
// they introduce XSS attacks if the Blob URI is viewed directly in the
45
49
// browser (e.g. by copying the URI into a new tab or window.)
46
50
// See warning at top of file.
47
- let mimetype = file . mimetype ? file . mimetype . split ( ";" ) [ 0 ] . trim ( ) : '' ;
51
+ let mimetype = info ? .mimetype ? info . mimetype . split ( ";" ) [ 0 ] . trim ( ) : '' ;
48
52
mimetype = getBlobSafeMimeType ( mimetype ) ;
49
53
50
54
return new Blob ( [ dataArray ] , { type : mimetype } ) ;
0 commit comments