Browse Source

Update services to match the new microservice name changes

dev
David Ludwig 4 years ago
parent
commit
1d7f8bb923
18 changed files with 43 additions and 124 deletions
  1. +1
    -3
      services/request/src/server/services/Database.ts
  2. +1
    -3
      services/request/src/server/services/DiscordBot.ts
  3. +2
    -6
      services/request/src/server/services/Ipc/SeekerIpcClient.ts
  4. +1
    -3
      services/request/src/server/services/MovieSearch.ts
  5. +1
    -3
      services/request/src/server/services/PlexLibrary.ts
  6. +1
    -3
      services/request/src/server/services/TvDb.ts
  7. +1
    -3
      services/request/src/server/services/WebServer/index.ts
  8. +1
    -3
      services/seeker/src/services/Database.ts
  9. +2
    -6
      services/seeker/src/services/IpcInterface.ts
  10. +1
    -3
      services/seeker/src/services/MovieSearch.ts
  11. +1
    -3
      services/seeker/src/services/PostProcessor/PostProcessor.ts
  12. +1
    -3
      services/seeker/src/services/Supervisor.ts
  13. +1
    -3
      services/seeker/src/services/TorrentManager/TorrentClientIpc.ts
  14. +1
    -3
      services/seeker/src/services/TorrentManager/TorrentManager.ts
  15. +1
    -1
      services/torrent-client/src/database/entities/Torrent.ts
  16. +1
    -3
      services/torrent-client/src/services/Database.ts
  17. +24
    -69
      services/torrent-client/src/services/IpcInterface.ts
  18. +1
    -3
      services/torrent-client/src/services/TorrentClient.ts

+ 1
- 3
services/request/src/server/services/Database.ts View File

@ -14,9 +14,7 @@ export default class Database extends InternalService<Application>
/**
* The name of the service
*/
public get name() {
return "Database";
}
public readonly NAME = "Database";
/**
* Boot the database service


+ 1
- 3
services/request/src/server/services/DiscordBot.ts View File

@ -92,9 +92,7 @@ export default class DiscordBot extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "Discord Bot";
}
public readonly NAME = "Discord Bot";
/**
* Boot the discord bot


+ 2
- 6
services/request/src/server/services/Ipc/SeekerIpcClient.ts View File

@ -7,16 +7,12 @@ export default class SeekerIpcClient extends IpcClientService<Application>
/**
* 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 -------------------------------------------------------------------------------------


+ 1
- 3
services/request/src/server/services/MovieSearch.ts View File

@ -35,9 +35,7 @@ export default class MovieSearch extends InternalService<Application>
/**
* The name of the service
*/
public get name() {
return "Movie Search";
}
public readonly NAME = "Movie Search";
/**
* Start the service


+ 1
- 3
services/request/src/server/services/PlexLibrary.ts View File

@ -38,9 +38,7 @@ export default class PlexLibrary extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "Plex Library";
}
public readonly NAME = "Plex Library";
/**
* Boot the Plex library service


+ 1
- 3
services/request/src/server/services/TvDb.ts View File

@ -23,9 +23,7 @@ export default class TvDb extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "TVDB";
}
public readonly NAME = "TVDB";
/**
* Boot the service


+ 1
- 3
services/request/src/server/services/WebServer/index.ts View File

@ -35,9 +35,7 @@ export default class WebServer extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "Web Server";
}
public readonly NAME = "Web Server";
/**
* Register required Fastify plugins


+ 1
- 3
services/seeker/src/services/Database.ts View File

@ -14,9 +14,7 @@ export default class Database extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "Database";
}
public readonly NAME = "Database";
/**
* Boot the database service


+ 2
- 6
services/seeker/src/services/IpcInterface.ts View File

@ -9,16 +9,12 @@ export default class IpcInterface extends IpcServerService<Application>
/**
* 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


+ 1
- 3
services/seeker/src/services/MovieSearch.ts View File

@ -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


+ 1
- 3
services/seeker/src/services/PostProcessor/PostProcessor.ts View File

@ -47,9 +47,7 @@ export default class PostProcessor extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "Post Processor";
}
public readonly NAME = "Post Processor";
// Methods -------------------------------------------------------------------------------------


+ 1
- 3
services/seeker/src/services/Supervisor.ts View File

@ -34,9 +34,7 @@ export default class Supervisor extends InternalService<Application>
/**
* The service name
*/
public get name() {
return "Supervisor";
}
public readonly NAME = "Supervisor";
/**
* All services are booted and ready


+ 1
- 3
services/seeker/src/services/TorrentManager/TorrentClientIpc.ts View File

@ -63,9 +63,7 @@ export default abstract class TorrentClientIpc extends IpcClientService<Applicat
/**
* The path to the socket file
*/
public get socketPath() {
return env("TORRENT_CLIENT_IPC_SOCKET");
}
public readonly SOCKET_PATH = env("TORRENT_CLIENT_IPC_SOCKET");
/**
* Install the event handlers for the IPC socket


+ 1
- 3
services/seeker/src/services/TorrentManager/TorrentManager.ts View File

@ -37,9 +37,7 @@ export default class TorrentManager extends TorrentClientIpc
/**
* The service name
*/
public get name() {
return "Torrent Manager";
}
public readonly NAME = "Torrent Manager";
/**
* Boot the Torrent Manager service


+ 1
- 1
services/torrent-client/src/database/entities/Torrent.ts View File

@ -1,4 +1,4 @@
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity, ManyToOne } from "typeorm";
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity } from "typeorm";
import WebTorrent from "webtorrent-hybrid";
@Entity()


+ 1
- 3
services/torrent-client/src/services/Database.ts View File

@ -13,9 +13,7 @@ export default class Database extends InternalService
/**
* The service name
*/
public get name() {
return "Database";
}
public readonly NAME = "Database";
/**
* Boot the database service


+ 24
- 69
services/torrent-client/src/services/IpcInterface.ts View File

@ -1,19 +1,15 @@
import { mkdir } from "fs/promises";
import { dirname } from "path";
import ipc from "node-ipc";
import type { Server } from "node-ipc";
import { Socket } from "net";
import assert from "assert";
import WebTorrent from "webtorrent-hybrid";
import TorrentClient from "./TorrentClient";
import { InternalService, Microservice } from "@autoplex/microservice";
import { IpcServerService } from "@autoplex/microservice";
import { env } from "@autoplex/utils";
type IAddTorrent = string | {
type: "Buffer",
data: number[]
}
export default class IpcInterface extends InternalService
export default class IpcInterface extends IpcServerService
{
/**
* The torrent client instance
@ -21,87 +17,46 @@ export default class IpcInterface extends InternalService
protected torrentClient!: TorrentClient;
/**
* Quick reference to the IPC server
*/
protected server!: Server;
/**
* Create a new IPC interface
* The service name
*/
public constructor(app: Microservice) {
super(app);
ipc.config.id = "torrent-client";
ipc.config.retry = 1500;
ipc.config.silent = true;
}
public readonly NAME = "IPC";
/**
* The service name
* The path to the socket file
*/
public get name() {
return "IPC";
}
protected readonly SOCKET_PATH = env("IPC_SOCKET_PATH");
/**
* Boot the IPC interface
*/
public boot() {
// Store a reference to the torrent client
public async boot() {
this.torrentClient = this.app.service<TorrentClient>("Torrent Client");
// Boot the IPC socket
return new Promise<void>(async (resolve, reject) => {
console.log("Serving:", process.env["IPC_SOCKET_PATH"]);
await mkdir(dirname(<string>process.env["IPC_SOCKET_PATH"]), { recursive: true });
ipc.serve(<string>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<any>) {
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 <Socket[]>(<any>ipc.server).sockets) {
this.server.emit(socket, method, message);
}
}
// protected broadcast(method: string, ...message: any[]) {
// for (let socket of <Socket[]>(<any>ipc.server).sockets) {
// this.server.emit(socket, method, message);
// }
// }
/**
* Notify connected clients that a torrent has finished


+ 1
- 3
services/torrent-client/src/services/TorrentClient.ts View File

@ -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


Loading…
Cancel
Save