import defaultSettings from '../data/default_settings.json';
import buildGithubTokenUrl from './buildGithubTokenUrl';

export function filterOutputSettings(settings) {
  return Object.assign(
    {},
    settings,
    {
      defaultApiendpoint: defaultSettings.apiendpoint,
      defaultWebendpoint: defaultSettings.webendpoint,
      tokenUrl: buildGithubTokenUrl(settings.webendpoint),
      defaultInterval: defaultSettings.interval,
    }
  );
}

export function getSettingDataPromise() {
  return new Promise((resolve) => {
    const saved = window.localStorage.getItem('setting-data');
    if (!saved) {
      resolve({});
      return;
    }
    resolve(JSON.parse(saved));
  });
}

export function setSettingDataPromise(settingData) {
  return new Promise((resolve) => {
    window.localStorage.setItem('setting-data', JSON.stringify(settingData));
    resolve();
  });
}

@@ -110,16 +110,202 @@
 kenUrl';
+%0Aimport %7B databaseName %7D from '../../package.json';%0Aimport levelup from 'levelup';%0Aimport sub from 'level-sublevel';%0Aimport leveljs from 'level-js';%0Aconst settingsNameSpace = 'settings';
 %0A%0Aexport
@@ -694,32 +694,40 @@
 Promise((resolve
+, reject
 ) =%3E %7B%0A    const
@@ -731,79 +731,297 @@
 nst 
-saved = window.localStorage.getItem('setting-data');%0A    if (!saved) %7B%0A
+db = sub(levelup(databaseName, %7Bdb: leveljs, valueEncoding: 'json'%7D));%0A    try %7B%0A      const settings = db.sublevel(settingsNameSpace);%0A      settings.get('setting-data', (err, value) =%3E %7B%0A        if (err) %7B%0A          if (err.notFound) %7B%0A            // handle a 'NotFoundError' here%0A      
     
@@ -1041,16 +1041,22 @@
 ;%0A      
+  
+    
 return;%0A
@@ -1063,41 +1063,175 @@
     
+   
+   
 %7D%0A    
-resolve(JSON.parse(saved));
+      reject(err);%0A          return;%0A        %7D%0A        resolve(value);%0A      %7D);%0A    %7D finally %7B%0A      if (db.isOpen()) %7B%0A        db.close();%0A      %7D%0A    %7D
 %0A  %7D
@@ -1231,25 +1231,24 @@
   %7D%0A  %7D);%0A%7D%0A
-%0A
 export funct
@@ -1317,16 +1317,24 @@
 (resolve
+, reject
 ) =%3E %7B%0A 
@@ -1340,96 +1340,394 @@
     
-window.localStorage.setItem('setting-data', JSON.stringify(settingData));%0A    resolve();
+const db = sub(levelup(databaseName, %7Bdb: leveljs, valueEncoding: 'json'%7D));%0A    try %7B%0A      const settings = db.sublevel(settingsNameSpace);%0A      settings.put('setting-data', settingData, (err, value) =%3E %7B%0A        if (err) %7B%0A          reject(err);%0A          return;%0A        %7D%0A        resolve(value);%0A      %7D);%0A    %7D finally %7B%0A      if (db.isOpen()) %7B%0A        db.close();%0A      %7D%0A    %7D
 %0A  %7D

use indexeddb instead of localstorage