@ -1,37 +0,0 @@ | |||||
import { Connection } from "typeorm"; | |||||
import connectToDatabase from "@autoplex/database"; | |||||
import { env, secret } from "@autoplex/utils"; | |||||
import { InternalService } from "@autoplex/microservice"; | |||||
import Application from "../Application"; | |||||
export default class Database extends InternalService<Application> | |||||
{ | |||||
/** | |||||
* The active database connection | |||||
*/ | |||||
protected connection!: Connection; | |||||
/** | |||||
* The service name | |||||
*/ | |||||
public readonly NAME = "Database"; | |||||
/** | |||||
* Boot the database service | |||||
*/ | |||||
public async boot() { | |||||
let host = env("DB_HOST"); | |||||
let port = parseInt(env("DB_PORT")); | |||||
let username = env("DB_USER"); | |||||
let password = await secret(env("DB_PASSWORD_FILE")); | |||||
let database = env("DB_DATABASE"); | |||||
this.connection = await connectToDatabase(host, port, username, password, database); | |||||
} | |||||
/** | |||||
* Shutdown the database service | |||||
*/ | |||||
public async shutdown() { | |||||
await this.connection.close(); | |||||
} | |||||
} |
@ -0,0 +1,50 @@ | |||||
import Application from "../Application"; | |||||
import { IpcClient } from "@autoplex-api/torrent"; | |||||
interface IResponse { | |||||
response?: any, | |||||
error?: string | Error | |||||
} | |||||
/** | |||||
* Declare EventEmitter types | |||||
*/ | |||||
interface TorrentIpcEvents { | |||||
"connected": () => void | |||||
} | |||||
/** | |||||
* Torrent IPC events | |||||
*/ | |||||
declare interface TorrentIpc { | |||||
on<U extends keyof TorrentIpcEvents>(event: U, listener: TorrentIpcEvents[U]): this, | |||||
emit<U extends keyof TorrentIpcEvents>(event: U, ...args: Parameters<TorrentIpcEvents[U]>): boolean | |||||
} | |||||
/** | |||||
* The torrent client IPC service | |||||
*/ | |||||
class TorrentIpc extends IpcClient<Application> | |||||
{ | |||||
/** | |||||
* Install the message event handlers | |||||
*/ | |||||
protected installMessageHandlers() { | |||||
this.addListener("torrent_finished", this.onTorrentFinished); | |||||
} | |||||
/** | |||||
* Invoked when a torrent has finished downloading | |||||
*/ | |||||
protected async onTorrentFinished(infoHash: string) {} | |||||
/** | |||||
* Emit an event when connected | |||||
*/ | |||||
protected onConnect() { | |||||
super.onConnect(); | |||||
this.emit("connected"); | |||||
} | |||||
} | |||||
export default TorrentIpc; |
@ -1,25 +0,0 @@ | |||||
import Application from "../../Application"; | |||||
import { IpcClient } from "@autoplex-api/torrent"; | |||||
interface IResponse { | |||||
response?: any, | |||||
error?: string | Error | |||||
} | |||||
/** | |||||
* The torrent client IPC service | |||||
*/ | |||||
export default abstract class TorrentClientIpc extends IpcClient<Application> | |||||
{ | |||||
/** | |||||
* Install the message event handlers | |||||
*/ | |||||
protected installMessageHandlers() { | |||||
this.addListener("torrent_finished", this.onTorrentFinished); | |||||
} | |||||
/** | |||||
* Invoked when a torrent has finished downloading | |||||
*/ | |||||
protected async onTorrentFinished(infoHash: string) {} | |||||
} |
@ -1,3 +0,0 @@ | |||||
import TorrentManager from "./TorrentManager"; | |||||
export default TorrentManager; |
@ -1,15 +1,16 @@ | |||||
import Database from "./Database"; | |||||
import IpcInterface from "./IpcInterface"; | |||||
import MovieSearch from "./MovieSearch"; | |||||
import PostProcessor from "./PostProcessor"; | |||||
import Supervisor from "./Supervisor"; | |||||
import TorrentManager from "./TorrentManager"; | |||||
export { DatabaseService } from "@autoplex/database"; | |||||
import IpcInterface from "./IpcInterface"; | |||||
import MovieSearch from "./MovieSearch"; | |||||
import PostProcessor from "./PostProcessor"; | |||||
import Supervisor from "./Supervisor"; | |||||
import TorrentIpc from "./TorrentIpc"; | |||||
import TorrentManager from "./TorrentManager"; | |||||
export default { | |||||
Database, | |||||
export { | |||||
IpcInterface, | IpcInterface, | ||||
MovieSearch, | MovieSearch, | ||||
PostProcessor, | PostProcessor, | ||||
Supervisor, | Supervisor, | ||||
TorrentManager, | |||||
TorrentIpc, | |||||
TorrentManager | |||||
} | } |