Skip to content

Commit

Permalink
verify deluge connection before attempting to connect to windscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbasPL committed Dec 26, 2021
1 parent ddd66db commit edd8f95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/deluge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ if (!password || password.length == 0) {

// functions

export async function testDelugeConnection() {
try {
const client = new Deluge({
baseUrl: url,
password: password,
});

await client.connect();
} catch (error) {
throw new Error(`Failed to connect to deluge: ${error.message}`);
}
}

export async function updateDelugePort(port: number) {
try {
const client = new Deluge({
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dotenv/config';
import {updateDelugePort} from './deluge';
import {testDelugeConnection, updateDelugePort} from './deluge';
import {getMyAccountCsrfToken, getPortForwardingInfo, login, removeEphemeralPort, requestMatchingEphemeralPort} from './windscribe';

async function run() {
try {
// try to connect to deluge once before we start spamming windscribe with pointless requests
await testDelugeConnection();

// get a new session each time
const sessionCookie = await login();

Expand Down

0 comments on commit edd8f95

Please sign in to comment.