Skip to content

Commit

Permalink
Merge pull request #27 from chytanka/develop
Browse files Browse the repository at this point in the history
fix: detect file ext
  • Loading branch information
rodzyk authored Sep 26, 2024
2 parents 3626b5e + 63c0527 commit 64aebe5
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/app/shared/ui/file-change/file-change.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export class FileChangeComponent implements OnInit {
this.initFileInput();

if ("launchQueue" in window) {
console.log(`"launchQueue" in window`);

(window as any).launchQueue.setConsumer(async (launchParams: any) => {
console.log(launchParams);

const file: File = launchParams.files[0];
this.fileHandler(file)
});
Expand Down Expand Up @@ -51,20 +51,16 @@ export class FileChangeComponent implements OnInit {
}

getRouteType(file: File): string | undefined {
const fileType = file.type

if (fileType) {
if (fileType.search(/zip|cbz/) >= 0) return "zip"
else if (fileType.includes('pdf')) return "pdf"
} else {
const fileName = file.name
const extension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase();

return ['cbz', 'zip', 'pdf'].includes(extension) ? extension : undefined
}

return;
const fileType = file.type || file.name.split('.').pop()?.toLowerCase();

if (!fileType) return undefined;

if (fileType.includes('pdf')) return 'pdf';
if (/zip|cbz/.test(fileType)) return 'zip';

return undefined;
}

input = document.createElement('input')

initFileInput() {
Expand Down

0 comments on commit 64aebe5

Please sign in to comment.