Skip to content

Commit 2a0526f

Browse files
committed
action/notifications: fix webui base url for trailing slash #414
1 parent aa9574c commit 2a0526f

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/util/action.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { TorrentWebUI } from "../models/webui";
2+
import { addTrailingSlash } from "./utils";
23

34

45
export function registerClickActionForIcon(webUi: TorrentWebUI | null): (tab: chrome.tabs.Tab) => Promise<void> {
56
const clickActionListener = async (tab: chrome.tabs.Tab) => {
67
if (webUi) {
78
await chrome.tabs.create({
8-
url: webUi.createBaseUrl(),
9+
url: addTrailingSlash(webUi.createBaseUrl()),
910
active: true,
1011
});
1112
}

src/util/messaging.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
IUpdateActionBadgeTextMessage,
1414
TestNotificationMessage
1515
} from "../models/messages";
16-
import { RTASettings } from "../models/settings";
1716
import { SerializedTorrent, Torrent, TorrentUploadConfig } from "../models/torrent";
1817
import { TorrentAddingResult, TorrentWebUI, WebUISettings } from "../models/webui";
1918
import { updateBadgeText } from "./action";
@@ -22,6 +21,7 @@ import { downloadTorrent } from "./download";
2221
import { showNotification } from "./notifications";
2322
import { serializeSettings, convertTorrentToSerialized, convertSerializedToTorrent, deserializeSettings } from "./serializer";
2423
import { Settings } from "./settings";
24+
import { addTrailingSlash } from "./utils";
2525
import { initiateWebUis } from "./webuis";
2626

2727

@@ -212,7 +212,7 @@ function downloadAndAddTorrentToWebUi(webUi: TorrentWebUI, url: string, config:
212212
true,
213213
settings.notificationsDurationMs,
214214
settings.notificationsSoundEnabled,
215-
webUi.createBaseUrl());
215+
addTrailingSlash(webUi.createBaseUrl()));
216216
});
217217
} else {
218218
console.error("No WebUI found for addTorrentMessage:", message);
@@ -221,7 +221,7 @@ function downloadAndAddTorrentToWebUi(webUi: TorrentWebUI, url: string, config:
221221
true,
222222
settings.notificationsDurationMs,
223223
settings.notificationsSoundEnabled,
224-
webUi.createBaseUrl());
224+
addTrailingSlash(webUi.createBaseUrl()));
225225
}
226226
});
227227
}
@@ -259,7 +259,7 @@ function getAutoLabelDirResultForConfig(torrent: Torrent, webUiSettings: WebUISe
259259

260260
function sendTorrentToWebUi(webUi: TorrentWebUI, torrent: Torrent, config: TorrentUploadConfig | null) {
261261
new Settings().loadSettings().then(settings => {
262-
const webUiUrl = webUi.createBaseUrl();
262+
const webUiUrl = addTrailingSlash(webUi.createBaseUrl());
263263
webUi.sendTorrent(torrent, config).then((torrentAddingResult: TorrentAddingResult) => {
264264
console.log(`Torrent sent successfully: ${torrent.name} to -> ${webUi.name}`);
265265
if (settings.notificationsEnabled) {

src/util/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ export function clearListeners(listeners: RegisteredListeners): void {
1414
export function isMatchedByRegexes(url: string, regexes: RegExp[]): boolean {
1515
return regexes.some(regex => regex.test(url));
1616
}
17+
18+
export function addTrailingSlash(url: string): string {
19+
if (!url.endsWith("/")) {
20+
return url + "/";
21+
}
22+
return url;
23+
}

0 commit comments

Comments
 (0)