check mime is added

This commit is contained in:
richard-loafle 2020-02-14 09:30:31 +09:00
parent 7f1218dcf4
commit 7ffe9d4561
5 changed files with 134 additions and 26 deletions

85
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "ucap-webmessenger", "name": "ucap-webmessenger",
"version": "0.0.19", "version": "0.0.20",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -3281,6 +3281,11 @@
"defer-to-connect": "^1.0.1" "defer-to-connect": "^1.0.1"
} }
}, },
"@tokenizer/token": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@tokenizer/token/-/token-0.1.1.tgz",
"integrity": "sha512-XO6INPbZCxdprl+9qa/AAbFFOMzzwqYxpjPgLICrMD6C2FCw6qfJOPcBk6JqqPLSaZ/Qx87qn4rpPmPMwaAK6w=="
},
"@tweenjs/tween.js": { "@tweenjs/tween.js": {
"version": "17.4.0", "version": "17.4.0",
"resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-17.4.0.tgz", "resolved": "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-17.4.0.tgz",
@ -3334,8 +3339,7 @@
"@types/debug": { "@types/debug": {
"version": "4.1.5", "version": "4.1.5",
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.5.tgz",
"integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ==", "integrity": "sha512-Q1y515GcOdTHgagaVFhHnIFQ38ygs/kmxdNpvpou+raI9UO3YZcHDngBSYKQklcKlvA7iuQlmIKbzvmxcOE9CQ=="
"dev": true
}, },
"@types/detect-browser": { "@types/detect-browser": {
"version": "4.0.0", "version": "4.0.0",
@ -3388,6 +3392,15 @@
"integrity": "sha512-g1QUuhYVVAamfCifK7oB7G3aIl4BbOyzDOqVyUfEr4tfBKrXfeH+M+Tg7HKCXSrbzxYdhyCP7z9WbKo0R2hBCw==", "integrity": "sha512-g1QUuhYVVAamfCifK7oB7G3aIl4BbOyzDOqVyUfEr4tfBKrXfeH+M+Tg7HKCXSrbzxYdhyCP7z9WbKo0R2hBCw==",
"dev": true "dev": true
}, },
"@types/file-type": {
"version": "10.9.1",
"resolved": "https://registry.npmjs.org/@types/file-type/-/file-type-10.9.1.tgz",
"integrity": "sha512-oq0fy8Jqj19HofanFsZ56o5anMDUQtFO9B3wfLqM9o42RyCe1WT+wRbSvRbL2l8ARZXNaJturHk0b442+0yi+g==",
"dev": true,
"requires": {
"file-type": "*"
}
},
"@types/filesize": { "@types/filesize": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/@types/filesize/-/filesize-4.2.0.tgz", "resolved": "https://registry.npmjs.org/@types/filesize/-/filesize-4.2.0.tgz",
@ -4584,8 +4597,7 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
"dev": true
}, },
"base": { "base": {
"version": "0.11.2", "version": "0.11.2",
@ -4870,7 +4882,6 @@
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -5647,8 +5658,7 @@
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
"dev": true
}, },
"concat-stream": { "concat-stream": {
"version": "1.6.2", "version": "1.6.2",
@ -7811,6 +7821,17 @@
"integrity": "sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw==", "integrity": "sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw==",
"dev": true "dev": true
}, },
"file-type": {
"version": "14.1.2",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-14.1.2.tgz",
"integrity": "sha512-9NI4+QzDlEPB6OETc/FcJt8i8vNT396VweRwEwLcE07MnorWkZDopNuc+MeoYA7ArbzoK044JbaDExWys8deTQ==",
"requires": {
"readable-web-to-node-stream": "^2.0.0",
"strtok3": "^6.0.0",
"token-types": "^2.0.0",
"typedarray-to-buffer": "^3.1.5"
}
},
"file-uri-to-path": { "file-uri-to-path": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
@ -8099,8 +8120,7 @@
"fs.realpath": { "fs.realpath": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
"dev": true
}, },
"fsevents": { "fsevents": {
"version": "2.0.7", "version": "2.0.7",
@ -8155,7 +8175,6 @@
"version": "7.1.4", "version": "7.1.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
"integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==", "integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",
"dev": true,
"requires": { "requires": {
"fs.realpath": "^1.0.0", "fs.realpath": "^1.0.0",
"inflight": "^1.0.4", "inflight": "^1.0.4",
@ -8713,8 +8732,7 @@
"ieee754": { "ieee754": {
"version": "1.1.13", "version": "1.1.13",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==", "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
"dev": true
}, },
"iferr": { "iferr": {
"version": "0.1.5", "version": "0.1.5",
@ -8815,7 +8833,6 @@
"version": "1.0.6", "version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"dev": true,
"requires": { "requires": {
"once": "^1.3.0", "once": "^1.3.0",
"wrappy": "1" "wrappy": "1"
@ -8824,8 +8841,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
"dev": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -11158,7 +11174,6 @@
"version": "3.0.4", "version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -11891,7 +11906,6 @@
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"dev": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -12356,6 +12370,11 @@
"sha.js": "^2.4.8" "sha.js": "^2.4.8"
} }
}, },
"peek-readable": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/peek-readable/-/peek-readable-3.1.0.tgz",
"integrity": "sha512-KGuODSTV6hcgdZvDrIDBUkN0utcAVj1LL7FfGbM0viKTtCHmtZcuEJ+lGqsp0fTFkGqesdtemV2yUSMeyy3ddA=="
},
"pend": { "pend": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",
@ -13164,6 +13183,11 @@
"util-deprecate": "~1.0.1" "util-deprecate": "~1.0.1"
} }
}, },
"readable-web-to-node-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/readable-web-to-node-stream/-/readable-web-to-node-stream-2.0.0.tgz",
"integrity": "sha512-+oZJurc4hXpaaqsN68GoZGQAQIA3qr09Or4fqEsargABnbe5Aau8hFn6ISVleT3cpY/0n/8drn7huyyEvTbghA=="
},
"readdir-scoped-modules": { "readdir-scoped-modules": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/readdir-scoped-modules/-/readdir-scoped-modules-1.1.0.tgz", "resolved": "https://registry.npmjs.org/readdir-scoped-modules/-/readdir-scoped-modules-1.1.0.tgz",
@ -14859,6 +14883,17 @@
"integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=",
"dev": true "dev": true
}, },
"strtok3": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/strtok3/-/strtok3-6.0.0.tgz",
"integrity": "sha512-ZXlmE22LZnIBvEU3n/kZGdh770fYFie65u5+2hLK9s74DoFtpkQIdBZVeYEzlolpGa+52G5IkzjUWn+iXynOEQ==",
"requires": {
"@tokenizer/token": "^0.1.1",
"@types/debug": "^4.1.5",
"debug": "^4.1.1",
"peek-readable": "^3.1.0"
}
},
"style-loader": { "style-loader": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/style-loader/-/style-loader-1.0.0.tgz", "resolved": "https://registry.npmjs.org/style-loader/-/style-loader-1.0.0.tgz",
@ -15148,7 +15183,6 @@
"version": "0.1.0", "version": "0.1.0",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.1.0.tgz",
"integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==", "integrity": "sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw==",
"dev": true,
"requires": { "requires": {
"rimraf": "^2.6.3" "rimraf": "^2.6.3"
}, },
@ -15157,7 +15191,6 @@
"version": "2.7.1", "version": "2.7.1",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
"integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
"dev": true,
"requires": { "requires": {
"glob": "^7.1.3" "glob": "^7.1.3"
} }
@ -15235,6 +15268,15 @@
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==", "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==",
"dev": true "dev": true
}, },
"token-types": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/token-types/-/token-types-2.0.0.tgz",
"integrity": "sha512-WWvu8sGK8/ZmGusekZJJ5NM6rRVTTDO7/bahz4NGiSDb/XsmdYBn6a1N/bymUHuWYTWeuLUg98wUzvE4jPdCZw==",
"requires": {
"@tokenizer/token": "^0.1.0",
"ieee754": "^1.1.13"
}
},
"tough-cookie": { "tough-cookie": {
"version": "2.4.3", "version": "2.4.3",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
@ -17720,8 +17762,7 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
"dev": true
}, },
"write-file-atomic": { "write-file-atomic": {
"version": "2.4.3", "version": "2.4.3",

View File

@ -48,6 +48,7 @@
"electron-store": "^5.1.0", "electron-store": "^5.1.0",
"electron-updater": "^4.2.0", "electron-updater": "^4.2.0",
"electron-window-state": "^5.0.3", "electron-window-state": "^5.0.3",
"file-type": "^14.1.2",
"fs-extra": "^8.1.0", "fs-extra": "^8.1.0",
"rxjs": "^6.5.4", "rxjs": "^6.5.4",
"semver": "^6.3.0", "semver": "^6.3.0",
@ -88,6 +89,7 @@
"@types/electron-debug": "^2.1.0", "@types/electron-debug": "^2.1.0",
"@types/electron-devtools-installer": "^2.2.0", "@types/electron-devtools-installer": "^2.2.0",
"@types/extract-text-webpack-plugin": "^3.0.4", "@types/extract-text-webpack-plugin": "^3.0.4",
"@types/file-type": "^10.9.1",
"@types/file-saver": "^2.0.1", "@types/file-saver": "^2.0.1",
"@types/filesize": "^4.1.0", "@types/filesize": "^4.1.0",
"@types/fs-extra": "^8.0.1", "@types/fs-extra": "^8.0.1",

View File

@ -72,7 +72,7 @@ import {
import { _MODULE_CONFIG } from '../config/token'; import { _MODULE_CONFIG } from '../config/token';
import { ModuleConfig } from '../config/module-config'; import { ModuleConfig } from '../config/module-config';
import { Urls } from '../config/urls'; import { Urls } from '../config/urls';
import { UrlConfig } from '@ucap-webmessenger/core'; import { UrlConfig, MimeUtil } from '@ucap-webmessenger/core';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -223,6 +223,35 @@ export class CommonApiService {
}; };
} }
public acceptableMimeForFileTalk(
files: File[]
): Promise<{ accept: boolean; rejected: string[] }> {
return new Promise<{ accept: boolean; rejected: string[] }>(
async (resolve, reject) => {
let accept = true;
const rejected: string[] = [];
for (const file of files) {
const info = await MimeUtil.getMimeFromBlob(file);
if (
!file ||
-1 ===
this.moduleConfig.acceptableFileExtensions.indexOf(
info.ext.toLocaleLowerCase()
)
) {
rejected.push(info.ext);
accept = false;
}
}
resolve({
accept,
rejected
});
}
);
}
public mimeCheckForImageAndVideoFiles(files: File[]) { public mimeCheckForImageAndVideoFiles(files: File[]) {
files.forEach(file => { files.forEach(file => {
console.log(file); console.log(file);

View File

@ -1111,14 +1111,36 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
// fileUploadItems.map(fui => fui.file) // fileUploadItems.map(fui => fui.file)
// ); // );
const checkExt = this.commonApiService.acceptableExtensionForFileTalk( const checkExt = await this.commonApiService.acceptableMimeForFileTalk(
fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name)) fileUploadItems.map(fui => fui.file)
); );
// const checkExt = this.commonApiService.acceptableExtensionForFileTalk(
// fileUploadItems.map(fui => FileUtil.getExtension(fui.file.name))
// );
if (!checkExt.accept) { if (!checkExt.accept) {
if (!!this.fileUploadQueue) { if (!!this.fileUploadQueue) {
this.fileUploadQueue.onUploadComplete(); this.fileUploadQueue.onUploadComplete();
} }
// this.snackBarService.openFromComponent<
// AlertSnackbarComponent,
// AlertSnackbarData
// >(AlertSnackbarComponent, {
// duration: 1000,
// verticalPosition: 'bottom',
// horizontalPosition: 'center',
// data: {
// html: this.translateService.instant(
// 'common.file.errors.notSupporedType',
// {
// supporedType:
// checkExt.reject.length > 0 ? checkExt.reject.join(',') : ''
// }
// )
// }
// });
this.snackBarService.openFromComponent< this.snackBarService.openFromComponent<
AlertSnackbarComponent, AlertSnackbarComponent,
AlertSnackbarData AlertSnackbarData
@ -1131,7 +1153,7 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit {
'common.file.errors.notSupporedType', 'common.file.errors.notSupporedType',
{ {
supporedType: supporedType:
checkExt.reject.length > 0 ? checkExt.reject.join(',') : '' checkExt.rejected.length > 0 ? checkExt.rejected.join(',') : ''
} }
) )
} }

View File

@ -1,3 +1,5 @@
import * as FileType from 'file-type/browser';
const MimeMap: Map<string, string> = new Map([ const MimeMap: Map<string, string> = new Map([
['123', 'application/vnd.lotus-1-2-3'], ['123', 'application/vnd.lotus-1-2-3'],
['3dml', 'text/vnd.in3d.3dml'], ['3dml', 'text/vnd.in3d.3dml'],
@ -871,4 +873,16 @@ export class MimeUtil {
static getMimeFromExtension(ext: string): string | undefined { static getMimeFromExtension(ext: string): string | undefined {
return MimeMap.get(ext); return MimeMap.get(ext);
} }
static getMimeFromBlob(blob: Blob) {
return FileType.fromBlob(blob);
}
static getMimeFromBuffer(buffer: Buffer) {
return FileType.fromBuffer(buffer);
}
static getMimeFromStream(stream: ReadableStream) {
return FileType.fromStream(stream);
}
} }