| 34 | } |
| 35 | |
| 36 | public async init() { |
| 37 | this.state = await this.getCache(); |
| 38 | |
| 39 | if ( |
| 40 | !this.state || |
| 41 | (this.state.provider === 'firebase' && |
| 42 | this.state.updated && |
| 43 | this.state.updated + 7 * 24 * 60 * 60 * 1000 < new Date().getTime()) |
| 44 | ) { |
| 45 | const tempState = await this.api(); |
| 46 | if (tempState) this.state = tempState; |
| 47 | } |
| 48 | |
| 49 | this.logger.m('Result').log(this.state); |
| 50 | |
| 51 | if (this.state) { |
| 52 | await this.setCache(this.state); |
| 53 | } |
| 54 | return this; |
| 55 | } |
| 56 | |
| 57 | public getRules() { |
| 58 | if (this.state && this.state.rules && this.state.rules.length) return this.state.rules; |