7 Commits

Author SHA1 Message Date
0f47750bc2 Merge branch 'master' into automated-download-loop 2024-10-23 14:27:44 -04:00
d7e865f84f 🔧 Prettification 2024-10-23 14:26:24 -04:00
baa5a99855 🔧 Removed indirection for getBundles 2024-10-23 13:42:05 -04:00
68c2dacff4 🔧 getBundles endpoint WIP 2024-10-21 18:04:16 -04:00
55e0ce6d36 🖌️ Formatting changes 2024-10-18 13:19:57 -04:00
4ffad69c44 🔧 Todo to move the method from UI 2024-10-16 18:50:14 -04:00
f9438f2129 🔧 Fixing broken AirDCPP search 2024-09-26 21:33:02 -04:00
4 changed files with 1067 additions and 1318 deletions

View File

@@ -60,7 +60,7 @@ services:
networks:
- kafka-net
ports:
- "127.0.0.1:27017:27017"
- "27017:27017"
volumes:
- "mongodb_data:/bitnami/mongodb"
@@ -72,7 +72,7 @@ services:
networks:
- kafka-net
ports:
- "127.0.0.1:6379:6379"
- "6379:6379"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.16.2
@@ -88,7 +88,7 @@ services:
soft: -1
hard: -1
ports:
- "127.0.0.1:9200:9200"
- "9200:9200"
networks:
- kafka-net

