| 351 | } |
| 352 | |
| 353 | setRecords (origin, addresses) { |
| 354 | const timestamp = Date.now() |
| 355 | const records = { records: { 4: null, 6: null } } |
| 356 | let minTTL = this.#maxTTL |
| 357 | for (const record of addresses) { |
| 358 | record.timestamp = timestamp |
| 359 | if (typeof record.ttl === 'number') { |
| 360 | // The record TTL is expected to be in ms |
| 361 | record.ttl = Math.min(record.ttl, this.#maxTTL) |
| 362 | minTTL = Math.min(minTTL, record.ttl) |
| 363 | } else { |
| 364 | record.ttl = this.#maxTTL |
| 365 | } |
| 366 | |
| 367 | const familyRecords = records.records[record.family] ?? { ips: [] } |
| 368 | |
| 369 | familyRecords.ips.push(record) |
| 370 | records.records[record.family] = familyRecords |
| 371 | } |
| 372 | |
| 373 | // We provide a default TTL if external storage will be used without TTL per record-level support |
| 374 | this.storage.set(origin.hostname, records, { ttl: minTTL }) |
| 375 | } |
| 376 | |
| 377 | deleteRecords (origin) { |
| 378 | this.storage.delete(origin.hostname) |