import { Injectable } from '@angular/core' ; import * as path from 'path' ; import { CollectionService } from '../collection/collection.service' ; import { Constants } from '../../core/constants' ; @ Injectable ( { providedIn : 'root' , } ) export class FileService { constructor ( private collection ) { } public isDroppingFiles ( dropEvent ) { return this . getDroppedFilesPaths ( dropEvent ) . length > 0 ; } public getDroppedFilesPaths ( dropEvent ) { const droppedFilesPaths = [ ] ; if ( dropEvent . dataTransfer . items ) { for ( let i = 0 ; i < dropEvent . dataTransfer . items . length ; i ++ ) { if ( dropEvent . dataTransfer . items [ i ] . kind === 'file' ) { const file = dropEvent . dataTransfer . items [ i ] . getAsFile ( ) ; droppedFilesPaths . push ( file . path ) ; } } } else { for ( let i = 0 ; i < dropEvent . dataTransfer . files . length ; i ++ ) { droppedFilesPaths . push ( dropEvent . dataTransfer . files [ i ] . path ) ; } } return droppedFilesPaths ; } public getNoteFilePaths ( filePaths ) { const noteFilePaths = filePaths . filter ( x => path . extname ( x ) === Constants . noteExportExtension ) ; return noteFilePaths ; } }