| 7586 | return new Promise((resolve, reject) => { |
| 7587 | const reader = new FileReader(); |
| 7588 | reader.onerror = () => reject(reader.error); |
| 7589 | reader.onload = () => resolve(reader.result || ''); |
| 7590 | reader.readAsText(file); |
| 7591 | }); |
| 7592 | } |
| 7593 | |
| 7594 | function promptForBackupFile() { |
| 7595 | return new Promise((resolve) => { |
| 7596 | const input = document.createElement('input'); |
| 7597 | input.type = 'file'; |
| 7598 | input.accept = '.db'; |
| 7599 | input.style.display = 'none'; |
| 7600 | input.addEventListener('change', () => { |
| 7601 | const file = input.files && input.files[0] ? input.files[0] : null; |
| 7602 | input.remove(); |
| 7603 | resolve(file); |
| 7604 | }); |
| 7605 | document.body.appendChild(input); |
| 7606 | input.click(); |
| 7607 | }); |
| 7608 | } |
| 7609 | |
| 7610 | function promptForLibraryImportFile() { |
| 7611 | return new Promise((resolve) => { |
| 7612 | const input = document.createElement('input'); |
| 7613 | input.type = 'file'; |
| 7614 | input.accept = '.json,application/json'; |
| 7615 | input.style.display = 'none'; |
| 7616 | input.addEventListener('change', () => { |
| 7617 | const file = input.files && input.files[0] ? input.files[0] : null; |
| 7618 | input.remove(); |