Creating browser extension to facilitate starting downloads. Chrome/Brave and Firefox supported.

The extension is hosted in a sibling repo and
is distributed off-store. Each WROLPi release ships the prebuilt artifacts
under wrolpi/static/extensions/ and serves them at /api/extensions/<file>:

  - wrolpi-chrome.zip       Load-Unpacked sideload for Chrome / Brave / Edge
  - wrolpi-firefox.xpi      Mozilla-signed (unlisted self-distribution),
                            one-click install in any Firefox
  - versions.json           Per-browser version metadata for the install page

Backend (modules/archive/api.py, wrolpi/root_api.py):

  - POST /api/archive/upload accepts an optional repeated `tagNames`
    multipart form field; the upload switch handler applies tags to the
    new FileGroup via FileGroup.set_tags(). Unknown tag names are auto-
    created inside a per-name SAVEPOINT so concurrent inserts on the same
    novel name don't abort the transaction (Tag.name has unique=True).
  - GET /api/extensions returns metadata (per-file availability + size +
    versions.json contents) for the install page.
  - GET /api/extensions/<filename> serves the binary, whitelisted by
    filename. Firefox .xpi is served as application/x-xpinstall WITHOUT a
    Content-Disposition: attachment header, so Firefox triggers its
    add-on install handler instead of saving the file.

Frontend (app/src/):

  - New /admin/extension page (linked from AdminRoute) detects the user's
    browser via navigator.userAgent and renders an install card per
    Firefox / Chromium / Other. Pulls metadata from /api/extensions to
    show file size and version, and gracefully reports 'Not yet
    available' when binaries are missing.
  - Dashboard's Getters component supports a deep link from the
    extension's 'Configure Download' button:
      /?downloader=<archive|video|...>&download_url=<u1>&download_url=<u2>
    On mount, the matching downloader form auto-opens with URLs pre-
    filled. Query params are cleared on close so a refresh doesn't
    re-open the modal.
  - DownloadMenu and the per-downloader forms accept an `initialUrls`
    seed via the existing `download` prop pattern, joined with newlines
    for the `urls` textarea (and first URL for single-URL forms).

Behavior is fully backwards compatible: pre-existing API callers can
still POST to /api/archive/upload without `tagNames`, and the
DashboardPage modal continues to open via the existing button click
when no deep-link query params are present.
This commit is contained in:
Roland 2026-05-02 14:31:54 -06:00
parent ae460af8d6
commit a9a460c54c
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
21 changed files with 865 additions and 21 deletions

View file

@ -0,0 +1,48 @@
import React from 'react';
import {render, screen, waitFor} from '../../test-utils';
import {ExtensionInstallSuggestion} from './ExtensionInstallSuggestion';
const setMeta = (version) => {
const existing = document.querySelector('meta[name="wrolpi-extension"]');
if (existing) existing.remove();
if (version === undefined) return;
const meta = document.createElement('meta');
meta.name = 'wrolpi-extension';
meta.content = String(version);
document.head.appendChild(meta);
};
describe('ExtensionInstallSuggestion', () => {
beforeEach(() => {
setMeta(undefined);
window.localStorage.removeItem('wrolpi-extension-banner-dismissed');
});
it('renders nothing when the extension marker meta is present', async () => {
setMeta('0.2.2');
render(<ExtensionInstallSuggestion/>);
// Give the hook a moment in case its initial detect() races; should
// still find the marker on first render.
await waitFor(() => {
expect(screen.queryByText(/Install the WROLPi browser extension/i)).toBeNull();
});
});
it('renders the install message when the marker is absent', async () => {
render(<ExtensionInstallSuggestion/>);
// The hook re-checks once at 500ms before deciding "not installed".
// Wait the recheck out, then assert.
await waitFor(
() => expect(screen.getByText(/Install the WROLPi browser extension/i)).toBeInTheDocument(),
{timeout: 1500},
);
expect(screen.getByText(/Open install page/i)).toBeInTheDocument();
});
it('renders nothing when the user has dismissed the banner', async () => {
window.localStorage.setItem('wrolpi-extension-banner-dismissed', 'true');
render(<ExtensionInstallSuggestion/>);
await new Promise(r => setTimeout(r, 600));
expect(screen.queryByText(/Install the WROLPi browser extension/i)).toBeNull();
});
});