➕ Added an AutoDownloadService
This commit is contained in:
68
services/autodownload.service.ts
Normal file
68
services/autodownload.service.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
import { Context, Service, ServiceBroker, ServiceSchema, Errors } from "moleculer";
|
||||
import axios from "axios";
|
||||
|
||||
export default class AutoDownloadService extends Service {
|
||||
// @ts-ignore
|
||||
public constructor(
|
||||
public broker: ServiceBroker,
|
||||
schema: ServiceSchema<{}> = { name: "autodownload" },
|
||||
) {
|
||||
super(broker);
|
||||
this.parseServiceSchema({
|
||||
name: "autodownload",
|
||||
mixins: [],
|
||||
hooks: {},
|
||||
actions: {
|
||||
searchWantedComics: {
|
||||
rest: "POST /searchWantedComics",
|
||||
handler: async (ctx: Context<{}>) => {
|
||||
// 1.iterate through the wanted comic objects, and:
|
||||
// 1a. Orchestrate all issues from ComicVine if the entire volume is wanted
|
||||
// 1b. Just the issues in "wanted.issues[]"
|
||||
const wantedComics: any = await this.broker.call(
|
||||
"library.getComicsMarkedAsWanted",
|
||||
{},
|
||||
);
|
||||
|
||||
// Iterate through the list of wanted comics
|
||||
for (const comic of wantedComics) {
|
||||
let issuesToSearch: any = [];
|
||||
|
||||
if (comic.wanted.markEntireVolumeAsWanted) {
|
||||
// 1a. Fetch all issues from ComicVine if the entire volume is wanted
|
||||
issuesToSearch = await this.broker.call(
|
||||
"comicvine.getIssuesForVolume",
|
||||
{
|
||||
volumeId: comic.wanted.volume.id,
|
||||
},
|
||||
);
|
||||
} else if (comic.wanted.issues && comic.wanted.issues.length > 0) {
|
||||
// 1b. Just the issues in "wanted.issues[]"
|
||||
issuesToSearch = comic.wanted.issues;
|
||||
}
|
||||
for (const issue of issuesToSearch) {
|
||||
// construct the search queries
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
determineDownloadChannel: {
|
||||
rest: "POST /determineDownloadChannel",
|
||||
handler: async (ctx: Context<{}>) => {
|
||||
// 1. Parse the incoming search query
|
||||
// to make sure that it is well-formed
|
||||
// At the very least, it should have name, year, number
|
||||
// 2. Choose between download mediums based on user-preference?
|
||||
// possible choices are: DC++, Torrent
|
||||
// 3. Perform the search on those media with the aforementioned search query
|
||||
// 4. Choose a subset of relevant search results,
|
||||
// and score them
|
||||
// 5. Download the highest-scoring, relevant result
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ export default class ProwlarrService extends Service {
|
||||
offset: number;
|
||||
}>,
|
||||
) => {
|
||||
console.log(JSON.stringify(ctx.params, null, 2));
|
||||
const {
|
||||
indexerIds,
|
||||
categories,
|
||||
@@ -76,15 +77,16 @@ export default class ProwlarrService extends Service {
|
||||
limit,
|
||||
offset,
|
||||
} = ctx.params;
|
||||
|
||||
const indexer = indexerIds[0] ? indexerIds.length === 1 : indexerIds;
|
||||
const category = categories[0] ? categories.length === 1 : categories;
|
||||
const result = await axios({
|
||||
url: `http://${host}:${port}/api/v1/search`,
|
||||
method: "GET",
|
||||
params: {
|
||||
query,
|
||||
type,
|
||||
indexerIds,
|
||||
categories,
|
||||
indexer,
|
||||
category,
|
||||
limit,
|
||||
offset,
|
||||
},
|
||||
|
||||
@@ -86,7 +86,6 @@ export default class QBittorrentService extends Service {
|
||||
getClientInfo: {
|
||||
rest: "GET /getClientInfo",
|
||||
handler: async (ctx: Context<{}>) => {
|
||||
console.log(this.meta.app);
|
||||
await this.broker.call("qbittorrent.loginWithStoredCredentials", {});
|
||||
return {
|
||||
buildInfo: await this.meta.app.buildInfo(),
|
||||
@@ -212,6 +211,20 @@ export default class QBittorrentService extends Service {
|
||||
}
|
||||
},
|
||||
},
|
||||
determineDownloadApps: {
|
||||
rest: "",
|
||||
handler: async () => {
|
||||
// 1. Parse the incoming search query
|
||||
// to make sure that it is well-formed
|
||||
// At the very least, it should have name, year, number
|
||||
// 2. Choose between download mediums based on user-preference?
|
||||
// possible choices are: DC++, Torrent
|
||||
// 3. Perform the search on those media with the aforementioned search query
|
||||
// 4. Choose a subset of relevant search results,
|
||||
// and score them
|
||||
// 5. Download the highest-scoring, relevant result
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {},
|
||||
async started() {
|
||||
|
||||
Reference in New Issue
Block a user