|
@ -1,6 +1,7 @@ |
|
|
import { IpcClientService } from "@autoplex/ipc"; |
|
|
import { IpcClientService } from "@autoplex/ipc"; |
|
|
import { Microservice } from "@autoplex/microservice"; |
|
|
import { Microservice } from "@autoplex/microservice"; |
|
|
import { SOCKET_PATH } from "./constants"; |
|
|
import { SOCKET_PATH } from "./constants"; |
|
|
|
|
|
import { IMovie, IMovieDetails } from "./schema"; |
|
|
|
|
|
|
|
|
export class IpcClient<M extends Microservice = Microservice> extends IpcClientService<M> |
|
|
export class IpcClient<M extends Microservice = Microservice> extends IpcClientService<M> |
|
|
{ |
|
|
{ |
|
@ -17,28 +18,48 @@ export class IpcClient<M extends Microservice = Microservice> extends IpcClientS |
|
|
/** |
|
|
/** |
|
|
* Get the details of a movie |
|
|
* Get the details of a movie |
|
|
*/ |
|
|
*/ |
|
|
public async details(tmdbId: number) { |
|
|
|
|
|
return await this.request("details", tmdbId); |
|
|
|
|
|
|
|
|
public async movieDetails(tmdbId: number) { |
|
|
|
|
|
let result = await this.request("details", tmdbId); |
|
|
|
|
|
if (result.error) { |
|
|
|
|
|
console.error("Failed to fetch movie details:", result.error); |
|
|
|
|
|
throw new Error("Failed to fetch movie details"); |
|
|
|
|
|
} |
|
|
|
|
|
return <IMovieDetails>result.data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Find a movie by its IMDb ID |
|
|
* Find a movie by its IMDb ID |
|
|
*/ |
|
|
*/ |
|
|
public async findFromImdb(imdbId: string) { |
|
|
|
|
|
return await this.request("find", imdbId); |
|
|
|
|
|
|
|
|
public async findMovieFromImdb(imdbId: string) { |
|
|
|
|
|
let result = await this.request("find", imdbId); |
|
|
|
|
|
if (result.error) { |
|
|
|
|
|
console.error("Failed to find a movie by its IMDb ID:", result.error); |
|
|
|
|
|
throw new Error("Failed to find a movie by its IMDb ID"); |
|
|
|
|
|
} |
|
|
|
|
|
return <IMovie>result.data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Search for a movie |
|
|
* Search for a movie |
|
|
*/ |
|
|
*/ |
|
|
public async search(query: string, year?: number, page?: number) { |
|
|
|
|
|
return await this.request("search", { query, year, page }); |
|
|
|
|
|
|
|
|
public async searchMovie(query: string, year?: number, page?: number) { |
|
|
|
|
|
let result = await this.request("search", { query, year, page }); |
|
|
|
|
|
if (result.error) { |
|
|
|
|
|
console.error("Failed to search for a movie:", result.error); |
|
|
|
|
|
throw new Error("Failed to search for a movie"); |
|
|
|
|
|
} |
|
|
|
|
|
return <IMovie>result.data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Verify an IMDb ID |
|
|
* Verify an IMDb ID |
|
|
*/ |
|
|
*/ |
|
|
public async verifyImdbId(imdbId: string) { |
|
|
public async verifyImdbId(imdbId: string) { |
|
|
return await this.request("verify_imdb_id", imdbId); |
|
|
|
|
|
|
|
|
let result = await this.request("verify_imdb_id", imdbId); |
|
|
|
|
|
if (result.error) { |
|
|
|
|
|
console.error("Failed to verify an IMDb ID:", result.error); |
|
|
|
|
|
throw new Error("Failed to verify an IMDb ID"); |
|
|
|
|
|
} |
|
|
|
|
|
return <boolean>result.data; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |