diff --git a/services/request/src/server/services/Database.ts b/services/request/src/server/services/Database.ts index 6ab5ac2..2609198 100644 --- a/services/request/src/server/services/Database.ts +++ b/services/request/src/server/services/Database.ts @@ -14,9 +14,7 @@ export default class Database extends InternalService /** * The name of the service */ - public get name() { - return "Database"; - } + public readonly NAME = "Database"; /** * Boot the database service diff --git a/services/request/src/server/services/DiscordBot.ts b/services/request/src/server/services/DiscordBot.ts index 8d2ccd0..ba88381 100644 --- a/services/request/src/server/services/DiscordBot.ts +++ b/services/request/src/server/services/DiscordBot.ts @@ -92,9 +92,7 @@ export default class DiscordBot extends InternalService /** * The service name */ - public get name() { - return "Discord Bot"; - } + public readonly NAME = "Discord Bot"; /** * Boot the discord bot diff --git a/services/request/src/server/services/Ipc/SeekerIpcClient.ts b/services/request/src/server/services/Ipc/SeekerIpcClient.ts index cd66b76..1730852 100644 --- a/services/request/src/server/services/Ipc/SeekerIpcClient.ts +++ b/services/request/src/server/services/Ipc/SeekerIpcClient.ts @@ -7,16 +7,12 @@ export default class SeekerIpcClient extends IpcClientService /** * The service name */ - public get name() { - return "Seeker IPC" - } + public readonly NAME = "Seeker IPC"; /** * The path to the socket file */ - public get socketPath() { - return env("SEEKER_IPC_SOCKET"); - } + protected readonly SOCKET_PATH = env("SEEKER_IPC_SOCKET"); // Methods ------------------------------------------------------------------------------------- diff --git a/services/request/src/server/services/MovieSearch.ts b/services/request/src/server/services/MovieSearch.ts index d352290..2f6de6e 100644 --- a/services/request/src/server/services/MovieSearch.ts +++ b/services/request/src/server/services/MovieSearch.ts @@ -35,9 +35,7 @@ export default class MovieSearch extends InternalService /** * The name of the service */ - public get name() { - return "Movie Search"; - } + public readonly NAME = "Movie Search"; /** * Start the service diff --git a/services/request/src/server/services/PlexLibrary.ts b/services/request/src/server/services/PlexLibrary.ts index 59b1fcf..d5383d0 100644 --- a/services/request/src/server/services/PlexLibrary.ts +++ b/services/request/src/server/services/PlexLibrary.ts @@ -38,9 +38,7 @@ export default class PlexLibrary extends InternalService /** * The service name */ - public get name() { - return "Plex Library"; - } + public readonly NAME = "Plex Library"; /** * Boot the Plex library service diff --git a/services/request/src/server/services/TvDb.ts b/services/request/src/server/services/TvDb.ts index 53e89a2..2a5e9b7 100644 --- a/services/request/src/server/services/TvDb.ts +++ b/services/request/src/server/services/TvDb.ts @@ -23,9 +23,7 @@ export default class TvDb extends InternalService /** * The service name */ - public get name() { - return "TVDB"; - } + public readonly NAME = "TVDB"; /** * Boot the service diff --git a/services/request/src/server/services/WebServer/index.ts b/services/request/src/server/services/WebServer/index.ts index 47e4a32..4ddcad7 100644 --- a/services/request/src/server/services/WebServer/index.ts +++ b/services/request/src/server/services/WebServer/index.ts @@ -35,9 +35,7 @@ export default class WebServer extends InternalService /** * The service name */ - public get name() { - return "Web Server"; - } + public readonly NAME = "Web Server"; /** * Register required Fastify plugins diff --git a/services/seeker/src/services/Database.ts b/services/seeker/src/services/Database.ts index eafb4fd..d8967a9 100644 --- a/services/seeker/src/services/Database.ts +++ b/services/seeker/src/services/Database.ts @@ -14,9 +14,7 @@ export default class Database extends InternalService /** * The service name */ - public get name() { - return "Database"; - } + public readonly NAME = "Database"; /** * Boot the database service diff --git a/services/seeker/src/services/IpcInterface.ts b/services/seeker/src/services/IpcInterface.ts index 70b860b..f0b6681 100644 --- a/services/seeker/src/services/IpcInterface.ts +++ b/services/seeker/src/services/IpcInterface.ts @@ -9,16 +9,12 @@ export default class IpcInterface extends IpcServerService /** * The service name */ - public get name() { - return "IPC" - } + public readonly NAME = "IPC"; /** * The path to the socket file */ - public get socketPath() { - return env("IPC_SOCKET_PATH"); - } + public readonly SOCKET_PATH = env("IPC_SOCKET_PATH"); /** * Install the the event handlers diff --git a/services/seeker/src/services/MovieSearch.ts b/services/seeker/src/services/MovieSearch.ts index 6a02b07..2353f7e 100644 --- a/services/seeker/src/services/MovieSearch.ts +++ b/services/seeker/src/services/MovieSearch.ts @@ -41,9 +41,7 @@ export default class MovieSearch extends InternalService /** * The service name */ - public get name() { - return "Movie Search"; - } + public readonly NAME = "Movie Search"; /** * Boot the movie search service diff --git a/services/seeker/src/services/PostProcessor/PostProcessor.ts b/services/seeker/src/services/PostProcessor/PostProcessor.ts index e536df9..1711408 100644 --- a/services/seeker/src/services/PostProcessor/PostProcessor.ts +++ b/services/seeker/src/services/PostProcessor/PostProcessor.ts @@ -47,9 +47,7 @@ export default class PostProcessor extends InternalService /** * The service name */ - public get name() { - return "Post Processor"; - } + public readonly NAME = "Post Processor"; // Methods ------------------------------------------------------------------------------------- diff --git a/services/seeker/src/services/Supervisor.ts b/services/seeker/src/services/Supervisor.ts index f33b8d8..df94a5f 100644 --- a/services/seeker/src/services/Supervisor.ts +++ b/services/seeker/src/services/Supervisor.ts @@ -34,9 +34,7 @@ export default class Supervisor extends InternalService /** * The service name */ - public get name() { - return "Supervisor"; - } + public readonly NAME = "Supervisor"; /** * All services are booted and ready diff --git a/services/seeker/src/services/TorrentManager/TorrentClientIpc.ts b/services/seeker/src/services/TorrentManager/TorrentClientIpc.ts index 5b41b3e..e8f569f 100644 --- a/services/seeker/src/services/TorrentManager/TorrentClientIpc.ts +++ b/services/seeker/src/services/TorrentManager/TorrentClientIpc.ts @@ -63,9 +63,7 @@ export default abstract class TorrentClientIpc extends IpcClientService("Torrent Client"); - - // Boot the IPC socket - return new Promise(async (resolve, reject) => { - console.log("Serving:", process.env["IPC_SOCKET_PATH"]); - await mkdir(dirname(process.env["IPC_SOCKET_PATH"]), { recursive: true }); - ipc.serve(process.env["IPC_SOCKET_PATH"], () => { - this.server = ipc.server; - this.installEventHandlers(this.server); - resolve(); - }); - ipc.server.start(); - }); + await super.boot(); } /** * Install the the event handlers */ - protected installEventHandlers(server: Server) { - this.addEventHandler(server, "add", this.addTorrent); - this.addEventHandler(server, "remove", this.removeTorrent); - this.addEventHandler(server, "list", this.listTorrents); - this.addEventHandler(server, "details", this.torrentDetails); + protected installMessageHandlers() { + this.addMessageHandler("add", this.addTorrent); + this.addMessageHandler("remove", this.removeTorrent); + this.addMessageHandler("list", this.listTorrents); + this.addMessageHandler("details", this.torrentDetails); this.torrentClient.on("torrent_finished", this.torrentFinished.bind(this)); } - /** - * Handle a specific event - */ - protected addEventHandler(server: Server, method: string, handle: (...args: any[]) => Promise) { - server.on(method, async (message: any, socket: Socket) => { - try { - let response = await handle.apply(this, message); - this.server.emit(socket, method, { response }); - } catch (error) { - console.log("Error:", method, error); - this.server.emit(socket, method, { - response: undefined, - error - }); - } - }); - } - // Interface Methods --------------------------------------------------------------------------- /** * Add a torrent to the client */ - protected async addTorrent(torrentInfo: IAddTorrent, downloadPath?: string) { + // protected async addTorrent(torrentInfo: IAddTorrent, downloadPath?: string) { + protected async addTorrent(payload: { torrent: IAddTorrent, downloadPath?: string }) { let torrent: WebTorrent.Torrent; - if (typeof torrentInfo == "string") { - torrent = await this.torrentClient.add(torrentInfo, { downloadPath }); + if (typeof payload.torrent == "string") { + torrent = await this.torrentClient.add(payload.torrent, { downloadPath: payload.downloadPath }); } else { - torrent = await this.torrentClient.add(Buffer.from(torrentInfo.data), { downloadPath }); + torrent = await this.torrentClient.add(Buffer.from(payload.torrent.data), { downloadPath: payload.downloadPath }); } return torrent.infoHash; } @@ -144,11 +99,11 @@ export default class IpcInterface extends InternalService /** * Broadcast a message to the connected clients */ - protected broadcast(method: string, ...message: any[]) { - for (let socket of (ipc.server).sockets) { - this.server.emit(socket, method, message); - } - } + // protected broadcast(method: string, ...message: any[]) { + // for (let socket of (ipc.server).sockets) { + // this.server.emit(socket, method, message); + // } + // } /** * Notify connected clients that a torrent has finished diff --git a/services/torrent-client/src/services/TorrentClient.ts b/services/torrent-client/src/services/TorrentClient.ts index 2917f9a..133eaad 100644 --- a/services/torrent-client/src/services/TorrentClient.ts +++ b/services/torrent-client/src/services/TorrentClient.ts @@ -45,9 +45,7 @@ export class TorrentClient extends InternalService /** * The service name */ - public get name() { - return "Torrent Client" - } + public readonly NAME = "Torrent Client"; /** * Boot the service