()
| 23 | } |
| 24 | |
| 25 | loadData() { |
| 26 | try { |
| 27 | const content = fs.readFileSync(this.dbFile, 'utf8') |
| 28 | const data = JSON.parse(content) |
| 29 | // Update lastModified time when loading data |
| 30 | if (fs.existsSync(this.dbFile)) { |
| 31 | this.lastModified = fs.statSync(this.dbFile).mtime |
| 32 | } |
| 33 | console.log('[Data Load] Loaded data from file:', JSON.stringify(data)) |
| 34 | return data |
| 35 | } catch (err) { |
| 36 | console.warn(`[Data Load] Could not load data file ${this.dbFile}:`, err.message) |
| 37 | console.log('[Data Load] Using fallback default data') |
| 38 | return { |
| 39 | posts: [{ id: 1, title: 'json-server', author: 'davert' }], |
| 40 | user: { name: 'john', password: '123456' }, |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | reloadData() { |
| 46 | console.log('[Reload] Reloading data from file...') |
no test coverage detected