make writing async

This commit is contained in:
buzzcode2007 2024-04-08 16:08:04 +08:00
parent ddce5b4320
commit 5c61411280

View file

@ -229,7 +229,7 @@ export async function search(SOURCE, TERM, ADDITIONAL_PLACES, STRICT = false) {
@param {object} DATA the new data to be written
@param {int} CLOUD store in the cloud; otherwise set to automatic
*/
export function write(PATH, DATA, CLOUD = -1) {
export async function write(PATH, DATA, CLOUD = -1) {
let DATA_INJECTED = {};
/* Forcibly write the data to chrome database
@ -278,9 +278,8 @@ export function write(PATH, DATA, CLOUD = -1) {
return DATABASE;
}
read(null, CLOUD).then((DATA_ALL) => {
// handle empty collected data.
if (!DATA_ALL) {
let DATA_ALL = await read(null, CLOUD);
if ((DATA_ALL != null && (typeof DATA_ALL).includes(`obj`)) ? Object.keys(DATA_ALL).length <= 0 : true) {
DATA_ALL = {};
}
@ -297,7 +296,6 @@ export function write(PATH, DATA, CLOUD = -1) {
// Write!
write_database(DATA_INJECTED, CLOUD);
});
}
/* Dangerous: Resets all data or a domain's data.