70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import { EndpointBrokerManagerFS } from "$lib/server/broker-utils/FileSystem/Endpoint"
|
|
import type { IEndpoint } from "./endpoints-interfaces"
|
|
|
|
|
|
// UGLY: refactor this
|
|
export class EndpointManagerApp {
|
|
|
|
private static initialized = false
|
|
/** Here we store all endpoints
|
|
* - Key: path
|
|
* - Value: any IEndpointFS
|
|
*/
|
|
|
|
public static get ready() {
|
|
return EndpointManagerApp.initialized
|
|
}
|
|
|
|
public static init() {
|
|
// TODO: Read all files
|
|
|
|
// TODO: QUICK parse them
|
|
|
|
// TODO: Initialize a file watcher
|
|
|
|
}
|
|
|
|
|
|
public static async activateEndpoint(path: string): Promise<boolean> {
|
|
return await EndpointBrokerManagerFS.activateEndpoint(path)
|
|
}
|
|
|
|
public static async deactivateEndpoint(path: string): Promise<boolean> {
|
|
return await EndpointBrokerManagerFS.deactivateEndpoint(path)
|
|
}
|
|
|
|
public static async getStatus(path: string) {
|
|
return await EndpointBrokerManagerFS.getStatus(path)
|
|
}
|
|
|
|
|
|
public static getEndpointByPath(path: string): IEndpoint | null {
|
|
|
|
const endpoint = EndpointBrokerManagerFS.getEndpointByPath(path)
|
|
|
|
if(!endpoint) {
|
|
return null
|
|
}
|
|
|
|
return endpoint.toIEndpoint()
|
|
|
|
}
|
|
|
|
|
|
public static async getAll(): Promise<IEndpoint[]> {
|
|
|
|
const endpoints = await EndpointBrokerManagerFS.getAll()
|
|
|
|
return endpoints.map( (endpoint) => {
|
|
return endpoint.toIEndpoint()
|
|
})
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|