yolkbot 0.1.0-alpha.51 → 0.1.0-alpha.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/bot.js +13 -11
- package/build/browser.js +0 -8
package/package.json
CHANGED
package/src/bot.js
CHANGED
|
@@ -665,23 +665,25 @@ export class Bot {
|
|
|
665
665
|
if (!IsBrowser) {
|
|
666
666
|
const { existsSync, mkdirSync, readFileSync, writeFileSync } = await import('node:fs');
|
|
667
667
|
const { join } = await import('node:path');
|
|
668
|
+
const { homedir } = await import('node:os');
|
|
668
669
|
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
670
|
+
const yolkbotCache = join(homedir(), '.yolkbot');
|
|
671
|
+
const mapCache = join(yolkbotCache, 'maps');
|
|
672
|
+
|
|
673
|
+
if (!existsSync(yolkbotCache)) mkdirSync(yolkbotCache);
|
|
674
|
+
if (!existsSync(mapCache)) mkdirSync(mapCache);
|
|
675
|
+
|
|
676
|
+
const mapFile = join(mapCache, `${name}-${hash}.json`);
|
|
672
677
|
|
|
673
|
-
|
|
678
|
+
if (existsSync(mapFile))
|
|
679
|
+
return JSON.parse(readFileSync(mapFile, 'utf-8'));
|
|
680
|
+
|
|
681
|
+
console.log('map not in cache, IMPORT!!', name, hash);
|
|
674
682
|
|
|
675
683
|
const data = await (await fetch(`https://${this.instance}/maps/${name}.json?${hash}`)).json();
|
|
676
684
|
|
|
677
|
-
|
|
678
|
-
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
685
|
+
writeFileSync(mapFile, JSON.stringify(data, null, 4), { flag: 'w+' });
|
|
679
686
|
|
|
680
|
-
writeFileSync(
|
|
681
|
-
join(dir, `${name}-${hash}.json`),
|
|
682
|
-
JSON.stringify(data, null, 4),
|
|
683
|
-
{ flag: 'w+' }
|
|
684
|
-
);
|
|
685
687
|
return data;
|
|
686
688
|
} else {
|
|
687
689
|
const data = await (await fetch(`https://${this.instance}/maps/${name}.json?${hash}`)).json();
|