| 115 | * @returns {Promise<void>} | 115 | * @returns {Promise<void>} |
| 116 | */ | 116 | */ |
| 117 | async verify(directoriesList) { | 117 | async verify(directoriesList) { |
| 118 | if (!useDiskCache) { | 118 | try { |
| 119 | return; | 119 | if (!useDiskCache) { |
| 120 | } | 120 | return; |
| | 121 | } |
| 121 | | 122 | |
| 122 | const cache = await this.instance(); | 123 | const cache = await this.instance(); |
| 123 | const validKeys = new Set(); | 124 | const validKeys = new Set(); |
| 124 | for (const dir of directoriesList) { | 125 | for (const dir of directoriesList) { |
| 125 | const files = fs.readdirSync(dir.characters, { withFileTypes: true }); | 126 | const files = fs.readdirSync(dir.characters, { withFileTypes: true }); |
| 126 | for (const file of files.filter(f => f.isFile() && path.extname(f.name) === '.png')) { | 127 | for (const file of files.filter(f => f.isFile() && path.extname(f.name) === '.png')) { |
| 127 | const filePath = path.join(dir.characters, file.name); | 128 | const filePath = path.join(dir.characters, file.name); |
| 128 | const cacheKey = getCacheKey(filePath); | 129 | const cacheKey = getCacheKey(filePath); |
| 129 | validKeys.add(path.parse(cache.getDatumPath(cacheKey)).base); | 130 | validKeys.add(path.parse(cache.getDatumPath(cacheKey)).base); |
| | 131 | } |
| 130 | } | 132 | } |
| 131 | } | 133 | for (const key of this.hashedKeys) { |
| 132 | for (const key of this.hashedKeys) { | 134 | if (!validKeys.has(key)) { |
| 133 | if (!validKeys.has(key)) { | 135 | await cache.removeItem(key); |
| 134 | await cache.removeItem(key); | 136 | } |
| 135 | } | 137 | } |
| | 138 | } catch (error) { |
| | 139 | console.error('Error while verifying disk cache:', error); |
| 136 | } | 140 | } |
| 137 | } | 141 | } |
| 138 | | 142 | |