🏗️ WIP for automatic downloads endpoint
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer";
|
||||
import axios from "axios";
|
||||
import io from "socket.io-client";
|
||||
|
||||
export default class AutoDownloadService extends Service {
|
||||
// @ts-ignore
|
||||
@@ -25,12 +25,17 @@ export default class AutoDownloadService extends Service {
|
||||
{},
|
||||
);
|
||||
|
||||
// 2a. Get the list of hubs from AirDC++
|
||||
const data: any = await this.broker.call("settings.getSettings", {
|
||||
settingsKey: "directConnect",
|
||||
});
|
||||
const { hubs } = data?.client;
|
||||
console.log("HUBZZZZZ", hubs);
|
||||
// Iterate through the list of wanted comics
|
||||
for (const comic of wantedComics) {
|
||||
wantedComics.forEach(async (comic: any) => {
|
||||
let issuesToSearch: any = [];
|
||||
|
||||
if (comic.wanted.markEntireVolumeAsWanted) {
|
||||
// 1a. Fetch all issues from ComicVine if the entire volume is wanted
|
||||
// Fetch all issues from ComicVine if the entire volume is wanted
|
||||
issuesToSearch = await this.broker.call(
|
||||
"comicvine.getIssuesForVolume",
|
||||
{
|
||||
@@ -39,12 +44,68 @@ export default class AutoDownloadService extends Service {
|
||||
);
|
||||
} else if (comic.wanted.issues && comic.wanted.issues.length > 0) {
|
||||
// 1b. Just the issues in "wanted.issues[]"
|
||||
issuesToSearch = comic.wanted.issues;
|
||||
issuesToSearch = {
|
||||
issues: comic.wanted.issues,
|
||||
volumeName: comic.wanted.volume?.name,
|
||||
};
|
||||
}
|
||||
for (const issue of issuesToSearch) {
|
||||
// construct the search queries
|
||||
for (const issue of issuesToSearch.issues) {
|
||||
// 2. construct the search queries
|
||||
|
||||
// 2b. for AirDC++ search, with the volume name, issueId and cover_date
|
||||
const { year } = this.parseStringDate(issue.coverDate);
|
||||
|
||||
const dcppSearchQuery = {
|
||||
query: {
|
||||
pattern: `${issuesToSearch.volumeName.replace(/#/g, "")} ${
|
||||
issue.issueNumber
|
||||
} ${year}`,
|
||||
extensions: ["cbz", "cbr", "cb7"],
|
||||
},
|
||||
hub_urls: hubs.map((hub: any) => hub.value),
|
||||
priority: 5,
|
||||
};
|
||||
// Perform the AirDC++ search
|
||||
const dcppResults = await this.broker.call("socket.search", {
|
||||
query: dcppSearchQuery,
|
||||
config: {
|
||||
hostname: "localhost:5600",
|
||||
protocol: "http",
|
||||
username: "user",
|
||||
password: "pass",
|
||||
},
|
||||
namespace: "/automated",
|
||||
});
|
||||
this.socketIOInstance.on("searchResultUpdated", (data: any) => {
|
||||
console.log("Hyaar we go", data);
|
||||
});
|
||||
// const dcppResults = await ctx.call("airdcpp.search", {
|
||||
// dcppSearchQuery,
|
||||
// });
|
||||
|
||||
// 2b. for Prowlarr search, with the volume name, issueId and cover_date
|
||||
const prowlarrQuery = {
|
||||
port: "9696",
|
||||
apiKey: "c4f42e265fb044dc81f7e88bd41c3367",
|
||||
offset: 0,
|
||||
categories: [7030],
|
||||
query: `${issuesToSearch.volumeName} ${issue.issueNumber} ${year}`,
|
||||
host: "localhost",
|
||||
limit: 100,
|
||||
type: "search",
|
||||
indexerIds: [2],
|
||||
};
|
||||
|
||||
// Perform the Prowlarr search
|
||||
const prowlarrResults = await this.broker.call("prowlarr.search", {
|
||||
prowlarrQuery,
|
||||
});
|
||||
|
||||
// Process results here or after the loop
|
||||
console.log("DCPP Results: ", dcppResults);
|
||||
console.log("Prowlarr Results: ", prowlarrResults);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
determineDownloadChannel: {
|
||||
@@ -62,7 +123,30 @@ export default class AutoDownloadService extends Service {
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {},
|
||||
methods: {
|
||||
parseStringDate: (dateString: string) => {
|
||||
const date = new Date(dateString);
|
||||
|
||||
// Get the year, month, and day
|
||||
const year = date.getFullYear(); // 2022
|
||||
const month = date.getMonth() + 1; // December is 11 in Date object (0-indexed), so add 1 to make it human-readable
|
||||
const day = date.getDate(); // 1
|
||||
return { year, month, day };
|
||||
},
|
||||
},
|
||||
async started() {
|
||||
this.socketIOInstance = io("ws://localhost:3001/automated", {
|
||||
transports: ["websocket"],
|
||||
withCredentials: true,
|
||||
});
|
||||
this.socketIOInstance.on("connect", (data: any) => {
|
||||
console.log("connected", data);
|
||||
});
|
||||
|
||||
this.socketIOInstance.on("searchResultAdded", (data: any) => {
|
||||
console.log("Received searchResultUpdated event:", data);
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,28 +54,31 @@ export default class ProwlarrService extends Service {
|
||||
rest: "GET /search",
|
||||
handler: async (
|
||||
ctx: Context<{
|
||||
host: string;
|
||||
port: string;
|
||||
apiKey: string;
|
||||
query: string;
|
||||
type: string;
|
||||
indexerIds: [number];
|
||||
categories: [number];
|
||||
limit: number;
|
||||
offset: number;
|
||||
prowlarrQuery: {
|
||||
host: string;
|
||||
port: string;
|
||||
apiKey: string;
|
||||
query: string;
|
||||
type: string;
|
||||
indexerIds: [number];
|
||||
categories: [number];
|
||||
limit: number;
|
||||
offset: number;
|
||||
};
|
||||
}>,
|
||||
) => {
|
||||
console.log(JSON.stringify(ctx.params, null, 2));
|
||||
const {
|
||||
indexerIds,
|
||||
categories,
|
||||
host,
|
||||
port,
|
||||
apiKey,
|
||||
query,
|
||||
type,
|
||||
limit,
|
||||
offset,
|
||||
prowlarrQuery: {
|
||||
indexerIds,
|
||||
categories,
|
||||
host,
|
||||
port,
|
||||
apiKey,
|
||||
query,
|
||||
type,
|
||||
limit,
|
||||
offset,
|
||||
},
|
||||
} = ctx.params;
|
||||
const indexer = indexerIds[0] ? indexerIds.length === 1 : indexerIds;
|
||||
const category = categories[0] ? categories.length === 1 : categories;
|
||||
|
||||
Reference in New Issue
Block a user