Skip to content

Fix for always downloading to default directory with firefox extension#319

Merged
SuperCoolPencil merged 3 commits intoSurgeDM:mainfrom
leferi99:main
Apr 4, 2026
Merged

Fix for always downloading to default directory with firefox extension#319
SuperCoolPencil merged 3 commits intoSurgeDM:mainfrom
leferi99:main

Conversation

@leferi99
Copy link
Copy Markdown
Contributor

@leferi99 leferi99 commented Apr 4, 2026

Pass non-empty directory information to pendingDuplicates() and sendToSurge()

Greptile Summary

This PR fixes a silent bug where the Firefox extension always sent an empty directory string to Surge, causing every download to land in Surge's default directory instead of the user-selected location.

The fix is minimal and correct: handleDownloadIntercept already called extractPathInfo to parse downloadItem.filename into { filename, directory }, but the extracted directory was discarded in both the duplicate-confirmation path (directory: '' hardcoded in pendingDuplicates.set) and the normal download path (only filename was destructured before calling sendToSurge). Both call-sites now properly forward the extracted directory.

  • extractPathInfo correctly handles Windows (C:/…) and POSIX (/…) absolute paths and is unchanged.
  • sendToSurge already guards the path field with if (absolutePath), so downloads with no directory information still fall back to Surge's default — no regression risk.
  • The duplicate-confirmation handler (confirmDuplicate message case) also reads pending.directory when calling sendToSurge, so it too now benefits from the correct stored value.

Confidence Score: 5/5

Safe to merge — targeted two-line fix with no regression risk

The change is minimal and precisely correct: it stops discarding the already-extracted directory in two call-sites. The guard in sendToSurge (if absolutePath) preserves fallback behaviour when no directory is present. No new logic is introduced and no existing behaviour is broken.

No files require special attention

Important Files Changed

Filename Overview
extension-firefox/background.js Passes extracted directory from extractPathInfo to both pendingDuplicates and sendToSurge, fixing the always-default-directory bug

Sequence Diagram

sequenceDiagram
    participant Browser
    participant handleDownloadIntercept
    participant extractPathInfo
    participant Target as sendToSurge / pendingDuplicates

    Browser->>handleDownloadIntercept: onCreated(downloadItem)
    alt duplicate detected
        handleDownloadIntercept->>extractPathInfo: extractPathInfo(downloadItem)
        extractPathInfo-->>handleDownloadIntercept: { filename, directory }
        handleDownloadIntercept->>Target: pendingDuplicates.set(id, { filename, directory, … })
        Note over Target: Previously directory was hardcoded ''
    else surge running
        handleDownloadIntercept->>extractPathInfo: extractPathInfo(downloadItem)
        extractPathInfo-->>handleDownloadIntercept: { filename, directory }
        handleDownloadIntercept->>Target: sendToSurge(url, filename, directory)
        Note over Target: Previously directory was hardcoded ''
        Target-->>handleDownloadIntercept: { success }
    end
Loading

Greploops — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.
Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.

Reviews (2): Last reviewed commit: "shorthand for directory path" | Re-trigger Greptile

leferi99 added 2 commits April 4, 2026 17:40
Pass directory information to pendingDuplicates and sendToSurge
Fix for always downloading to default directory with firefox extension
Comment thread extension-firefox/background.js Outdated
Comment on lines 728 to 738
@@ -734,7 +734,7 @@ async function handleDownloadIntercept(downloadItem) {
const result = await sendToSurge(
downloadItem.url,
filename,
''
directory
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 No tests included for this bug fix

This patch corrects a silent data-loss bug (downloads ignoring the user-selected directory), but ships without any automated tests. Consider adding coverage for:

  • extractPathInfo with a Windows path (e.g. C:/Users/foo/Downloads/file.zip) returns { directory: 'C:/Users/foo/Downloads', filename: 'file.zip' }
  • extractPathInfo with a POSIX path returns the correct split
  • handleDownloadIntercept passes a non-empty directory to sendToSurge (integration)
  • Edge case: downloadItem.filename is empty — both fields default to ''

Rule Used: What: All code changes must include tests for edge... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: extension-firefox/background.js
Line: 728-738

Comment:
**No tests included for this bug fix**

This patch corrects a silent data-loss bug (downloads ignoring the user-selected directory), but ships without any automated tests. Consider adding coverage for:
- `extractPathInfo` with a Windows path (e.g. `C:/Users/foo/Downloads/file.zip`) returns `{ directory: 'C:/Users/foo/Downloads', filename: 'file.zip' }`
- `extractPathInfo` with a POSIX path returns the correct split
- `handleDownloadIntercept` passes a non-empty `directory` to `sendToSurge` (integration)
- Edge case: `downloadItem.filename` is empty — both fields default to `''`

**Rule Used:** What: All code changes must include tests for edge... ([source](https://app.greptile.com/review/custom-context?memory=2b22782d-3452-4d55-b059-e631b2540ce8))

How can I resolve this? If you propose a fix, please make it concise.

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@leferi99
Copy link
Copy Markdown
Contributor Author

leferi99 commented Apr 4, 2026

This is meant as a quick fix for #302

Copy link
Copy Markdown
Member

@SuperCoolPencil SuperCoolPencil left a comment

Choose a reason for hiding this comment

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

Thank you so much for contributing :)

@SuperCoolPencil SuperCoolPencil merged commit f563d64 into SurgeDM:main Apr 4, 2026
7 checks passed
SuperCoolPencil added a commit that referenced this pull request Apr 6, 2026
- Fix directory bug from PR #319: directory is now extracted and
  forwarded in both normal and duplicate download paths
- sendToSurge now correctly takes 4 args (url, filename, directory, headers)
  instead of the broken 3-arg signature that passed captured headers as
  the directory argument
- Extract inline confirmDuplicate/skipDuplicate logic into named functions
- Use explicit types (PendingDup interface) instead of inline tuples
- Remove unused _healthCheckTimer/_syncIntervalTimer variables
- Simplify getBaseUrl: drop the redundant cachedPort branch, just scan
- Add proper directory storage to pendingDuplicates for the duplicate
  confirmation flow
- Consistent formatting: one function per clear purpose

Co-Authored-By: Claude Opus 4.6 <[email protected]>
SuperCoolPencil added a commit that referenced this pull request Apr 6, 2026
- Fix directory bug from PR #319: directory is now extracted and
  forwarded in both normal and duplicate download paths
- sendToSurge now correctly takes 4 args (url, filename, directory, headers)
  instead of the broken 3-arg signature that passed captured headers as
  the directory argument
- Extract inline confirmDuplicate/skipDuplicate logic into named functions
- Use explicit types (PendingDup interface) instead of inline tuples
- Remove unused _healthCheckTimer/_syncIntervalTimer variables
- Simplify getBaseUrl: drop the redundant cachedPort branch, just scan
- Add proper directory storage to pendingDuplicates for the duplicate
  confirmation flow
- Consistent formatting: one function per clear purpose

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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