Skip to content

fix: Show delete_key in UI after URL shortening - #5

Merged
manishym merged 5 commits into
mainfrom
fix_delete_key_frontend
Mar 19, 2026
Merged

fix: Show delete_key in UI after URL shortening#5
manishym merged 5 commits into
mainfrom
fix_delete_key_frontend

Conversation

@manishym

Copy link
Copy Markdown
Owner
  • Display delete key below shortened URL
  • Add copy button for delete key
  • Pre-fill delete path and key in delete form
  • Require delete key for deletion

- Display delete key below shortened URL
- Add copy button for delete key
- Pre-fill delete path and key in delete form
- Require delete key for deletion
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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 significantly improves the user experience and security for managing shortened URLs. It introduces the immediate display and easy copying of the delete key after URL shortening, and integrates this key into a more intuitive and secure deletion workflow. Users can now effortlessly delete their links with the required authentication, making the system more robust and user-friendly.

Highlights

  • Delete Key Display: The delete key is now displayed in the UI immediately after a URL is shortened, providing users with the necessary information to manage their links.
  • Copy Functionality for Delete Key: A dedicated 'Copy Key' button has been added next to the displayed delete key, allowing users to easily copy it to their clipboard.
  • Pre-filled Deletion Form: Upon shortening a URL, the 'Delete a short link' form is automatically pre-filled with the newly generated short code and its corresponding delete key, streamlining the deletion process.
  • Delete Key Requirement for Deletion: The deletion process now explicitly requires the delete key, enhancing security by preventing unauthorized removal of shortened URLs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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.

@manishym

Copy link
Copy Markdown
Owner Author

/gemini review

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

Copy link
Copy Markdown

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 updates the frontend to display the delete key after a URL is shortened, along with a button to copy it. It also pre-fills the deletion form with the short path and delete key, and makes the delete key a required field for deletion. The changes are functionally correct and implement the described features. I've added a few comments with suggestions to improve code quality and maintainability by avoiding inline styles, using safer DOM manipulation methods, and reducing code duplication.

Comment thread gateway/static/index.html Outdated
Comment on lines +182 to +185
<div class="result-row" style="margin-top: 0.75rem;">
<span style="color: var(--text-muted); font-size: 0.8rem;">Delete key:</span>
<span class="short-url" id="delete-key-display" style="font-size: 0.8rem;"></span>
<button type="button" class="btn-ghost copy-btn" id="copy-key-btn">Copy Key</button>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better maintainability and separation of concerns, it's recommended to avoid inline styles. Consider creating dedicated CSS classes in the <style> block for these elements. For example, you could create classes for the delete key row, label, and value, and apply them here instead of using style attributes. This makes the styling more consistent and easier to manage.

Comment thread gateway/static/index.html Outdated
Comment on lines 256 to 257
document.getElementById('short-url-display').innerHTML =
'<a href="' + shortFull + '" target="_blank" rel="noopener">' + shortFull + '</a>';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent potential Cross-Site Scripting (XSS) vulnerabilities, it's safer to avoid using innerHTML to construct DOM elements. Even though shortFull is constructed from what seems to be safe data, it's a best practice to create and append elements programmatically using document.createElement and element.appendChild (or element.replaceChildren). This approach is inherently safer against injection attacks.

