From 456e6a7219338461c58b762bfcecb87012be32ba Mon Sep 17 00:00:00 2001 From: Imran Rahman Date: Sat, 16 Jul 2022 13:42:41 +0600 Subject: [PATCH] optional options for custom remote db url --- src/timer-db/TimerDB.ts | 4 ++-- src/timer-db/storage/PouchDBStorage.ts | 4 ++-- src/timer-db/storage/Storage.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/timer-db/TimerDB.ts b/src/timer-db/TimerDB.ts index d9378c3..43c778d 100644 --- a/src/timer-db/TimerDB.ts +++ b/src/timer-db/TimerDB.ts @@ -9,8 +9,8 @@ export class TimerDB { this.storage = new PouchDBStorage(); } - startSync(params: { username: string; password: string }): void { - this.storage.connectRemoteDB(params.username, params.password); + startSync(params: { username: string; password: string; options?: {dbURL: string} }): void { + this.storage.connectRemoteDB(params.username, params.password, params.options); } // TODO: provide a way to get only sessions with solves. diff --git a/src/timer-db/storage/PouchDBStorage.ts b/src/timer-db/storage/PouchDBStorage.ts index 2e8db34..fb92480 100644 --- a/src/timer-db/storage/PouchDBStorage.ts +++ b/src/timer-db/storage/PouchDBStorage.ts @@ -37,8 +37,8 @@ export class PouchDBStorage { // }); } - connectRemoteDB(username: string, password: string): void { - const url = new URL(DB_URL); + connectRemoteDB(username: string, password: string, options?: {dbURL: string} ): void { + const url = options === null ? new URL(DB_URL) : new URL(options.dbURL) url.username = username; url.password = password; url.pathname = `results-${localStorage.timerDBUsername}`; diff --git a/src/timer-db/storage/Storage.ts b/src/timer-db/storage/Storage.ts index 1dd8311..369751f 100644 --- a/src/timer-db/storage/Storage.ts +++ b/src/timer-db/storage/Storage.ts @@ -10,7 +10,7 @@ import { SessionUUID } from "../UUID"; export type SyncChangeListener = (attempt: StoredAttempt[]) => void; export declare interface Storage { - connectRemoteDB(username: string, password: string): void; + connectRemoteDB(username: string, password: string, options?: {dbURL: string} ): void; // Sessions createSession(