Skip to content

Commit 63c0527

Browse files
committed
fix: detect file ext
1 parent 60a2200 commit 63c0527

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/app/shared/ui/file-change/file-change.component.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export class FileChangeComponent implements OnInit {
1414
this.initFileInput();
1515

1616
if ("launchQueue" in window) {
17-
console.log(`"launchQueue" in window`);
18-
1917
(window as any).launchQueue.setConsumer(async (launchParams: any) => {
18+
console.log(launchParams);
19+
2020
const file: File = launchParams.files[0];
2121
this.fileHandler(file)
2222
});
@@ -51,20 +51,16 @@ export class FileChangeComponent implements OnInit {
5151
}
5252

5353
getRouteType(file: File): string | undefined {
54-
const fileType = file.type
55-
56-
if (fileType) {
57-
if (fileType.search(/zip|cbz/) >= 0) return "zip"
58-
else if (fileType.includes('pdf')) return "pdf"
59-
} else {
60-
const fileName = file.name
61-
const extension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase();
62-
63-
return ['cbz', 'zip', 'pdf'].includes(extension) ? extension : undefined
64-
}
65-
66-
return;
54+
const fileType = file.type || file.name.split('.').pop()?.toLowerCase();
55+
56+
if (!fileType) return undefined;
57+
58+
if (fileType.includes('pdf')) return 'pdf';
59+
if (/zip|cbz/.test(fileType)) return 'zip';
60+
61+
return undefined;
6762
}
63+
6864
input = document.createElement('input')
6965

7066
initFileInput() {

0 commit comments

Comments
 (0)