Comment thread gateway/static/index.html
Comment on lines +283 to +291
document.getElementById('copy-key-btn').addEventListener('click', () => {
if (!lastDeleteKey) return;
navigator.clipboard.writeText(lastDeleteKey).then(() => {
const btn = document.getElementById('copy-key-btn');
const orig = btn.textContent;
btn.textContent = 'Copied!';
setTimeout(() => { btn.textContent = orig; }, 2000);
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This logic for updating the button text to 'Copied!' and back is duplicated from the 'copy-btn' event listener (lines 276-279). To improve maintainability and follow the Don't Repeat Yourself (DRY) principle, consider extracting this UI feedback logic into a shared helper function. For example, a function like showCopiedFeedback(buttonElement) could be created and called from both event listeners.

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

Copy link
Copy Markdown

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 successfully adds the functionality to display and use a delete key for shortened URLs. The backend changes and associated tests are well-implemented. My review focuses on the frontend changes in gateway/static/index.html, where I've identified opportunities to improve maintainability by removing inline styles and reducing code duplication, and to enhance security by avoiding the use of innerHTML.

Comment thread gateway/static/index.html Outdated
Comment on lines +182 to +186
<div class="result-row" style="margin-top: 0.75rem;">
<span style="color: var(--text-muted); font-size: 0.8rem;">Delete key:</span>
<span class="short-url" id="delete-key-display" style="font-size: 0.8rem;"></span>
<button type="button" class="btn-ghost copy-btn" id="copy-key-btn">Copy Key</button>
</div>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using inline styles makes the code harder to maintain and violates the separation of concerns principle. It's better to define styles in CSS classes. Please consider moving the inline styles for margin-top, color, and font-size into dedicated CSS classes within the <style> block at the top of the file.

For example, you could add classes like .result-row--secondary, .result-label, and .result-value to your stylesheet and apply them here. This will make your HTML cleaner and your styles easier to manage.

Comment thread gateway/static/index.html Outdated
Comment on lines 256 to 257
document.getElementById('short-url-display').innerHTML =
'<a href="' + shortFull + '" target="_blank" rel="noopener">' + shortFull + '</a>';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using innerHTML to set content from an API response can introduce Cross-Site Scripting (XSS) vulnerabilities if the data is not properly sanitized or if the API's output changes unexpectedly. A safer approach is to programmatically create DOM elements.

Suggested change
document.getElementById('short-url-display').innerHTML =
'<a href="' + shortFull + '" target="_blank" rel="noopener">' + shortFull + '</a>';
const displayEl = document.getElementById('short-url-display');
displayEl.textContent = ''; // Clear existing content
const linkEl = document.createElement('a');
linkEl.href = shortFull;
linkEl.target = '_blank';
linkEl.rel = 'noopener';
linkEl.textContent = shortFull;
displayEl.appendChild(linkEl);

Comment thread gateway/static/index.html
Comment on lines +283 to +291
document.getElementById('copy-key-btn').addEventListener('click', () => {
if (!lastDeleteKey) return;
navigator.clipboard.writeText(lastDeleteKey).then(() => {
const btn = document.getElementById('copy-key-btn');
const orig = btn.textContent;
btn.textContent = 'Copied!';
setTimeout(() => { btn.textContent = orig; }, 2000);
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic to show 'Copied!' on the button is nearly identical to the event listener for copy-btn (lines 271-281). To avoid code duplication and improve maintainability, this common logic should be extracted into a shared helper function.

For example, you could create a function like this:

function animateCopied(button) {
  const originalText = button.textContent;
  button.textContent = 'Copied!';
  setTimeout(() => { button.textContent = originalText; }, 2000);
}

Then, both click handlers could simply call animateCopied(event.currentTarget) inside their .then() block. This would make the code cleaner and easier to update in the future.

- Replace inline styles with CSS classes (.result-label, .result-value)
- Use safe DOM manipulation instead of innerHTML to prevent XSS
- Extract duplicated 'Copied!' logic into animateCopied() helper
- Move zql.png to gateway/static
- Add favicon link to HTML head
- Add logo image to page header
- Change from number input (seconds) to datetime-local picker
- Convert selected datetime to seconds from current time
@manishym

Copy link
Copy Markdown
Owner Author

/gemini review

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

Copy link
Copy Markdown

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 updates the UI to display and manage the delete_key for shortened URLs. The changes include showing the delete key after creation, adding a button to copy it, and pre-filling the deletion form. The code is well-structured, for instance by extracting the animateCopied function. I've added a couple of suggestions to improve the robustness of the clipboard copy functionality by handling potential errors.

Comment thread gateway/static/index.html Outdated
btn.textContent = 'Copied!';
setTimeout(() => { btn.textContent = orig; }, 2000);
animateCopied(document.getElementById('copy-btn'));
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The navigator.clipboard.writeText method returns a promise that can reject if the clipboard operation fails (e.g., due to browser permissions or other issues). It's a good practice to handle potential errors using .catch() to provide feedback to the user or log the error.

Suggested change
});
}).catch(err => console.error('Failed to copy URL:', err));

Comment thread gateway/static/index.html Outdated
if (!lastDeleteKey) return;
navigator.clipboard.writeText(lastDeleteKey).then(() => {
animateCopied(document.getElementById('copy-key-btn'));
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to the other clipboard operation, it's important to handle potential errors when writing to the clipboard. Adding a .catch() block will make the feature more robust.

Suggested change
});
}).catch(err => console.error('Failed to copy delete key:', err));

- Add .catch() to clipboard.writeText() for better error handling
@manishym
manishym merged commit fe9089f into main Mar 19, 2026
3 checks passed
@manishym
manishym deleted the fix_delete_key_frontend branch March 19, 2026 06:56
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.

1 participant