import type { IManualBroker, Manual } from "$lib/server/classes/endpoints/manual-endpoint"; import { EndpointType } from "$lib/server/enums/endpoints"; import { EndpointBrokerManagerFS } from "./Endpoint-Manager"; import type { ManualFS } from "./endpoints/manual-fs"; export class ManualFSBroker implements IManualBroker { public async init(): Promise { // Do nothing? } public async getManualByPath(path: string): Promise { const endpoint = EndpointBrokerManagerFS.getEndpointByPath(path) if (!endpoint) { return null } if (endpoint.type !== EndpointType.MANUAL) { // UGLY: be specific throw new Error("This is not a Manual Endpoint") } return endpoint.toIEndpoint() as Manual } public async getAllManuals(): Promise { const endpoints = (await EndpointBrokerManagerFS.getAll()).filter(async (endpoint) => { if (endpoint.type !== EndpointType.MANUAL) { return false } return true }) as ManualFS[] return endpoints.map( (endpoint) => { return endpoint.toIEndpoint() as Manual }) } public async activateEndpointByPath(path: string): Promise { return await EndpointBrokerManagerFS.activateEndpoint(path) } public async deactivateEndpointByPath(path: string): Promise { return await EndpointBrokerManagerFS.deactivateEndpoint(path) } }