2151
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -57,6 +57,7 @@ const through2 = require("through2");
import klaw from "klaw";
import path from "path";
import { COMICS_DIRECTORY, USERDATA_DIRECTORY } from "../constants/directories";
import AirDCPPSocket from "../shared/airdcpp.socket";
export default class LibraryService extends Service {
public constructor(
@@ -174,7 +175,7 @@ export default class LibraryService extends Service {
// Convert klaw to use a promise-based approach for better flow control
const files = await this.getComicFiles(
process.env.COMICS_DIRECTORY
COMICS_DIRECTORY
);
for (const file of files) {
console.info(
@@ -187,6 +188,7 @@ export default class LibraryService extends Service {
path.extname(file.path)
),
});
if (!comicExists) {
// Send the extraction job to the queue
await this.broker.call("jobqueue.enqueue", {
@@ -330,51 +332,21 @@ export default class LibraryService extends Service {
},
getComicsMarkedAsWanted: {
rest: "GET /getComicsMarkedAsWanted",
params: {
page: { type: "number", default: 1 },
limit: { type: "number", default: 100 },
},
handler: async (
ctx: Context<{ page: number; limit: number }>
) => {
const { page, limit } = ctx.params;
this.logger.info(
`Requesting page ${page} with limit ${limit}`
);
handler: async (ctx: Context<{}>) => {
try {
const options = {
page,
limit,
lean: true,
};
// Query to find comics where 'markEntireVolumeAsWanted' is true or 'issues' array is not empty
const wantedComics = await Comic.find({
wanted: { $exists: true },
$or: [
{ "wanted.markEntireVolumeWanted": true },
{ "wanted.issues": { $not: { $size: 0 } } },
],
});
const result = await Comic.paginate(
{
wanted: { $exists: true },
$or: [
{
"wanted.markEntireVolumeWanted":
true,
},
{
"wanted.issues": {
$not: { $size: 0 },
},
},
],
},
options
);
// Log the raw result from the database
this.logger.info(
"Paginate result:",
JSON.stringify(result, null, 2)
);
return result.docs; // Return just the docs array
console.log(wantedComics); // Output the found comics
return wantedComics;
} catch (error) {
this.logger.error("Error finding comics:", error);
console.error("Error finding comics:", error);
throw error;
}
},
@@ -556,7 +528,9 @@ export default class LibraryService extends Service {
params: { id: "string" },
async handler(ctx: Context<{ id: string }>) {
console.log(ctx.params.id);
return await Comic.findById(ctx.params.id);
return await Comic.findById(
new ObjectId(ctx.params.id)
);
},
},
getComicBooksByIds: {
@@ -775,6 +749,46 @@ export default class LibraryService extends Service {
},
},
// This method belongs in library service,
// because bundles can only exist for comics _in the library_
// (wanted or imported)
getBundles: {
rest: "POST /getBundles",
params: {},
handler: async (
ctx: Context<{
comicObjectId: string;
config: any;
}>
) => {
try {
// 1. Get the comic object Id
const { config } = ctx.params;
const comicObject = await Comic.findById(
new ObjectId(ctx.params.comicObjectId)
);
// 2. Init AirDC++
// 3. Get the bundles for the comic object
const ADCPPSocket = new AirDCPPSocket(config);
if (comicObject) {
// make the call to get the bundles from AirDC++ using the bundleId
return comicObject.acquisition.directconnect.downloads.map(
async (bundle) =>
await ADCPPSocket.get(
`queue/bundles/${bundle.id}`
)
);
}
return false;
} catch (error) {
throw new Errors.MoleculerError(
"Couldn't fetch bundles from AirDC++",
500
);
}
},
},
flushDB: {
rest: "POST /flushDB",
params: {},

View File

@@ -61,12 +61,8 @@ export default class SocketService extends Service {
if (active > 0 || paused > 0 || waiting > 0) {
// 3. Get job counts
const completedJobCount = await pubClient.get(
"completedJobCount"
);
const failedJobCount = await pubClient.get(
"failedJobCount"
);
const completedJobCount = await pubClient.get("completedJobCount");
const failedJobCount = await pubClient.get("failedJobCount");
// 4. Send the counts to the active socket.io session
await this.broker.call("socket.broadcast", {
@@ -83,14 +79,9 @@ export default class SocketService extends Service {
}
}
} catch (err) {
throw new MoleculerError(
err,
500,
"SESSION_ID_NOT_FOUND",
{
data: sessionId,
}
);
throw new MoleculerError(err, 500, "SESSION_ID_NOT_FOUND", {
data: sessionId,
});
}
},
@@ -101,11 +92,7 @@ export default class SocketService extends Service {
}>
) => {
const { queueAction } = ctx.params;
await this.broker.call(
"jobqueue.toggle",
{ action: queueAction },
{}
);
await this.broker.call("jobqueue.toggle", { action: queueAction }, {});
},
importSingleIssue: async (ctx: Context<{}>) => {
console.info("AirDC++ finished a download -> ");
@@ -116,13 +103,11 @@ export default class SocketService extends Service {
// {}
// );
},
// AirDCPP Socket actions
search: {
params: {
query: "object",
config: "object",
namespace: "string",
},
async handler(ctx) {
const { query, config, namespace } = ctx.params;
@@ -130,10 +115,7 @@ export default class SocketService extends Service {
const ADCPPSocket = new AirDCPPSocket(config);
try {
await ADCPPSocket.connect();
const instance = await ADCPPSocket.post(
"search",
query
);
const instance = await ADCPPSocket.post("search", query);
// Send the instance to the client
await namespacedInstance.emit("searchInitiated", {
@@ -144,14 +126,9 @@ export default class SocketService extends Service {
await ADCPPSocket.addListener(
`search`,
`search_result_added`,
(data) => {
namespacedInstance.emit(
"searchResultAdded",
{
groupedResult: data,
instanceId: instance.id,
}
);
(groupedResult) => {
console.log(JSON.stringify(groupedResult, null, 4));
namespacedInstance.emit("searchResultAdded", groupedResult);
},
instance.id
);
@@ -159,18 +136,8 @@ export default class SocketService extends Service {
await ADCPPSocket.addListener(
`search`,
`search_result_updated`,
(data) => {
console.log({
updatedResult: data,
instanceId: instance.id,
});
namespacedInstance.emit(
"searchResultUpdated",
{
updatedResult: data,
instanceId: instance.id,
}
);
(updatedResult) => {
namespacedInstance.emit("searchResultUpdated", updatedResult);
},
instance.id
);
@@ -180,54 +147,32 @@ export default class SocketService extends Service {
`search_hub_searches_sent`,
async (searchInfo) => {
await this.sleep(5000);
const currentInstance =
await ADCPPSocket.get(
`search/${instance.id}`
);
console.log(
JSON.stringify(currentInstance, null, 4)
const currentInstance = await ADCPPSocket.get(
`search/${instance.id}`
);
// Send the instance to the client
await namespacedInstance.emit(
"searchesSent",
{
searchInfo,
}
);
await namespacedInstance.emit("searchesSent", {
searchInfo,
});
if (currentInstance.result_count === 0) {
console.log("No more search results.");
namespacedInstance.emit(
"searchComplete",
{
message:
"No more search results.",
currentInstance,
}
);
namespacedInstance.emit("searchComplete", {
message: "No more search results.",
});
}
},
instance.id
);
// Perform the actual search
await ADCPPSocket.post(
`search/${instance.id}/hub_search`,
query
);
await ADCPPSocket.post(`search/${instance.id}/hub_search`, query);
} catch (error) {
await namespacedInstance.emit(
"searchError",
error.message
);
throw new MoleculerError(
"Search failed",
500,
"SEARCH_FAILED",
{ error }
);
await namespacedInstance.emit("searchError", error.message);
throw new MoleculerError("Search failed", 500, "SEARCH_FAILED", {
error,
});
} finally {
await ADCPPSocket.disconnect();
// await ADCPPSocket.disconnect();
}
},
},
@@ -276,10 +221,7 @@ export default class SocketService extends Service {
"Download and metadata update successful",
bundleDBImportResult
);
this.broker.emit(
"downloadCompleted",
bundleDBImportResult
);
this.broker.emit("downloadCompleted", bundleDBImportResult);
return bundleDBImportResult;
} else {
throw new Error(
@@ -288,12 +230,9 @@ export default class SocketService extends Service {
}
} catch (error) {
this.broker.emit("downloadError", error.message);
throw new MoleculerError(
"Download failed",
500,
"DOWNLOAD_FAILED",
{ error }
);
throw new MoleculerError("Download failed", 500, "DOWNLOAD_FAILED", {
error,
});
} finally {
// await ADCPPSocket.disconnect();
}
@@ -313,10 +252,7 @@ export default class SocketService extends Service {
"queue",
"queue_bundle_tick",
(tickData) => {
console.log(
"Received tick data: ",
tickData
);
console.log("Received tick data: ", tickData);
this.io.emit("bundleTickUpdate", tickData);
},
null