* Decide whether a consent marker file is expired. * A marker that cannot be parsed or has an invalid timestamp can never grant * access again (the read paths treat it as absent), so it counts as expired.
(filePath, ttlMs, nowMs)
| 61 | * access again (the read paths treat it as absent), so it counts as expired. |
| 62 | */ |
| 63 | function markerIsExpired(filePath, ttlMs, nowMs) { |
| 64 | try { |
| 65 | const marker = JSON.parse(fs.readFileSync(filePath, 'utf8')); |
| 66 | const age = nowMs - new Date(marker.timestamp).getTime(); |
| 67 | if (Number.isNaN(age)) return true; // invalid timestamp, dead marker |
| 68 | return age >= ttlMs; |
| 69 | } catch { |
| 70 | return true; // unreadable or malformed, dead marker |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Sweep expired consent markers of one kind from the plugin data dir. |