enables schema saving in db, initial refactor of db schema for revisions
This commit is contained in:
@@ -15,9 +15,13 @@ export class DHSecretClient {
|
||||
* @param dhBaseUri uri for hosted Dragon's Hoard instance
|
||||
* @param cacheDir path to cache dir
|
||||
*/
|
||||
constructor(private dhBaseUri: string, private cacheDir: string) {
|
||||
constructor(
|
||||
private dhBaseUri: string,
|
||||
private cacheDir: string,
|
||||
) {
|
||||
this.cacheLocation = this.cacheDir.trim().replace(/\/^/, "") + "/.dh_cache";
|
||||
mkdirSync(this.cacheDir, { recursive: true });
|
||||
|
||||
this.readDiskCache();
|
||||
this.token = this.fetchToken();
|
||||
}
|
||||
@@ -42,12 +46,13 @@ export class DHSecretClient {
|
||||
}
|
||||
|
||||
private readDiskCache() {
|
||||
const cache = readFileSync(this.cacheLocation, "utf-8");
|
||||
|
||||
if (!cache) {
|
||||
try {
|
||||
const cache = readFileSync(this.cacheLocation, "utf-8");
|
||||
this.cache = JSON.parse(cache || "{}");
|
||||
} catch {
|
||||
this.cache = {};
|
||||
this.writeDiskCache();
|
||||
} else this.cache = JSON.parse(cache || "{}");
|
||||
this.writeDiskCache().then(this.readDiskCache);
|
||||
}
|
||||
}
|
||||
private async writeDiskCache() {
|
||||
await writeFile(this.cacheLocation, JSON.stringify(this.cache), "utf-8");
|
||||
|
Reference in New Issue
Block a user