| 213 | JSONFilePreset(path.join(pmcDir, "pmcaptcha_config.json"), DEFAULT_CONFIG) as Promise<JsonDb>, |
| 214 | JSONFilePreset(path.join(dataDir, "pmcaptcha_data.json"), DEFAULT_DATA) as Promise<JsonDb>, |
| 215 | ]); |
| 216 | dbReady = true; |
| 217 | log(LogLevel.INFO, `Config DB ready | Data DB: ${path.join(dataDir, "pmcaptcha_data.json")}`); |
| 218 | } catch (e) { |
| 219 | log(LogLevel.ERROR, "DB init failed", e); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | async function generationDelay(ms: number): Promise<boolean> { |
| 224 | const lifecycle = getActiveLifecycle(); |
| 225 | if (!lifecycle) return false; |
| 226 | return await new Promise<boolean>((resolve) => { |
| 227 | lifecycle.setTimeout(() => resolve(!lifecycle.signal.aborted), ms, { label: "pmcaptcha-delay" }); |
| 228 | if (lifecycle.signal.aborted) resolve(false); |
| 229 | }); |