Get all data and set a blank value if it doesn't exist yet.
This commit is contained in:
		
							parent
							
								
									7cc22f8b11
								
							
						
					
					
						commit
						ec72d1bc01
					
				
					 1 changed files with 23 additions and 12 deletions
				
			
		|  | @ -117,8 +117,21 @@ class global { | |||
| 		}; | ||||
| 
 | ||||
| 		// Get all data and set a blank value if it doesn't exist yet.
 | ||||
| 		DATA_ALL = await global.read(null, CLOUD); | ||||
| 		DATA_ALL = ((DATA_ALL != null && DATA_ALL != undefined && (typeof DATA_ALL).includes(`obj`)) ? Object.keys(DATA_ALL).length <= 0 : true) | ||||
| 		if (CLOUD == 0  || CLOUD == null) { | ||||
| 			const ORIGINS = {}; | ||||
| 			ORIGINS[-1] = `local`; | ||||
| 			ORIGINS[1] = `global`; | ||||
| 			 | ||||
| 			for (let SOURCE = -1; SOURCE != 0 && SOURCE < 2; SOURCE = SOURCE + 2) { | ||||
| 				DATA_ALL[ORIGINS[SOURCE]] = await global.read(null, CLOUD); | ||||
| 			}; | ||||
| 			 | ||||
| 			CLOUD = (DATA_ALL[`local`] != null) ? -1 : 1;  | ||||
| 		} else { | ||||
| 			DATA_ALL = await global.read(null, CLOUD); | ||||
| 		}; | ||||
| 		 | ||||
| 		DATA_ALL = ((!(typeof DATA_ALL).includes(`undef`)) ? ((DATA_ALL != null && (typeof DATA_ALL).includes(`obj`)) ? Object.keys(DATA_ALL).length <= 0 : true) : false) | ||||
| 			? {} | ||||
| 			: DATA_ALL; | ||||
| 		 | ||||
|  | @ -130,15 +143,14 @@ class global { | |||
| 		// Merge!
 | ||||
| 		DATA_INJECTED = nested.dictionary.set(DATA_ALL, (DATA_NAME != null) ? [...DATA_NAME] : DATA_NAME, data, OPTIONS); | ||||
| 
 | ||||
| 		// If cloud is not selected, get where the data is already existent.
 | ||||
| 		(CLOUD == 0 || CLOUD == null) | ||||
| 			? (CLOUD = (DATA_ALL[`local`] != null) ? -1 : 1) | ||||
| 			: false; | ||||
| 
 | ||||
| 		// Write!
 | ||||
| 		await chrome.storage[(CLOUD > 0) ? `sync` : `local`].set(DATA_INJECTED); | ||||
| 		GUI_INFO[`log`] ? GUI_INFO[`log`].clear() : false; | ||||
| 		return ((OPTIONS[`verify`] != null ? (OPTIONS[`verify`]) : true) ? await verify(DATA_NAME, data) : true); | ||||
| 		return(chrome.storage[(CLOUD > 0) ? `sync` : `local`].set(DATA_INJECTED).then(async () => { | ||||
| 			GUI_INFO[`log`] ? GUI_INFO[`log`].clear() : false; | ||||
| 			return (((OPTIONS[`verify`] != null ? (OPTIONS[`verify`]) : true) ? await verify(DATA_NAME, data, OPTIONS) : true)); | ||||
| 		}).catch((err) => { | ||||
| 			logging.error((new texts(`error_msg_save_failed`)).localized, DATA_NAME.join(` → `), JSON.stringify(data)) | ||||
| 			return (false); | ||||
| 		})); | ||||
| 	} | ||||
| 
 | ||||
| 	/* | ||||
|  | @ -257,7 +269,6 @@ export async function compare(PATH, DATA) { | |||
| 		return (RESULT); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	let COMPARISON = {}; | ||||
| 	COMPARISON[`test`] = (PATH) ? DATA : DATA[1]; | ||||
| 	COMPARISON[`against`] = (PATH) ? (await global.read((Array.isArray(PATH)) ? [...PATH] : PATH)) : DATA[0]; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue