Compare commits
2 Commits
graphql-re
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afead56a74 | ||
| f65a24da25 |
23
models/graphql/resolvers.ts
Normal file
23
models/graphql/resolvers.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
export const resolvers = {
|
||||||
|
Query: {
|
||||||
|
_empty: (): null => null,
|
||||||
|
},
|
||||||
|
|
||||||
|
Mutation: {
|
||||||
|
addTorrent: async (_: any, { input }: any, context: any) => {
|
||||||
|
const { broker } = context;
|
||||||
|
if (!broker) throw new Error("Broker not available in context");
|
||||||
|
|
||||||
|
return broker.call("qbittorrent.addTorrent", {
|
||||||
|
torrentToDownload: input.torrentToDownload,
|
||||||
|
comicObjectId: input.comicObjectId,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
JSON: {
|
||||||
|
__parseValue: (value: any) => value,
|
||||||
|
__serialize: (value: any) => value,
|
||||||
|
__parseLiteral: (ast: any) => ast.value,
|
||||||
|
},
|
||||||
|
};
|
||||||
25
models/graphql/typedef.ts
Normal file
25
models/graphql/typedef.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { gql } from "graphql-tag";
|
||||||
|
|
||||||
|
export const typeDefs = gql`
|
||||||
|
scalar JSON
|
||||||
|
|
||||||
|
input AddTorrentInput {
|
||||||
|
torrentToDownload: String!
|
||||||
|
comicObjectId: ID!
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddTorrentResult {
|
||||||
|
result: JSON
|
||||||
|
}
|
||||||
|
|
||||||
|
type Query {
|
||||||
|
_empty: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type Mutation {
|
||||||
|
"""
|
||||||
|
Add a torrent to qBittorrent
|
||||||
|
"""
|
||||||
|
addTorrent(input: AddTorrentInput!): AddTorrentResult
|
||||||
|
}
|
||||||
|
`;
|
||||||
890
package-lock.json
generated
890
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -46,10 +46,13 @@
|
|||||||
"typescript": "^4.9.3"
|
"typescript": "^4.9.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@graphql-tools/schema": "^10.0.31",
|
||||||
"@robertklep/qbittorrent": "^1.0.1",
|
"@robertklep/qbittorrent": "^1.0.1",
|
||||||
|
"axios": "^1.7.9",
|
||||||
|
"graphql": "^16.13.1",
|
||||||
|
"graphql-tag": "^2.12.6",
|
||||||
"ioredis": "^5.0.0",
|
"ioredis": "^5.0.0",
|
||||||
"kafkajs": "^2.2.4",
|
"kafkajs": "^2.2.4",
|
||||||
"axios": "^1.7.9",
|
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"moleculer": "^0.14.34",
|
"moleculer": "^0.14.34",
|
||||||
"moleculer-web": "^0.10.7",
|
"moleculer-web": "^0.10.7",
|
||||||
|
|||||||
@@ -1,7 +1,28 @@
|
|||||||
import fs from "fs";
|
import type { IncomingMessage, ServerResponse } from "http";
|
||||||
import { Service, ServiceBroker } from "moleculer";
|
import type { ServiceBroker } from "moleculer";
|
||||||
|
import { Service } from "moleculer";
|
||||||
import ApiGateway from "moleculer-web";
|
import ApiGateway from "moleculer-web";
|
||||||
|
|
||||||
|
interface GraphQLRequest extends IncomingMessage {
|
||||||
|
body: {
|
||||||
|
query: string;
|
||||||
|
variables?: Record<string, unknown>;
|
||||||
|
operationName?: string;
|
||||||
|
};
|
||||||
|
$params: {
|
||||||
|
query?: string;
|
||||||
|
variables?: string;
|
||||||
|
operationName?: string;
|
||||||
|
};
|
||||||
|
$ctx: {
|
||||||
|
broker: ServiceBroker;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GraphQLError {
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default class ApiService extends Service {
|
export default class ApiService extends Service {
|
||||||
constructor(broker: ServiceBroker) {
|
constructor(broker: ServiceBroker) {
|
||||||
super(broker);
|
super(broker);
|
||||||
@@ -46,9 +67,61 @@ export default class ApiService extends Service {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "/logs",
|
path: "/acquisition-graphql",
|
||||||
use: [ApiGateway.serveStatic("logs")],
|
whitelist: ["acquisition-graphql.query"],
|
||||||
|
cors: {
|
||||||
|
origin: "*",
|
||||||
|
methods: ["GET", "POST", "OPTIONS"],
|
||||||
|
allowedHeaders: ["*"],
|
||||||
|
credentials: false,
|
||||||
|
maxAge: 3600,
|
||||||
},
|
},
|
||||||
|
aliases: {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
"POST /": async (req: GraphQLRequest, res: ServerResponse) => {
|
||||||
|
try {
|
||||||
|
const { query, variables, operationName } = req.body;
|
||||||
|
const result = await req.$ctx.broker.call("acquisition-graphql.query", {
|
||||||
|
query,
|
||||||
|
variables,
|
||||||
|
operationName,
|
||||||
|
});
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
res.end(JSON.stringify(result));
|
||||||
|
} catch (error: unknown) {
|
||||||
|
res.statusCode = 500;
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
res.end(JSON.stringify({ errors: [{ message: (error as GraphQLError).message }] }));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
"GET /": async (req: GraphQLRequest, res: ServerResponse) => {
|
||||||
|
try {
|
||||||
|
const { query, variables: variablesStr, operationName } = req.$params;
|
||||||
|
const variables = variablesStr ? JSON.parse(variablesStr) : undefined;
|
||||||
|
const result = await req.$ctx.broker.call("acquisition-graphql.query", {
|
||||||
|
query,
|
||||||
|
variables,
|
||||||
|
operationName,
|
||||||
|
});
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
res.end(JSON.stringify(result));
|
||||||
|
} catch (error: unknown) {
|
||||||
|
res.statusCode = 500;
|
||||||
|
res.setHeader("Content-Type", "application/json");
|
||||||
|
res.end(JSON.stringify({ errors: [{ message: (error as GraphQLError).message }] }));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
bodyParsers: { json: { strict: false, limit: "1MB" } },
|
||||||
|
mappingPolicy: "restrict",
|
||||||
|
logging: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
path: "/logs",
|
||||||
|
use: [ApiGateway.serveStatic("logs")],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
log4XXResponses: false,
|
log4XXResponses: false,
|
||||||
logRequestParams: true,
|
logRequestParams: true,
|
||||||
@@ -62,7 +135,7 @@ export default class ApiService extends Service {
|
|||||||
events: {},
|
events: {},
|
||||||
|
|
||||||
methods: {},
|
methods: {},
|
||||||
started(): any {},
|
started(): void {},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
"use strict";
|
import type { Producer } from "kafkajs";
|
||||||
import { Kafka } from "kafkajs";
|
import { Kafka } from "kafkajs";
|
||||||
import type { Context, ServiceBroker, ServiceSchema } from "moleculer";
|
import type { Context, ServiceBroker } from "moleculer";
|
||||||
import { Errors, Service } from "moleculer";
|
import { Errors, Service } from "moleculer";
|
||||||
|
|
||||||
|
interface Issue {
|
||||||
|
id: string;
|
||||||
|
number: number;
|
||||||
|
}
|
||||||
|
|
||||||
interface Comic {
|
interface Comic {
|
||||||
wanted: {
|
wanted: {
|
||||||
markEntireVolumeWanted?: boolean;
|
markEntireVolumeWanted?: boolean;
|
||||||
issues?: any[];
|
issues?: Issue[];
|
||||||
volume: {
|
volume: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -15,22 +20,20 @@ interface Comic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class AutoDownloadService extends Service {
|
export default class AutoDownloadService extends Service {
|
||||||
private kafkaProducer: any;
|
private kafkaProducer!: Producer;
|
||||||
|
|
||||||
private readonly BATCH_SIZE = 100; // Adjust based on your system capacity
|
private readonly BATCH_SIZE = 100;
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore -- Moleculer requires this constructor signature for service instantiation
|
||||||
constructor(
|
constructor(broker: ServiceBroker) {
|
||||||
public broker: ServiceBroker,
|
|
||||||
schema: ServiceSchema<{}> = { name: "autodownload" },
|
|
||||||
) {
|
|
||||||
super(broker);
|
super(broker);
|
||||||
this.parseServiceSchema({
|
this.parseServiceSchema({
|
||||||
name: "autodownload",
|
name: "autodownload",
|
||||||
actions: {
|
actions: {
|
||||||
searchWantedComics: {
|
searchWantedComics: {
|
||||||
rest: "POST /searchWantedComics",
|
rest: "POST /searchWantedComics",
|
||||||
handler: async (ctx: Context<{}>) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
handler: async (ctx: Context<Record<string, never>>) => {
|
||||||
try {
|
try {
|
||||||
/* eslint-disable no-await-in-loop */
|
/* eslint-disable no-await-in-loop */
|
||||||
let page = 1;
|
let page = 1;
|
||||||
@@ -99,7 +102,7 @@ export default class AutoDownloadService extends Service {
|
|||||||
async started() {
|
async started() {
|
||||||
const kafka = new Kafka({
|
const kafka = new Kafka({
|
||||||
clientId: "comic-search-service",
|
clientId: "comic-search-service",
|
||||||
brokers: [process.env.KAFKA_BROKER_URI],
|
brokers: [process.env.KAFKA_BROKER_URI || "localhost:9092"],
|
||||||
});
|
});
|
||||||
this.kafkaProducer = kafka.producer();
|
this.kafkaProducer = kafka.producer();
|
||||||
await this.kafkaProducer.connect();
|
await this.kafkaProducer.connect();
|
||||||
|
|||||||
@@ -1,30 +1,90 @@
|
|||||||
import type { EachMessagePayload } from "kafkajs";
|
import type { Consumer, EachMessagePayload, Producer } from "kafkajs";
|
||||||
import { Kafka, logLevel } from "kafkajs";
|
import { Kafka, logLevel } from "kafkajs";
|
||||||
import { isNil, isUndefined } from "lodash";
|
import { isNil } from "lodash";
|
||||||
import type { ServiceBroker, ServiceSchema } from "moleculer";
|
import type { ServiceBroker, ServiceSchema } from "moleculer";
|
||||||
import { Service } from "moleculer";
|
import { Service } from "moleculer";
|
||||||
|
import type { Socket } from "socket.io-client";
|
||||||
import io from "socket.io-client";
|
import io from "socket.io-client";
|
||||||
import stringSimilarity from "string-similarity-alg";
|
import stringSimilarity from "string-similarity-alg";
|
||||||
|
|
||||||
|
interface SearchPayload {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface SearchResult {
|
interface SearchResult {
|
||||||
groupedResult: { entityId: number; payload: any };
|
groupedResult: { entityId: number; payload: SearchPayload };
|
||||||
updatedResult: { entityId: number; payload: any };
|
updatedResult: { entityId: number; payload: SearchPayload };
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Issue {
|
||||||
|
issueNumber?: string;
|
||||||
|
issue_number?: string;
|
||||||
|
coverDate?: string;
|
||||||
|
year?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Volume {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Comic {
|
||||||
|
wanted: {
|
||||||
|
volume: Volume;
|
||||||
|
issues?: Issue[];
|
||||||
|
markEntireVolumeWanted?: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Job {
|
||||||
|
comic: Comic;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Hub {
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DirectConnectSettings {
|
||||||
|
client: {
|
||||||
|
hubs: Hub[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SearchInfo {
|
||||||
|
query: {
|
||||||
|
pattern: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SearchesSentData {
|
||||||
|
searchInfo: SearchInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RankedResult extends SearchPayload {
|
||||||
|
similarity: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ComicProcessorService extends Service {
|
export default class ComicProcessorService extends Service {
|
||||||
private kafkaConsumer: any;
|
private kafkaConsumer!: Consumer;
|
||||||
private socketIOInstance: any;
|
|
||||||
private kafkaProducer: any;
|
|
||||||
private prowlarrResultsMap: Map<string, any> = new Map();
|
|
||||||
private airDCPPSearchResults: Map<number, any[]> = new Map();
|
|
||||||
private issuesToSearch: any = [];
|
|
||||||
|
|
||||||
// @ts-ignore: schema parameter is required by Service constructor
|
private socketIOInstance!: Socket;
|
||||||
|
|
||||||
|
private kafkaProducer!: Producer;
|
||||||
|
|
||||||
|
private prowlarrResultsMap: Map<string, unknown> = new Map();
|
||||||
|
|
||||||
|
private airDCPPSearchResults: Map<number, SearchPayload[]> = new Map();
|
||||||
|
|
||||||
|
private issuesToSearch: Issue[] = [];
|
||||||
|
|
||||||
|
// @ts-ignore -- Moleculer requires this constructor signature for service instantiation
|
||||||
constructor(
|
constructor(
|
||||||
public broker: ServiceBroker,
|
broker: ServiceBroker,
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
schema: ServiceSchema<object> = { name: "comicProcessor" },
|
schema: ServiceSchema<object> = { name: "comicProcessor" },
|
||||||
) {
|
) {
|
||||||
super(broker, schema);
|
super(broker);
|
||||||
this.parseServiceSchema({
|
this.parseServiceSchema({
|
||||||
name: "comicProcessor",
|
name: "comicProcessor",
|
||||||
methods: {
|
methods: {
|
||||||
@@ -36,9 +96,9 @@ export default class ComicProcessorService extends Service {
|
|||||||
day: date.getDate(),
|
day: date.getDate(),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
rankSearchResults: async (results: Map<number, any[]>, query: string) => {
|
rankSearchResults: (results: Map<number, SearchPayload[]>, query: string): RankedResult | null => {
|
||||||
// Find the highest-ranked response based on similarity to the search string
|
// Find the highest-ranked response based on similarity to the search string
|
||||||
let highestRankedResult = null;
|
let highestRankedResult: RankedResult | null = null;
|
||||||
let highestSimilarity = -1;
|
let highestSimilarity = -1;
|
||||||
|
|
||||||
results.forEach((resultArray) => {
|
results.forEach((resultArray) => {
|
||||||
@@ -56,24 +116,25 @@ export default class ComicProcessorService extends Service {
|
|||||||
|
|
||||||
return highestRankedResult;
|
return highestRankedResult;
|
||||||
},
|
},
|
||||||
processJob: async (job: any) => {
|
processJob: async (job: Job) => {
|
||||||
try {
|
try {
|
||||||
this.logger.info("Processing job:", JSON.stringify(job, null, 2));
|
this.logger.info("Processing job:", JSON.stringify(job, null, 2));
|
||||||
// Get the hub to search on
|
// Get the hub to search on
|
||||||
const settings: any = await this.broker.call("settings.getSettings", {
|
const settings: DirectConnectSettings = await this.broker.call("settings.getSettings", {
|
||||||
settingsKey: "directConnect",
|
settingsKey: "directConnect",
|
||||||
});
|
});
|
||||||
const hubs = settings.client.hubs.map((hub: any) => hub.value);
|
const hubs = settings.client.hubs.map((hub: Hub) => hub.value);
|
||||||
|
|
||||||
const { comic } = job;
|
const { comic } = job;
|
||||||
const { volume, issues, markEntireVolumeWanted } = comic.wanted;
|
const { volume, issues, markEntireVolumeWanted } = comic.wanted;
|
||||||
|
|
||||||
// If entire volume is marked as wanted, get their details from CV
|
// If entire volume is marked as wanted, get their details from CV
|
||||||
if (markEntireVolumeWanted) {
|
if (markEntireVolumeWanted) {
|
||||||
this.issuesToSearch = await this.broker.call(
|
const fetchedIssues: Issue[] = await this.broker.call(
|
||||||
"comicvine.getIssuesForVolume",
|
"comicvine.getIssuesForVolume",
|
||||||
{ volumeId: volume.id },
|
{ volumeId: volume.id },
|
||||||
);
|
);
|
||||||
|
this.issuesToSearch = fetchedIssues;
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
`The entire volume with id: ${volume.id} was marked as wanted.`,
|
`The entire volume with id: ${volume.id} was marked as wanted.`,
|
||||||
);
|
);
|
||||||
@@ -81,17 +142,18 @@ export default class ComicProcessorService extends Service {
|
|||||||
this.logger.info(`${this.issuesToSearch.length} issues to search`);
|
this.logger.info(`${this.issuesToSearch.length} issues to search`);
|
||||||
} else {
|
} else {
|
||||||
// Or proceed with `issues` from the wanted object.
|
// Or proceed with `issues` from the wanted object.
|
||||||
this.issuesToSearch = issues;
|
this.issuesToSearch = issues || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-disable no-await-in-loop */
|
||||||
for (const issue of this.issuesToSearch) {
|
for (const issue of this.issuesToSearch) {
|
||||||
// Query builder for DC++
|
// Query builder for DC++
|
||||||
// 1. issue number
|
// 1. issue number
|
||||||
const inferredIssueNumber =
|
const issueNumber =
|
||||||
issue.issueNumber || issue.issue_number || "";
|
issue.issueNumber || issue.issue_number || "";
|
||||||
// 2. year
|
// 2. year
|
||||||
const { year } = this.parseStringDate(issue.coverDate);
|
const { year } = this.parseStringDate(issue.coverDate || "");
|
||||||
const inferredYear = year || issue.year || "";
|
const issueYear = year || issue.year || "";
|
||||||
|
|
||||||
// 3. Orchestrate the query
|
// 3. Orchestrate the query
|
||||||
const dcppSearchQuery = {
|
const dcppSearchQuery = {
|
||||||
@@ -109,6 +171,7 @@ export default class ComicProcessorService extends Service {
|
|||||||
"DC++ search query:",
|
"DC++ search query:",
|
||||||
JSON.stringify(dcppSearchQuery, null, 4),
|
JSON.stringify(dcppSearchQuery, null, 4),
|
||||||
);
|
);
|
||||||
|
this.logger.debug(`Issue number: ${issueNumber}, Year: ${issueYear}`);
|
||||||
|
|
||||||
await this.broker.call("socket.search", {
|
await this.broker.call("socket.search", {
|
||||||
query: dcppSearchQuery,
|
query: dcppSearchQuery,
|
||||||
@@ -120,40 +183,18 @@ export default class ComicProcessorService extends Service {
|
|||||||
},
|
},
|
||||||
namespace: "/automated",
|
namespace: "/automated",
|
||||||
});
|
});
|
||||||
|
|
||||||
// const prowlarrResults = await this.broker.call("prowlarr.search", {
|
|
||||||
// prowlarrQuery: {
|
|
||||||
// port: "9696",
|
|
||||||
// apiKey: "c4f42e265fb044dc81f7e88bd41c3367",
|
|
||||||
// offset: 0,
|
|
||||||
// categories: [7030],
|
|
||||||
// query: `${volume.name} ${issue.issueNumber} ${year}`,
|
|
||||||
// host: "localhost",
|
|
||||||
// limit: 100,
|
|
||||||
// type: "search",
|
|
||||||
// indexerIds: [2],
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// this.logger.info(
|
|
||||||
// "Prowlarr search results:",
|
|
||||||
// JSON.stringify(prowlarrResults, null, 4),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// Store prowlarr results in map using unique key
|
|
||||||
// const key = `${volume.name}-${issue.issueNumber}-${year}`;
|
|
||||||
// this.prowlarrResultsMap.set(key, prowlarrResults);
|
|
||||||
}
|
}
|
||||||
|
/* eslint-enable no-await-in-loop */
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error("Error processing job:", error);
|
this.logger.error("Error processing job:", error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
produceResultsToKafka: async (query: string, result: any[]): Promise<void> => {
|
produceResultsToKafka: async (query: string): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
/*
|
/*
|
||||||
Match and rank
|
Match and rank
|
||||||
*/
|
*/
|
||||||
const finalResult = await this.rankSearchResults(
|
const finalResult = this.rankSearchResults(
|
||||||
this.airDCPPSearchResults,
|
this.airDCPPSearchResults,
|
||||||
query,
|
query,
|
||||||
);
|
);
|
||||||
@@ -191,13 +232,13 @@ export default class ComicProcessorService extends Service {
|
|||||||
async started() {
|
async started() {
|
||||||
const kafka = new Kafka({
|
const kafka = new Kafka({
|
||||||
clientId: "comic-processor-service",
|
clientId: "comic-processor-service",
|
||||||
brokers: [process.env.KAFKA_BROKER_URI],
|
brokers: [process.env.KAFKA_BROKER_URI || "localhost:9092"],
|
||||||
logLevel: logLevel.INFO,
|
logLevel: logLevel.INFO,
|
||||||
});
|
});
|
||||||
this.kafkaConsumer = kafka.consumer({ groupId: "comic-processor-group" });
|
this.kafkaConsumer = kafka.consumer({ groupId: "comic-processor-group" });
|
||||||
this.kafkaProducer = kafka.producer();
|
this.kafkaProducer = kafka.producer();
|
||||||
|
|
||||||
this.kafkaConsumer.on("consumer.crash", (event: any) => {
|
this.kafkaConsumer.on("consumer.crash", (event: { payload: Error }) => {
|
||||||
this.logger.error("Consumer crash:", event);
|
this.logger.error("Consumer crash:", event);
|
||||||
});
|
});
|
||||||
this.kafkaConsumer.on("consumer.connect", () => {
|
this.kafkaConsumer.on("consumer.connect", () => {
|
||||||
@@ -219,9 +260,9 @@ export default class ComicProcessorService extends Service {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await this.kafkaConsumer.run({
|
await this.kafkaConsumer.run({
|
||||||
eachMessage: async ({ topic, partition, message }: EachMessagePayload) => {
|
eachMessage: async ({ message }: EachMessagePayload) => {
|
||||||
if (message.value) {
|
if (message.value) {
|
||||||
const job = JSON.parse(message.value.toString());
|
const job = JSON.parse(message.value.toString()) as Job;
|
||||||
await this.processJob(job);
|
await this.processJob(job);
|
||||||
} else {
|
} else {
|
||||||
this.logger.warn("Received message with null value");
|
this.logger.warn("Received message with null value");
|
||||||
@@ -250,14 +291,17 @@ export default class ComicProcessorService extends Service {
|
|||||||
this.airDCPPSearchResults.set(entityId, []);
|
this.airDCPPSearchResults.set(entityId, []);
|
||||||
}
|
}
|
||||||
if (!isNil(payload)) {
|
if (!isNil(payload)) {
|
||||||
this.airDCPPSearchResults.get(entityId).push(payload);
|
const results = this.airDCPPSearchResults.get(entityId);
|
||||||
|
if (results) {
|
||||||
|
results.push(payload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
this.logger.info(
|
||||||
"Updated airDCPPSearchResults:",
|
"Updated airDCPPSearchResults:",
|
||||||
JSON.stringify(Array.from(this.airDCPPSearchResults.entries()), null, 4),
|
JSON.stringify(Array.from(this.airDCPPSearchResults.entries()), null, 4),
|
||||||
);
|
);
|
||||||
console.log(JSON.stringify(payload, null, 4));
|
this.logger.info(JSON.stringify(payload, null, 4));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle searchResultUpdated event
|
// Handle searchResultUpdated event
|
||||||
@@ -268,7 +312,7 @@ export default class ComicProcessorService extends Service {
|
|||||||
const resultsForInstance = this.airDCPPSearchResults.get(entityId);
|
const resultsForInstance = this.airDCPPSearchResults.get(entityId);
|
||||||
|
|
||||||
if (resultsForInstance) {
|
if (resultsForInstance) {
|
||||||
const toReplaceIndex = resultsForInstance.findIndex((element: any) => {
|
const toReplaceIndex = resultsForInstance.findIndex((element: SearchPayload) => {
|
||||||
this.logger.info("search result updated!");
|
this.logger.info("search result updated!");
|
||||||
this.logger.info(JSON.stringify(element, null, 4));
|
this.logger.info(JSON.stringify(element, null, 4));
|
||||||
return element.id === payload.id;
|
return element.id === payload.id;
|
||||||
@@ -284,7 +328,7 @@ export default class ComicProcessorService extends Service {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Handle searchComplete event
|
// Handle searchComplete event
|
||||||
this.socketIOInstance.on("searchesSent", async (data: any) => {
|
this.socketIOInstance.on("searchesSent", async (data: SearchesSentData) => {
|
||||||
this.logger.info(
|
this.logger.info(
|
||||||
`Search complete for query: "${data.searchInfo.query.pattern}"`,
|
`Search complete for query: "${data.searchInfo.query.pattern}"`,
|
||||||
);
|
);
|
||||||
|
|||||||
49
services/graphql.service.ts
Normal file
49
services/graphql.service.ts
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import { makeExecutableSchema } from "@graphql-tools/schema";
|
||||||
|
import type { GraphQLSchema } from "graphql";
|
||||||
|
import { graphql } from "graphql";
|
||||||
|
import type { Context, ServiceBroker } from "moleculer";
|
||||||
|
import { Service } from "moleculer";
|
||||||
|
import { resolvers } from "../models/graphql/resolvers";
|
||||||
|
import { typeDefs } from "../models/graphql/typedef";
|
||||||
|
|
||||||
|
interface GraphQLParams {
|
||||||
|
query: string;
|
||||||
|
variables?: Record<string, unknown>;
|
||||||
|
operationName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GraphQLService extends Service {
|
||||||
|
private graphqlSchema!: GraphQLSchema;
|
||||||
|
|
||||||
|
constructor(broker: ServiceBroker) {
|
||||||
|
super(broker);
|
||||||
|
this.parseServiceSchema({
|
||||||
|
name: "acquisition-graphql",
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
query: {
|
||||||
|
params: {
|
||||||
|
query: "string",
|
||||||
|
variables: { type: "object", optional: true },
|
||||||
|
operationName: { type: "string", optional: true },
|
||||||
|
},
|
||||||
|
async handler(ctx: Context<GraphQLParams>) {
|
||||||
|
const { query, variables, operationName } = ctx.params;
|
||||||
|
return graphql({
|
||||||
|
schema: this.graphqlSchema,
|
||||||
|
source: query,
|
||||||
|
variableValues: variables,
|
||||||
|
operationName,
|
||||||
|
contextValue: { broker: this.broker, ctx },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
started() {
|
||||||
|
this.graphqlSchema = makeExecutableSchema({ typeDefs, resolvers });
|
||||||
|
this.logger.info("Acquisition GraphQL service started");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,32 @@
|
|||||||
|
|
||||||
import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer";
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import type { Context, ServiceBroker } from "moleculer";
|
||||||
|
import { Service } from "moleculer";
|
||||||
|
|
||||||
|
interface ConnectParams {
|
||||||
|
host: string;
|
||||||
|
port: string;
|
||||||
|
apiKey: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProwlarrQuery {
|
||||||
|
host: string;
|
||||||
|
port: string;
|
||||||
|
apiKey: string;
|
||||||
|
query: string;
|
||||||
|
type: string;
|
||||||
|
indexerIds: number[];
|
||||||
|
categories: number[];
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SearchParams {
|
||||||
|
prowlarrQuery: ProwlarrQuery;
|
||||||
|
}
|
||||||
|
|
||||||
export default class ProwlarrService extends Service {
|
export default class ProwlarrService extends Service {
|
||||||
// @ts-ignore
|
// @ts-ignore -- Moleculer requires this constructor signature for service instantiation
|
||||||
constructor(
|
constructor(broker: ServiceBroker) {
|
||||||
public broker: ServiceBroker,
|
|
||||||
schema: ServiceSchema<{}> = { name: "prowlarr" },
|
|
||||||
) {
|
|
||||||
super(broker);
|
super(broker);
|
||||||
this.parseServiceSchema({
|
this.parseServiceSchema({
|
||||||
name: "prowlarr",
|
name: "prowlarr",
|
||||||
@@ -16,13 +35,7 @@ export default class ProwlarrService extends Service {
|
|||||||
actions: {
|
actions: {
|
||||||
connect: {
|
connect: {
|
||||||
rest: "POST /connect",
|
rest: "POST /connect",
|
||||||
handler: async (
|
handler: async (ctx: Context<ConnectParams>) => {
|
||||||
ctx: Context<{
|
|
||||||
host: string;
|
|
||||||
port: string;
|
|
||||||
apiKey: string;
|
|
||||||
}>,
|
|
||||||
) => {
|
|
||||||
const { host, port, apiKey } = ctx.params;
|
const { host, port, apiKey } = ctx.params;
|
||||||
const result = await axios.request({
|
const result = await axios.request({
|
||||||
url: `http://${host}:${port}/api`,
|
url: `http://${host}:${port}/api`,
|
||||||
@@ -31,14 +44,12 @@ export default class ProwlarrService extends Service {
|
|||||||
"X-Api-Key": apiKey,
|
"X-Api-Key": apiKey,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(result.data);
|
this.logger.info(result.data);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getIndexers: {
|
getIndexers: {
|
||||||
rest: "GET /indexers",
|
rest: "GET /indexers",
|
||||||
handler: async (
|
handler: async (ctx: Context<ConnectParams>) => {
|
||||||
ctx: Context<{ host: string; port: string; apiKey: string }>,
|
|
||||||
) => {
|
|
||||||
const { host, port, apiKey } = ctx.params;
|
const { host, port, apiKey } = ctx.params;
|
||||||
const result = await axios.request({
|
const result = await axios.request({
|
||||||
url: `http://${host}:${port}/api/v1/indexer`,
|
url: `http://${host}:${port}/api/v1/indexer`,
|
||||||
@@ -52,21 +63,7 @@ export default class ProwlarrService extends Service {
|
|||||||
},
|
},
|
||||||
search: {
|
search: {
|
||||||
rest: "GET /search",
|
rest: "GET /search",
|
||||||
handler: async (
|
handler: async (ctx: Context<SearchParams>) => {
|
||||||
ctx: Context<{
|
|
||||||
prowlarrQuery: {
|
|
||||||
host: string;
|
|
||||||
port: string;
|
|
||||||
apiKey: string;
|
|
||||||
query: string;
|
|
||||||
type: string;
|
|
||||||
indexerIds: [number];
|
|
||||||
categories: [number];
|
|
||||||
limit: number;
|
|
||||||
offset: number;
|
|
||||||
};
|
|
||||||
}>,
|
|
||||||
) => {
|
|
||||||
const {
|
const {
|
||||||
prowlarrQuery: {
|
prowlarrQuery: {
|
||||||
indexerIds,
|
indexerIds,
|
||||||
@@ -103,7 +100,8 @@ export default class ProwlarrService extends Service {
|
|||||||
},
|
},
|
||||||
ping: {
|
ping: {
|
||||||
rest: "GET /ping",
|
rest: "GET /ping",
|
||||||
handler: async (ctx: Context<{}>) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
handler: async (ctx: Context<Record<string, never>>) => {
|
||||||
const foo = await axios.request({
|
const foo = await axios.request({
|
||||||
url: "http://192.168.1.183:9696/ping",
|
url: "http://192.168.1.183:9696/ping",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -112,7 +110,7 @@ export default class ProwlarrService extends Service {
|
|||||||
"X-Api-Key": "163ef9a683874f65b53c7be87354b38b",
|
"X-Api-Key": "163ef9a683874f65b53c7be87354b38b",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(foo.data);
|
this.logger.info(foo.data);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,12 +1,67 @@
|
|||||||
import { readFileSync, writeFileSync } from "fs";
|
import { readFileSync, writeFileSync } from "fs";
|
||||||
import { qBittorrentClient } from "@robertklep/qbittorrent";
|
import { qBittorrentClient } from "@robertklep/qbittorrent";
|
||||||
import type { Context, ServiceBroker, ServiceSchema } from "moleculer";
|
import type { Context, ServiceBroker } from "moleculer";
|
||||||
import { Errors, Service } from "moleculer";
|
import { Service } from "moleculer";
|
||||||
import parseTorrent from "parse-torrent";
|
import parseTorrent from "parse-torrent";
|
||||||
|
|
||||||
|
interface QBittorrentCredentials {
|
||||||
|
client: {
|
||||||
|
host: {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
hostname: string;
|
||||||
|
port: string;
|
||||||
|
protocol: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConnectParams {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
hostname: string;
|
||||||
|
port: string;
|
||||||
|
protocol: string;
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AddTorrentParams {
|
||||||
|
torrentToDownload: string;
|
||||||
|
comicObjectId: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface InfoHashesParams {
|
||||||
|
infoHashes: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TorrentRealTimeStatsParams {
|
||||||
|
infoHashes: { _id: string; infoHashes: string[] }[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TorrentDetail {
|
||||||
|
torrent: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TorrentDetailsGroup {
|
||||||
|
_id: string;
|
||||||
|
details: TorrentDetail[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface SyncMaindata {
|
||||||
|
torrents: Record<string, Record<string, unknown>>;
|
||||||
|
rid?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
type QBittorrentMeta = any;
|
||||||
|
|
||||||
export default class QBittorrentService extends Service {
|
export default class QBittorrentService extends Service {
|
||||||
// @ts-ignore
|
private meta!: QBittorrentMeta;
|
||||||
constructor(public broker: ServiceBroker, schema: ServiceSchema<{}> = { name: "qbittorrent" }) {
|
|
||||||
|
private rid = 0;
|
||||||
|
|
||||||
|
// @ts-ignore -- Moleculer requires this constructor signature for service instantiation
|
||||||
|
constructor(broker: ServiceBroker) {
|
||||||
super(broker);
|
super(broker);
|
||||||
this.parseServiceSchema({
|
this.parseServiceSchema({
|
||||||
name: "qbittorrent",
|
name: "qbittorrent",
|
||||||
@@ -16,42 +71,35 @@ export default class QBittorrentService extends Service {
|
|||||||
actions: {
|
actions: {
|
||||||
fetchQbittorrentCredentials: {
|
fetchQbittorrentCredentials: {
|
||||||
rest: "GET /fetchQbittorrentCredentials",
|
rest: "GET /fetchQbittorrentCredentials",
|
||||||
handler: async (ctx: Context<{}>) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
return await this.broker.call("settings.getSettings", {
|
handler: async (ctx: Context<Record<string, never>>) => this.broker.call("settings.getSettings", {
|
||||||
settingsKey: "bittorrent",
|
settingsKey: "bittorrent",
|
||||||
});
|
}),
|
||||||
},
|
|
||||||
},
|
},
|
||||||
connect: {
|
connect: {
|
||||||
rest: "POST /connect",
|
rest: "POST /connect",
|
||||||
handler: async (
|
handler: (ctx: Context<ConnectParams>) => {
|
||||||
ctx: Context<{
|
|
||||||
username: string;
|
|
||||||
password: string;
|
|
||||||
hostname: string;
|
|
||||||
port: string;
|
|
||||||
protocol: string;
|
|
||||||
name?: string;
|
|
||||||
}>,
|
|
||||||
) => {
|
|
||||||
const { username, password, hostname, port, protocol } = ctx.params;
|
const { username, password, hostname, port, protocol } = ctx.params;
|
||||||
|
|
||||||
|
// eslint-disable-next-line new-cap
|
||||||
this.meta = new qBittorrentClient(
|
this.meta = new qBittorrentClient(
|
||||||
`${protocol}://${hostname}:${port}`,
|
`${protocol}://${hostname}:${port}`,
|
||||||
`${username}`,
|
`${username}`,
|
||||||
`${password}`,
|
`${password}`,
|
||||||
);
|
);
|
||||||
console.log(this.meta);
|
this.logger.info(this.meta);
|
||||||
if (this.meta) {
|
if (this.meta) {
|
||||||
return { success: true, message: "Logged in successfully" };
|
return { success: true, message: "Logged in successfully" };
|
||||||
}
|
}
|
||||||
|
return { success: false, message: "Failed to connect" };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
loginWithStoredCredentials: {
|
loginWithStoredCredentials: {
|
||||||
rest: "POST /loginWithStoredCredentials",
|
rest: "POST /loginWithStoredCredentials",
|
||||||
handler: async (ctx: Context<{}>) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
handler: async (ctx: Context<Record<string, never>>) => {
|
||||||
try {
|
try {
|
||||||
const result: any = await this.broker.call(
|
const result: QBittorrentCredentials | undefined = await this.broker.call(
|
||||||
"qbittorrent.fetchQbittorrentCredentials",
|
"qbittorrent.fetchQbittorrentCredentials",
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
@@ -69,10 +117,14 @@ export default class QBittorrentService extends Service {
|
|||||||
port,
|
port,
|
||||||
protocol,
|
protocol,
|
||||||
});
|
});
|
||||||
console.log("qbittorrent connection details:");
|
this.logger.info("qbittorrent connection details:");
|
||||||
console.log(JSON.stringify(connection, null, 4));
|
this.logger.info(JSON.stringify(connection, null, 4));
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
return {
|
||||||
|
error: null,
|
||||||
|
message: "Qbittorrent credentials not found.",
|
||||||
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return {
|
return {
|
||||||
error: err,
|
error: err,
|
||||||
@@ -85,7 +137,8 @@ export default class QBittorrentService extends Service {
|
|||||||
|
|
||||||
getClientInfo: {
|
getClientInfo: {
|
||||||
rest: "GET /getClientInfo",
|
rest: "GET /getClientInfo",
|
||||||
handler: async (ctx: Context<{}>) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
handler: async (ctx: Context<Record<string, never>>) => {
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
return {
|
return {
|
||||||
buildInfo: await this.meta.app.buildInfo(),
|
buildInfo: await this.meta.app.buildInfo(),
|
||||||
@@ -96,22 +149,17 @@ export default class QBittorrentService extends Service {
|
|||||||
},
|
},
|
||||||
addTorrent: {
|
addTorrent: {
|
||||||
rest: "POST /addTorrent",
|
rest: "POST /addTorrent",
|
||||||
handler: async (
|
handler: async (ctx: Context<AddTorrentParams>) => {
|
||||||
ctx: Context<{
|
|
||||||
torrentToDownload: any;
|
|
||||||
comicObjectId: string;
|
|
||||||
}>,
|
|
||||||
) => {
|
|
||||||
try {
|
try {
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
const { torrentToDownload, comicObjectId } = ctx.params;
|
const { torrentToDownload, comicObjectId } = ctx.params;
|
||||||
console.log(torrentToDownload);
|
this.logger.info(torrentToDownload);
|
||||||
const response = await fetch(torrentToDownload, {
|
const response = await fetch(torrentToDownload, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
// Read the buffer to a file
|
// Read the buffer to a file
|
||||||
const buffer = await response.arrayBuffer();
|
const buffer = await response.arrayBuffer();
|
||||||
writeFileSync(`mithrandir.torrent`, Buffer.from(buffer));
|
writeFileSync(`mithrandir.torrent`, new Uint8Array(buffer));
|
||||||
// Add the torrent to qbittorrent's queue, paused.
|
// Add the torrent to qbittorrent's queue, paused.
|
||||||
const result = await this.meta.torrents.add({
|
const result = await this.meta.torrents.add({
|
||||||
torrents: {
|
torrents: {
|
||||||
@@ -134,28 +182,33 @@ export default class QBittorrentService extends Service {
|
|||||||
result,
|
result,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
this.logger.error(err);
|
||||||
|
return {
|
||||||
|
error: err,
|
||||||
|
message: "Failed to add torrent",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getTorrents: {
|
getTorrents: {
|
||||||
rest: "POST /getTorrents",
|
rest: "POST /getTorrents",
|
||||||
handler: async (ctx: Context<{}>) => {
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
handler: async (ctx: Context<Record<string, never>>) => {
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
return await this.meta.torrents.info();
|
return this.meta.torrents.info();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getTorrentProperties: {
|
getTorrentProperties: {
|
||||||
rest: "POST /getTorrentProperties",
|
rest: "POST /getTorrentProperties",
|
||||||
handler: async (ctx: Context<{ infoHashes: string[] }>) => {
|
handler: async (ctx: Context<InfoHashesParams>) => {
|
||||||
try {
|
try {
|
||||||
const { infoHashes } = ctx.params;
|
const { infoHashes } = ctx.params;
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
return await this.meta.torrents.info({
|
return this.meta.torrents.info({
|
||||||
hashes: infoHashes,
|
hashes: infoHashes,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("An error occurred:", err);
|
this.logger.error("An error occurred:", err);
|
||||||
// Consider handling the error more gracefully here, possibly returning an error response
|
// Consider handling the error more gracefully here, possibly returning an error response
|
||||||
throw err; // or return a specific error object/message
|
throw err; // or return a specific error object/message
|
||||||
}
|
}
|
||||||
@@ -163,23 +216,21 @@ export default class QBittorrentService extends Service {
|
|||||||
},
|
},
|
||||||
getTorrentRealTimeStats: {
|
getTorrentRealTimeStats: {
|
||||||
rest: "POST /getTorrentRealTimeStats",
|
rest: "POST /getTorrentRealTimeStats",
|
||||||
handler: async (
|
handler: async (ctx: Context<TorrentRealTimeStatsParams>) => {
|
||||||
ctx: Context<{ infoHashes: { _id: string; infoHashes: string[] }[] }>,
|
|
||||||
) => {
|
|
||||||
const { infoHashes } = ctx.params;
|
const { infoHashes } = ctx.params;
|
||||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Increment rid for each call
|
// Increment rid for each call
|
||||||
this.rid = typeof this.rid === "number" ? this.rid + 1 : 0;
|
this.rid = typeof this.rid === "number" ? this.rid + 1 : 0;
|
||||||
const data = await this.meta.sync.maindata(this.rid);
|
const data: SyncMaindata = await this.meta.sync.maindata(this.rid);
|
||||||
const torrentDetails: any = [];
|
const torrentDetails: TorrentDetailsGroup[] = [];
|
||||||
|
|
||||||
infoHashes.forEach(({ _id, infoHashes }) => {
|
infoHashes.forEach(({ _id, infoHashes: hashes }) => {
|
||||||
// Initialize an object to hold details for this _id
|
// Initialize an object to hold details for this _id
|
||||||
const details: any = [];
|
const details: TorrentDetail[] = [];
|
||||||
|
|
||||||
infoHashes.forEach((hash) => {
|
hashes.forEach((hash) => {
|
||||||
// Assuming 'data.torrents[hash]' retrieves the details for the hash
|
// Assuming 'data.torrents[hash]' retrieves the details for the hash
|
||||||
const torrent = data.torrents[hash];
|
const torrent = data.torrents[hash];
|
||||||
if (torrent) {
|
if (torrent) {
|
||||||
@@ -201,9 +252,9 @@ export default class QBittorrentService extends Service {
|
|||||||
// Assuming `data.rid` contains the latest rid from the server
|
// Assuming `data.rid` contains the latest rid from the server
|
||||||
if (data.rid !== undefined) {
|
if (data.rid !== undefined) {
|
||||||
this.rid = data.rid;
|
this.rid = data.rid;
|
||||||
console.log(`rid is ${this.rid}`);
|
this.logger.info(`rid is ${this.rid}`);
|
||||||
}
|
}
|
||||||
console.log(JSON.stringify(torrentDetails, null, 4));
|
this.logger.info(JSON.stringify(torrentDetails, null, 4));
|
||||||
return torrentDetails;
|
return torrentDetails;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
@@ -213,24 +264,23 @@ export default class QBittorrentService extends Service {
|
|||||||
},
|
},
|
||||||
determineDownloadApps: {
|
determineDownloadApps: {
|
||||||
rest: "",
|
rest: "",
|
||||||
handler: async () => {
|
// 1. Parse the incoming search query
|
||||||
// 1. Parse the incoming search query
|
// to make sure that it is well-formed
|
||||||
// to make sure that it is well-formed
|
// At the very least, it should have name, year, number
|
||||||
// At the very least, it should have name, year, number
|
// 2. Choose between download mediums based on user-preference?
|
||||||
// 2. Choose between download mediums based on user-preference?
|
// possible choices are: DC++, Torrent
|
||||||
// possible choices are: DC++, Torrent
|
// 3. Perform the search on those media with the aforementioned search query
|
||||||
// 3. Perform the search on those media with the aforementioned search query
|
// 4. Choose a subset of relevant search results,
|
||||||
// 4. Choose a subset of relevant search results,
|
// and score them
|
||||||
// and score them
|
// 5. Download the highest-scoring, relevant result
|
||||||
// 5. Download the highest-scoring, relevant result
|
handler: () => undefined,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {},
|
methods: {},
|
||||||
async started() {
|
started() {
|
||||||
console.log(`Initializing rid...`);
|
this.logger.info(`Initializing rid...`);
|
||||||
this.rid = 0;
|
this.rid = 0;
|
||||||
console.log(`rid is ${this.rid}`);
|
this.logger.info(`rid is ${this.rid}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
14
tsconfig.eslint.json
Normal file
14
tsconfig.eslint.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"noEmit": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./**/*.ts",
|
||||||
|
"./**/*.js"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"dist"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user