src/store.js
// Separate init function from constructor to separate async calls.
Separate init function from constructor to separate async calls.
Separate init function from constructor to separate async calls .
async init() {
    let configOverrides = await io.jsonGet(this.base, SERVER_CFG) || {};
    for (let k in configOverrides) {
      let key = k.toLowerCase();
      this[key] = configOverrides[key];
    }
    this.data = this.storage ? path.resolve(this.base, this.data) : null;
    this.public = path.resolve(this.base, this.public);
    if (await io.folderExists(this.public)) {
    } else {
      this.public = null;  
    }
    if (this.data) {
      if (!await io.folderExists(this.data)) {
        log.info(`Creating storage for '${this.name}' ('${this.id}') at ${this.data}`);
        await io.folderCreate(this.data);
      }
      if (await io.folderExists(this.data)) {
        await io.folderCreate(path.join(this.data, 'users'));
        await io.folderCreate(path.join(this.data, 'logins'));
        log.force(`Storage ready for '${this.name}' ('${this.id}'): ${this.data}`);
      } else {
        this.data = null; 
      }
    }
  }
async init ( ) { let configOverrides = await io . jsonGet ( this . base , SERVER_CFG ) || { } ; for ( let k in configOverrides ) { let key = k . toLowerCase ( ) ; this [ key ] = configOverrides [ key ] ; } this . data = this . storage ? path . resolve ( this . base , this . data ) : null ; this . public = path . resolve ( this . base , this . public ) ; if ( await io . folderExists ( this . public ) ) { } else { this . public = null ; } if ( this . data ) { if ( ! await io . folderExists ( this . data ) ) { log . info ( ` ${ this . name } ${ this . id } ${ this . data } ` ) ; await io . folderCreate ( this . data ) ; } if ( await io . folderExists ( this . data ) ) { await io . folderCreate ( path . join ( this . data , 'users' ) ) ; await io . folderCreate ( path . join ( this . data , 'logins' ) ) ; log . force ( ` ${ this . name } ${ this . id } ${ this . data } ` ) ; } else { this . data = null ; } } }
Separate init function from constructor to separate async calls.
Separate init function from constructor to separate async calls .
// add overrides to defaults from config // now determine where the config data actually is // check if static/public folder exists // log.info(`Found public folder for '${this.name}' ('${this.id}') port ${this.port} at ${this.api}: ${this.public}`); // clear it so we know not to try to use data that doesn't exist // check if storage location exists // Now make sure the initial folder structure is in place, create initial subfolders if necessary. // clear it so we know not to try to use data that doesn't exist