Skip to content

Commit 64263fe

Browse files
authored
Merge branch 'master' into 396-link-catching-post-vs-get
2 parents e5ea95a + a747c6a commit 64263fe

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ It supports the following BitTorrent clients:
1717
- Transmission
1818
- Porla (new!)
1919
- Tixati
20+
- QNAP DownloadStation
2021

2122
## How do i get it running?
2223

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.0.1",
2+
"version": "2.0.2",
33
"name": "Remote Torrent Adder",
44
"short_name": "RTA",
55
"icons": {

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/download.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ export async function downloadTorrent(url: string): Promise<Torrent> {
2323

2424
const torrentBlob: Blob = await response.blob();
2525
const torrentData: string = await convertBlobToString(torrentBlob);
26+
let decodedTorrentData: any;
2627
try {
27-
validateTorrentData(response, torrentData);
28+
decodedTorrentData = decodeTorrentDataAndValidate(response, torrentData);
2829
} catch (error) {
2930
reject(error);
3031
return;
31-
}
32-
const decodedTorrentData = bencode.decode(Buffer.from(torrentData, 'ascii'));
32+
};
3333

3434
resolve({
3535
data: torrentBlob,
@@ -43,15 +43,20 @@ export async function downloadTorrent(url: string): Promise<Torrent> {
4343
});
4444
}
4545

46-
function validateTorrentData(response: Response, data: string): void {
47-
if (!data || data.length < 10 || !data.startsWith("d8:announce")) {
46+
function decodeTorrentDataAndValidate(response: Response, torrentData: string): any {
47+
try {
48+
return bencode.decode(Buffer.from(torrentData, 'ascii'));
49+
} catch (error) {
4850
let contentType = response.headers.get("Content-Type");
4951
if (contentType) {
5052
const semicolonPos = contentType.indexOf(";");
5153
contentType = contentType.slice(0, semicolonPos).trim();
5254
} else {
5355
contentType = "unknown"
5456
}
55-
throw new Error("Received " + contentType + " content instead of a .torrent file");
57+
58+
console.error("Invalid torrent data received", torrentData);
59+
60+
throw new Error("Received " + contentType + " instead of a torrent file. Please check the devtools view for details.");
5661
}
5762
}

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
@@ -23,3 +23,10 @@ export function getBaseUrl(url: string): string {
2323
return '';
2424
}
2525
}
26+
27+
export function addTrailingSlash(url: string): string {
28+
if (!url.endsWith("/")) {
29+
return url + "/";
30+
}
31+
return url;
32+
}

0 commit comments

Comments
 (0)