(callback)
| 784 | const storageKeys = Object.keys(storageDefault); |
| 785 | |
| 786 | function start(callback) |
| 787 | { |
| 788 | ejs.setDataPath(storagePath); |
| 789 | |
| 790 | ejs.getMany(storageKeys, function(error, data) { |
| 791 | |
| 792 | // if(error) throw error; |
| 793 | |
| 794 | const setup = !data?.config?.appVersion; // Check if this is the first run |
| 795 | |
| 796 | const _appVersion = data?.config?.appVersion || false; |
| 797 | const _changes = data?.config.changes || false; |
| 798 | |
| 799 | if(!setup && _changes != changes) |
| 800 | { |
| 801 | const migration = require(p.join(appDir, 'scripts/migration.js')); |
| 802 | data = migration.start(data); |
| 803 | } |
| 804 | |
| 805 | for(const key of storageKeys) |
| 806 | { |
| 807 | if(setup) |
| 808 | { |
| 809 | if(key == 'config') |
| 810 | storageDefault[key].language = getLocaleUserLanguage(); |
| 811 | |
| 812 | let baseData = false; |
| 813 | |
| 814 | switch (key) |
| 815 | { |
| 816 | case 'opdsCatalogs': |
| 817 | |
| 818 | baseData = opds.addNewDefaultCatalogs({opdsCatalogs: []}, 0).opdsCatalogs; |
| 819 | |
| 820 | break; |
| 821 | } |
| 822 | |
| 823 | const newData = updateStorageMD(baseData, storageDefault[key]); |
| 824 | |
| 825 | ejs.set(key, newData, function(error){}); |
| 826 | storageJson[key] = newData; |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | if(_appVersion != _package.version || _changes != changes) |
| 831 | { |
| 832 | if(key == 'config') |
| 833 | storageDefault[key].language = getLocaleUserLanguage(); |
| 834 | |
| 835 | const newData = (_changes != changes) ? updateStorageMD(data[key], storageDefault[key]) : data[key]; |
| 836 | |
| 837 | if(key == 'config') |
| 838 | { |
| 839 | newData.appVersion = _package.version; |
| 840 | newData.changes = changes; |
| 841 | } |
| 842 | |
| 843 | ejs.set(key, newData, function(error){}); |
nothing calls this directly
no test coverage detected