From 215a4dd662e23e99cbe4fcd82e031a38e7b2f347 Mon Sep 17 00:00:00 2001 From: leejinho Date: Thu, 13 Feb 2020 17:24:00 +0900 Subject: [PATCH] =?UTF-8?q?fake=20=EC=9D=B4=EB=AF=B8=EC=A7=80,=20=EB=8F=99?= =?UTF-8?q?=EC=98=81=EC=83=81=20=ED=8C=8C=EC=9D=BC=20=EA=B2=80=EC=A6=9D?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20(=EC=A4=91=EA=B0=84?= =?UTF-8?q?=EB=8B=A8=EA=B3=84=20=EA=B0=9C=EB=B0=9C=EC=A4=91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/lib/services/common-api.service.ts | 59 +++++++++++++++++++ .../components/messages.component.ts | 4 ++ 2 files changed, 63 insertions(+) diff --git a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts index 2490f24c..e6cb24ad 100644 --- a/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts +++ b/projects/ucap-webmessenger-api-common/src/lib/services/common-api.service.ts @@ -223,6 +223,65 @@ export class CommonApiService { }; } + public mimeCheckForImageAndVideoFiles(files: File[]) { + files.forEach(file => { + console.log(file); + const fileReader = new FileReader(); + fileReader.onloadend = () => { + const arr = new Uint8Array(fileReader.result as ArrayBuffer).subarray( + 0, + 4 + ); + let header = ''; + for (let i = 0; i < arr.length; i++) { + header += arr[i].toString(16); + } + console.log('File header: ' + header); + + // Check the file signature against known types + var type = 'unknown'; + // http://forensic-proof.com/archives/300?ckattempt=1 + + if (header.startsWith('89504e47')) { + // 89504E470D0A1A0A + type = 'image/png'; + } else if (header.startsWith('47494638')) { + // 474946383761 + // 474946383961 + type = 'image/gif'; + } else if (header.startsWith('ffd8ffe')) { + // ffd8ffe0 + // ffd8ffe1 + // ffd8ffe2 + // ffd8ffe8 + type = 'image/jpeg'; + } else if (header.startsWith('424d')) { + type = 'image/bmp'; + } else if (header.startsWith('4d4d') || header.startsWith('4949')) { + type = 'image/tiff'; + } else if (header.startsWith('4F676753')) { + // 4F67675300020000 + type = 'image/ogg'; + } else if (header.startsWith('38425053')) { + // 38 42 50 53 + type = 'image/psd'; + } else if (header.startsWith('25504446')) { + // 38 42 50 53 + type = 'image/ai'; + } else if (header.startsWith('52494646')) { + // avi + type = 'video/x-msvideo'; + } else if (header.startsWith('00000018')) { + // 0000001866747970 + type = 'video/x-msvideo'; + } + + console.log('type', type); + }; + fileReader.readAsArrayBuffer(file); + }); + } + public fileTalkShare( req: FileTalkShareRequest ): Observable { diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts index f3820a0d..1159d8dc 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts @@ -1107,6 +1107,10 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { } } + // this.commonApiService.mimeCheckForImageAndVideoFiles( + // fileUploadItems.map(fui => fui.file) + // ); + const checkExt = this.commonApiService.acceptableExtensionForFileTalk( fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name)) );