(content = {})
| 109 | } |
| 110 | |
| 111 | async function eTLD(content = {}) { |
| 112 | if (!content.update_time || (Date.now() - content.update_time > 86400000 * 30)) { |
| 113 | await new Promise(resolve => { |
| 114 | $httpClient.get({ |
| 115 | url: 'https://publicsuffix.org/list/public_suffix_list.dat' |
| 116 | }, (error, resp, body) => { |
| 117 | if (resp.status == 200 && !error && body) { |
| 118 | content.update_time = Date.now(); |
| 119 | content.public_suffix = body.replace(/\r|.*(\/\/|#|;).*|\n(\!|\*\.)/g, '\n').split('\n').filter((t) => t); |
| 120 | $persistentStore.write(JSON.stringify(content), `${args.key}-eTLD`); |
| 121 | resolve() |
| 122 | } else if (content.update_time) { |
| 123 | console.log(`Update eTLD list failed: ${error}`); |
| 124 | resolve() |
| 125 | } else { |
| 126 | throw new Error(`Download eTLD list failed: ${error}`) |
| 127 | } |
| 128 | }) |
| 129 | }) |
| 130 | } |
| 131 | return content |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | Shorten multi level domain: non-eTLD, full eTLD, second level domain will return original |
no test coverage detected