Skip to content

Conversation

@tavdog
Copy link
Member

@tavdog tavdog commented Feb 1, 2026

warning banners on both firmware page and device edit page about localhost/127 in the image url

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @tavdog, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the user experience by proactively alerting users to potential configuration problems. It identifies when a device's image URL is set to a local address (localhost or 127.0.0.1), which is typically problematic for devices operating outside the server's local machine. By displaying a clear warning, the system guides users to correct their settings, preventing future connectivity issues without requiring them to discover the problem through trial and error.

Highlights

  • Localhost URL Warning: Introduced a warning banner on both the firmware generation page and the device edit page if the configured image URL contains 'localhost' or '127.0.0.1'. This helps users avoid common connectivity issues when devices are on different networks.
  • UI Enhancements: Added new JavaScript functions (resetImgUrl, resetWsUrl) to the device update page for resetting image and WebSocket URLs, and updated the 'Dim Mode Settings' section title to 'Display Settings' for clarity.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds helpful warnings to the UI when a device's image URL is configured to use localhost or 127.0.0.1, which is a great improvement for user experience. The implementation is straightforward.

My review includes a few suggestions:

  • Refactoring duplicated logic for checking the URL into a helper function.
  • Improving how localization strings are handled in the templates for better maintainability.
  • Addressing a critical JavaScript bug in update.html where functions are being redefined, which would break existing functionality.
  • Fixing a minor UI issue in update.html where two different sections have the same heading.

Overall, the core feature is well-implemented, and with these fixes, the PR will be in great shape.

Comment on lines 466 to 482
<script>
function resetImgUrl() {
const imageUrl = document.getElementById("img_url").value.trim();
if (imageUrl) {
document.getElementById("reported_img_url").value = imageUrl;
updateFirmwareSettings({image_url: imageUrl});
}
}

function resetWsUrl() {
const wsUrl = document.getElementById("ws_url").value.trim();
if (wsUrl) {
document.getElementById("reported_ws_url").value = wsUrl;
updateFirmwareSettings({ws_url: wsUrl});
}
}
</script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This script block redefines the functions resetImgUrl and resetWsUrl, which are already defined earlier in this file. This will break the "Reset" button functionality for the main URL fields.

The new functions also have misleading names; they seem to be for syncing URLs from the main device settings to the live firmware settings, not for resetting them.

To fix this, you should rename these new functions to something more descriptive (e.g., syncImgUrlToFirmware) and ensure they don't conflict with existing functions. If these new functions are intended to be used, they should be called by appropriate UI elements.

    <script>
		function syncImgUrlToFirmware() {
			const imageUrl = document.getElementById("img_url").value.trim();
			if (imageUrl) {
				document.getElementById("reported_img_url").value = imageUrl;
				updateFirmwareSettings({image_url: imageUrl});
			}
		}

		function syncWsUrlToFirmware() {
			const wsUrl = document.getElementById("ws_url").value.trim();
			if (wsUrl) {
				document.getElementById("reported_ws_url").value = wsUrl;
				updateFirmwareSettings({ws_url: wsUrl});
			}
		}
    </script>

