glanceapp / glance

A self-hosted dashboard that puts all your feeds in one place
GNU Affero General Public License v3.0
8.56k stars 297 forks source link

DNS Stats widget - fix Pihole privacy edge case #224

Closed SimJunYou closed 1 month ago

SimJunYou commented 2 months ago

There are privacy settings on the Pihole which affect the output of the API. pihole

When any privacy settings other than "Show everything" is selected on the Pihole, the DNS Stats widget fails with this error:

widget_with_privacy

The problem is that one of the fields (top_ads) in the JSON response from Pihole's API turns to an empty array because of the setting. For reference, with the privacy setting... with_privacy

... and without: without_privacy

I made a fix in pihole.go -- it just uses an alternate struct definition that does not expect top_ads if the original one fails. It copies to the original struct instance to sidestep any type errors, though it does look a little ugly. Here's how it looks after the fix: after_fix

It's my first time using Go, so I'm not sure if this was the best way to fix it. Do let me know if there's anything I can do to improve this.