2023-08-15 14:39:45 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-10-05 23:22:42 +02:00
|
|
|
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
2023-08-15 14:39:45 +02:00
|
|
|
|
|
|
|
|
export abstract class BaseClient<Client, ClientConfig, Fetcher> {
|
2024-08-25 22:34:01 +02:00
|
|
|
protected abstract client: Client;
|
2023-08-15 14:39:45 +02:00
|
|
|
|
|
|
|
|
public abstract readonly fetcher: Fetcher;
|
|
|
|
|
|
|
|
|
|
public getBaseUrl(): string {
|
|
|
|
|
const { hostname, port, protocol } = window.location;
|
|
|
|
|
|
|
|
|
|
// if port is 3000 it's probably running from webpack development server
|
2025-01-23 12:15:33 +01:00
|
|
|
const inferredPort = import.meta.env.DEV && port === '3000' ? '4567' : port;
|
2024-04-07 15:22:03 +02:00
|
|
|
return AppStorage.local.getItemParsed('serverBaseURL', `${protocol}//${hostname}:${inferredPort}`);
|
2023-08-15 14:39:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract updateConfig(config: Partial<ClientConfig>): void;
|
|
|
|
|
}
|