| 4 | import { SmartQueryResult } from '../Models'; |
| 5 | |
| 6 | export class LocalClient implements MetadataClient { |
| 7 | files: FileWithDirectoryAndFileHandle[]; |
| 8 | |
| 9 | constructor(files: FileWithDirectoryAndFileHandle[]) { |
| 10 | this.files = files; |
| 11 | } |
| 12 | |
| 13 | track(account: string, container: string, filepath: string): Promise<Track> { |
| 14 | throw new Error('track not supported for blob data sources'); |
| 15 | } |
| 16 | |
| 17 | async getMetaFromFile( |
| 18 | file: FileWithDirectoryAndFileHandle, |
| 19 | dataFile: FileWithDirectoryAndFileHandle, |
| 20 | account: string, |
| 21 | container: string |
| 22 | ) { |
| 23 | const fileContent = await file.text(); |
| 24 | let metadata = Object.assign(new SigMFMetadata(), JSON.parse(fileContent)) as SigMFMetadata; |
| 25 | metadata.dataFileHandle = dataFile; |
| 26 | metadata.metadataFileHandle = file; |
| 27 | const origin: TraceabilityOrigin = metadata.global['traceability:origin']; |
| 28 | if (!origin) { |
| 29 | metadata.global['traceability:origin'] = { |
| 30 | type: 'local', |
| 31 | account: account, |
| 32 | container: container, |
| 33 | file_path: !file.webkitRelativePath |
| 34 | ? file.name.replace('.sigmf-meta', '') |
| 35 | : file.webkitRelativePath.replace('.sigmf-meta', ''), |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | if (!metadata.global['traceability:sample_length']) { |
| 40 | metadata.global['traceability:sample_length'] = Math.round(dataFile.size / metadata.getBytesPerIQSample()); |
| 41 | } |
| 42 | metadata.annotations = metadata.annotations.map((annotation) => Object.assign(new Annotation(), annotation)); |
| 43 | metadata.captures = metadata.captures.map((capture) => Object.assign(new CaptureSegment(), capture)); |
| 44 | console.debug('getMetaFromFile', metadata); |
| 45 | return metadata; |
| 46 | } |
| 47 | |
| 48 | async getDataSourceMetaPaths(account: string, container: string): Promise<string[]> { |
| 49 | if (!this.files) { |
| 50 | return Promise.reject('No local directory found'); |
| 51 | } |
| 52 | const localFiles: FileWithDirectoryAndFileHandle[] = this.files; |
| 53 | let result: string[] = []; |
| 54 | for (let i = 0; i < localFiles.length; i++) { |
| 55 | const file = localFiles[i]; |
| 56 | if (file.name.split('.').pop() !== 'sigmf-meta') { |
| 57 | continue; |
| 58 | } |
| 59 | // check if there is a corresponding sigmf-data file |
| 60 | const dataFile = localFiles.find((f) => f.name === file.name.replace('.sigmf-meta', '.sigmf-data')); |
| 61 | if (!dataFile) { |
| 62 | continue; |
| 63 | } |
nothing calls this directly
no outgoing calls
no test coverage detected