refactor of smartUpdateUrl

This commit is contained in:
BlueSkiesAndGreenPastures
2025-06-20 11:12:46 -05:00
parent 2daf20874d
commit 086256cd9a
+44 -41
View File
@@ -26,39 +26,34 @@ export class EventCache {
} }
smartUpdateDomain(event: ToolsOzoneSafelinkDefs.Event) { smartUpdateDomain(event: ToolsOzoneSafelinkDefs.Event) {
let domain: string
try { try {
const domain = new URL(event.url).hostname domain = new URL(event.url).hostname
event.url = domain } catch (error) {
redirectLogger.error(
`[EventCache:smartUpdateDomain] Invalid URL: ${event.url}, error: ${error}`,
)
throw new Error(
`[EventCache:smartUpdateDomain] Error parsing domain from URL: ${error}`,
)
}
event.url = domain
try {
redirectLogger.info( redirectLogger.info(
`[EventCache] smartUpdateDomain called for domain: ${domain}, action: ${event.action}`, `[EventCache] smartUpdateDomain called for domain: ${domain}, action: ${event.action}`,
) )
if (event.action === ToolsOzoneSafelinkDefs.REMOVERULE) { if (event.action) {
this.insert(domain, event) this.insert(domain, event)
redirectLogger.info( redirectLogger.info(
`[EventCache] Removed rule for domain, adjusted audit log: ${domain}`, `[EventCache] rule updated or inserted for: ${domain}`,
) )
return return
} }
if (event.action === ToolsOzoneSafelinkDefs.WHITELIST) {
this.insert(domain, event)
redirectLogger.info(`[EventCache] Whitelisted domain: ${domain}`)
return
}
if (event.action === ToolsOzoneSafelinkDefs.BLOCK) {
this.insert(domain, event)
redirectLogger.info(`[EventCache] Blocked domain: ${domain}`)
return
}
if (event.action === ToolsOzoneSafelinkDefs.WARN) {
this.insert(domain, event)
redirectLogger.info(`[EventCache] Warned domain: ${domain}`)
return
}
} catch (error) { } catch (error) {
redirectLogger.error( redirectLogger.error(
`[EventCache:smartUpdateDomain] Error in smartUpdateDomain: ${error}`, `[EventCache:smartUpdateDomain] Error updating rule for domain: ${domain}, error: ${error}`,
) )
throw new Error( throw new Error(
`[EventCache:smartUpdateDomain] Error processing domain event: ${error}`, `[EventCache:smartUpdateDomain] Error processing domain event: ${error}`,
@@ -67,28 +62,36 @@ export class EventCache {
} }
smartUpdateUrl(event: ToolsOzoneSafelinkDefs.Event) { smartUpdateUrl(event: ToolsOzoneSafelinkDefs.Event) {
redirectLogger.info( let url: string
`[EventCache] smartUpdateUrl called for url: ${event.url}, action: ${event.action}`, try {
) url = new URL(event.url).toString()
if (event.action === ToolsOzoneSafelinkDefs.REMOVERULE) { } catch (error) {
this.insert(event.url, event) redirectLogger.error(
redirectLogger.info(`[EventCache] Removed rule for url: ${event.url}`) `[EventCache:smartUpdateUrl] Invalid URL: ${event.url}, error: ${error}`,
return )
throw new Error(`[EventCache:smartUpdateUrl] Error parsing URL: ${error}`)
} }
if (event.action === ToolsOzoneSafelinkDefs.WHITELIST) { event.url = url
this.insert(event.url, event)
redirectLogger.info(`[EventCache] Whitelisted url: ${event.url}`) try {
return redirectLogger.info(
} `[EventCache] smartUpdateUrl called for url: ${url}, action: ${event.action}`,
if (event.action === ToolsOzoneSafelinkDefs.BLOCK) { )
this.insert(event.url, event)
redirectLogger.info(`[EventCache] Blocked url: ${event.url}`) if (event.action) {
return this.insert(url, event)
} redirectLogger.info(
if (event.action === ToolsOzoneSafelinkDefs.WARN) { `[EventCache] rule updated or inserted for url: ${url}`,
this.insert(event.url, event) )
redirectLogger.info(`[EventCache] Warned url: ${event.url}`) return
return }
} catch (error) {
redirectLogger.error(
`[EventCache:smartUpdateUrl] Error updating rule for url: ${url}, error: ${error}`,
)
throw new Error(
`[EventCache:smartUpdateUrl] Error processing url event: ${error}`,
)
} }
} }