Comment on lines +261 to +266
// Check if URL contains localhost
imgURL := device.ImgURL
var urlWarning string
if strings.Contains(imgURL, "localhost") || strings.Contains(imgURL, "127.0.0.1") {
urlWarning = "localhost"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic to check for "localhost" or "127.0.0.1" in the image URL is duplicated from internal/server/firmware.go. To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a shared helper function.

For example, you could create a function like isLocalhostURL(url string) bool in internal/server/helpers.go and call it from both handleUpdateDeviceGet and handleFirmwareGenerateGet. This would centralize the logic and make future changes easier.

<i class="fa-solid fa-triangle-exclamation"></i> {{ t .Localizer "Warning: Localhost URL Detected" }}
</h4>
<p>
{{ t .Localizer "The firmware image URL uses localhost (" }}<strong>{{ .Device.ImgURL }}</strong>{{ t .Localizer ") which will not work when the device is running on a different network. Either replace localhost with the IP or hostname of this server, or connect to this server over its IP or hostname, edit the device and click the refresh buttons by the devices image URLs, then return here." }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The warning message is constructed by concatenating multiple translated strings and variables. This is not ideal for localization as it makes it difficult for translators to provide accurate and natural-sounding translations for different languages. It's better to use a single translation key with placeholders. This also applies to web/templates/manager/update.html.

A better approach would be:

<p>
    {{ t .Localizer "LocalhostURLWarning" (dict "ImgURL" .Device.ImgURL) }}
</p>

And in your en.json file, you would have a single entry:

"LocalhostURLWarning": {
  "other": "The firmware image URL uses localhost (<strong>{{.ImgURL}}</strong>) which will not work when the device is running on a different network. Either replace localhost with the IP or hostname of this server, or connect to this server over its IP or hostname, edit the device and click the refresh buttons by the devices image URLs, then return here."
}

This makes the string a single unit for translators.

</script>
<div class="device-settings-section">
<h2>{{ t .Localizer "Dim Mode Settings" }}</h2>
<h2>{{ t .Localizer "Display Settings" }}</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This section heading has been changed from "Dim Mode Settings" to "Display Settings". However, another section further down (previously "Firmware Features") has also been renamed to "Display Settings" (line 721). Having two sections with the same title on the same page is confusing for users.

I recommend reverting this heading back to "Dim Mode Settings" to maintain clarity and distinguish it from the other "Display Settings" section.

        <h2>{{ t .Localizer "Dim Mode Settings" }}</h2>

warning banners in proper locations
@tavdog tavdog force-pushed the local_image_url_warnings branch from 3ff65f6 to 22b056d Compare February 2, 2026 03:13
@tavdog
Copy link
Member Author

tavdog commented Feb 2, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a helpful warning to the UI when a device's image URL is set to localhost or 127.0.0.1. The implementation in the Go handlers is sound, but there's an opportunity to reduce code duplication by creating a shared helper function. My main concerns are with the template changes. In firmware.html, the form has been restructured in a way that will prevent it from submitting correctly, which is a critical issue. In update.html, there are a couple of issues: a JavaScript function is being redefined, which will cause bugs, and a section has been renamed to a title that's already in use, which will be confusing for users. Please see my detailed comments for suggestions on how to address these issues.

Comment on lines 204 to 212
<form method="post" id="firmware-form">
<div class="device-settings-section">
<div class="config-management-container">
<button class="w3-button w3-blue config-management-btn" type="submit">
<i class="fa-solid fa-microchip" aria-hidden="true"></i> {{ t .Localizer "Generate Firmware File" }}
</button>
</div>
</div>
</div>
</form>
<hr>
<script>
</form>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The <form> tag has been moved to only wrap the submit button. This means that all the other input fields (like WiFi credentials and Image URL) are now outside the form and will not be submitted when the 'Generate Firmware File' button is clicked. This will break the firmware generation functionality. The <form> tag should be moved back to its original position at line 60 to wrap all the necessary input fields.

Comment on lines 466 to 482
<script>
function resetImgUrl() {
const imageUrl = document.getElementById("img_url").value.trim();
if (imageUrl) {
document.getElementById("reported_img_url").value = imageUrl;
updateFirmwareSettings({image_url: imageUrl});
}
}

function resetWsUrl() {
const wsUrl = document.getElementById("ws_url").value.trim();
if (wsUrl) {
document.getElementById("reported_ws_url").value = wsUrl;
updateFirmwareSettings({ws_url: wsUrl});
}
}
</script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

You are defining resetImgUrl and resetWsUrl functions here, but these functions are already defined earlier in this file (lines 163-170). This re-definition will override the original functions and likely cause unintended behavior for the 'Reset' buttons. The new functions also have misleading names as they don't 'reset' but rather seem to sync values. Please rename these new functions to avoid conflict and clarify their purpose, for example syncImgUrlToFirmware and syncWsUrlToFirmware. Also, the resetWsUrl function references an element with ID reported_ws_url which does not exist in the page, this will cause a runtime error.

Comment on lines 751 to 752
<div class="device-settings-section">
<h2>{{ t .Localizer "Display Settings" }}</h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This section was previously titled 'Firmware Features' and is now 'Display Settings'. However, there is already another section titled 'Display Settings' earlier in the file (line 173). Having two sections with the same title can be confusing for users. Please consider using a more distinct title for this section, like 'Advanced Firmware Settings' or similar, to differentiate it from the other 'Display Settings' section.

Furthermore, the wrapping condition for this block was changed from if .Device.SupportsFirmwareFeatures to if .Device.OTACapable. This makes this section visible for devices with older firmware that might not support these features, which could lead to issues. It's recommended to revert to the more restrictive if .Device.SupportsFirmwareFeatures condition to ensure these settings are only shown for compatible devices.

Comment on lines +282 to +284
if strings.Contains(imgURL, "localhost") || strings.Contains(imgURL, "127.0.0.1") {
urlWarning = "localhost"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to check for localhost URLs is also present in internal/server/handlers_device.go. To avoid code duplication, consider extracting this into a shared helper function, for example in helpers.go.

Additionally, urlWarning is used as a boolean flag in the template. It would be more idiomatic to use a bool type for this instead of a string. The helper function could return a boolean, and the URLWarning field in TemplateData could be changed to bool.

Comment on lines +264 to +266
if strings.Contains(imgURL, "localhost") || strings.Contains(imgURL, "127.0.0.1") {
urlWarning = "localhost"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to check for localhost URLs is duplicated from internal/server/firmware.go. To improve maintainability and avoid code duplication, it would be better to extract this into a shared helper function.

A boolean flag would also be more idiomatic here instead of a string. You could create a helper function that returns a boolean, and update the URLWarning field in TemplateData to be of type bool.

@tavdog
Copy link
Member Author

tavdog commented Feb 2, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a helpful warning to the UI when an image URL contains 'localhost' or '127.0.0.1', which is a common source of issues. The implementation is mostly correct, but I've identified a few areas for improvement. There's some duplicated code in the Go backend that could be refactored into a helper function for better maintainability. More critically, I found a couple of issues in the update.html template: a JavaScript bug that breaks the 'Reset to default' URL functionality, and a change in template logic that could incorrectly show the 'Firmware Features' section for unsupported devices. Addressing these points will improve the robustness and maintainability of the code.

Comment on lines 466 to 482
<script>
function resetImgUrl() {
const imageUrl = document.getElementById("img_url").value.trim();
if (imageUrl) {
document.getElementById("reported_img_url").value = imageUrl;
updateFirmwareSettings({image_url: imageUrl});
}
}

function resetWsUrl() {
const wsUrl = document.getElementById("ws_url").value.trim();
if (wsUrl) {
document.getElementById("reported_ws_url").value = wsUrl;
updateFirmwareSettings({ws_url: wsUrl});
}
}
</script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This script block redefines the resetImgUrl and resetWsUrl functions with incorrect logic for the "Reset to default" buttons. The new functions do not reset the URLs but instead copy the current value from one input to another and trigger a firmware settings update. This breaks the reset functionality. The original functions, which are still present earlier in the file, are correct. This new block should be removed to restore the intended behavior.

</div>
</div>
{{ end }}
{{ if .Device.SupportsFirmwareFeatures }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The "Firmware Features" section was previously guarded by {{ if .Device.SupportsFirmwareFeatures }}. This change removes that specific guard and includes the section within the broader {{ if .Device.OTACapable }} block. The SupportsFirmwareFeatures check is more restrictive and accurate for that section's content. Removing it may cause the UI to display these features for devices that do not support them, leading to user confusion and potential errors. The original conditional logic should be restored, with the "Firmware Features" section wrapped in its own {{ if .Device.SupportsFirmwareFeatures }} ... {{ end }} block, separate from the {{ if .Device.OTACapable }} block.

Comment on lines +279 to +284
// Check if URL contains localhost
imgURL := device.ImgURL
var urlWarning string
if strings.Contains(imgURL, "localhost") || strings.Contains(imgURL, "127.0.0.1") {
urlWarning = "localhost"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to check for "localhost" or "127.0.0.1" in the URL is also present in internal/server/handlers_device.go. To avoid code duplication and improve maintainability, this check should be extracted into a shared helper function, for example in helpers.go.

Comment on lines +261 to +266
// Check if URL contains localhost
imgURL := device.ImgURL
var urlWarning string
if strings.Contains(imgURL, "localhost") || strings.Contains(imgURL, "127.0.0.1") {
urlWarning = "localhost"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to check for "localhost" or "127.0.0.1" is duplicated from internal/server/firmware.go. To follow the DRY (Don't Repeat Yourself) principle, this should be extracted into a common helper function.

@tavdog
Copy link
Member Author

tavdog commented Feb 2, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a warning banner on the firmware and device edit pages when the image URL contains localhost or 127.0.0.1. The implementation is generally good, but there are a couple of issues. There's some code duplication in the Go backend for checking the URL, which should be refactored into a helper function. More critically, there's an HTML issue in firmware.html where a change has resulted in a nested form, a duplicate element ID, and an unclosed form tag, which will break the page's functionality. I've provided suggestions to address these points.

Comment on lines 204 to 212
<form method="post" id="firmware-form">
<div class="device-settings-section">
<div class="config-management-container">
<button class="w3-button w3-blue config-management-btn" type="submit">
<i class="fa-solid fa-microchip" aria-hidden="true"></i> {{ t .Localizer "Generate Firmware File" }}
</button>
</div>
</div>
</div>
</form>
<hr>
<script>
</form>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change introduces invalid HTML. It creates a nested <form> element (which is not allowed), duplicates the id="firmware-form", and removes the closing tag for the outer form that starts on line 60, leaving it unclosed.

The original structure was correct, with the button inside the main form. I suggest reverting this part of the change to restore the valid HTML structure.

Suggested change
<form method="post" id="firmware-form">
<div class="device-settings-section">
<div class="config-management-container">
<button class="w3-button w3-blue config-management-btn" type="submit">
<i class="fa-solid fa-microchip" aria-hidden="true"></i> {{ t .Localizer "Generate Firmware File" }}
</button>
</div>
</div>
</div>
</form>
<hr>
<script>
</form>
<div class="device-settings-section">
<div class="config-management-container">
<button class="w3-button w3-blue config-management-btn" type="submit">
<i class="fa-solid fa-microchip" aria-hidden="true"></i> {{ t .Localizer "Generate Firmware File" }}
</button>
</div>
</div>
</form>

@tavdog
Copy link
Member Author

tavdog commented Feb 2, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a warning banner on the firmware and device edit pages when the image URL contains localhost or 127.0.0.1. The implementation is generally good, but I've identified a few areas for improvement regarding code duplication, internationalization, and a critical bug in one of the HTML templates that would break form submission. Please see my detailed comments.

Comment on lines 204 to 212
<form method="post" id="firmware-form">
<div class="device-settings-section">
<div class="config-management-container">
<button class="w3-button w3-blue config-management-btn" type="submit">
<i class="fa-solid fa-microchip" aria-hidden="true"></i> {{ t .Localizer "Generate Firmware File" }}
</button>
</div>
</div>
</div>
</form>
<hr>
<script>
</form>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change introduces a nested <form> element with a duplicate ID, which is invalid HTML and will break form submission. The outer <form> tag from line 60 is also left unclosed. This appears to be unintentional and should be reverted to the original structure where the button is inside the main form, which is closed properly.

    <div class="device-settings-section">
        <div class="config-management-container">
            <button class="w3-button w3-blue config-management-btn" type="submit">
                <i class="fa-solid fa-microchip" aria-hidden="true"></i> {{ t .Localizer "Generate Firmware File" }}
            </button>
        </div>
    </div>
</form>

@tavdog
Copy link
Member Author

tavdog commented Feb 2, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a warning banner on the firmware and device edit pages when the image URL contains 'localhost' or '127.0.0.1'. The implementation is correct, but there are several instances of code duplication in both the Go backend and the HTML templates. My review includes suggestions to refactor the duplicated logic into helper functions and partial templates to improve maintainability. I've also pointed out an issue with missing localization strings for the new UI text.

@tavdog tavdog merged commit cfe641d into main Feb 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants