🏗️ Automatic downloads endpoint support
This commit is contained in:
@@ -67,6 +67,8 @@ const wantedSchema = mongoose.Schema(
|
||||
id: Number,
|
||||
url: String,
|
||||
image: { type: Array, default: [] },
|
||||
coverDate: String,
|
||||
issueNumber: String,
|
||||
},
|
||||
],
|
||||
default: null,
|
||||
|
||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -13921,9 +13921,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/r2-shared-js": {
|
||||
"version": "1.0.72",
|
||||
"resolved": "https://registry.npmjs.org/r2-shared-js/-/r2-shared-js-1.0.72.tgz",
|
||||
"integrity": "sha512-aP0M8uqnyLtJ5TZkNx+q4fgVZbjmuhFQPL/N5Qd6W6ybCozZgiQc+FYZOqu1vdsNaYw0FaMzYlp0/DH6m3TdYA==",
|
||||
"version": "1.0.74",
|
||||
"resolved": "https://registry.npmjs.org/r2-shared-js/-/r2-shared-js-1.0.74.tgz",
|
||||
"integrity": "sha512-aNk8kkb4W9nMKKXrzTC76AXOVSLUx78V73hk4DJ7g81M3gfX2FZQD63Tohgt7VSAbVBdKy/7wo6KOBNFN8Kvow==",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@xmldom/xmldom": "^0.8.10",
|
||||
|
||||
@@ -58,6 +58,7 @@ export default class AirDCPPService extends Service {
|
||||
},
|
||||
getHubs: {
|
||||
rest: "POST /getHubs",
|
||||
timeout: 70000,
|
||||
handler: async (
|
||||
ctx: Context<{
|
||||
host: {
|
||||
@@ -69,7 +70,6 @@ export default class AirDCPPService extends Service {
|
||||
};
|
||||
}>
|
||||
) => {
|
||||
console.log(ctx.params);
|
||||
const {
|
||||
host: {
|
||||
hostname,
|
||||
@@ -93,8 +93,64 @@ export default class AirDCPPService extends Service {
|
||||
}
|
||||
},
|
||||
},
|
||||
search: {
|
||||
rest: "POST /search",
|
||||
timeout: 20000,
|
||||
handler: async (
|
||||
ctx: Context<{
|
||||
host: {
|
||||
hostname;
|
||||
port;
|
||||
protocol;
|
||||
username;
|
||||
password;
|
||||
};
|
||||
dcppSearchQuery;
|
||||
}>
|
||||
) => {
|
||||
try {
|
||||
const {
|
||||
host: {
|
||||
hostname,
|
||||
port,
|
||||
protocol,
|
||||
username,
|
||||
password,
|
||||
},
|
||||
dcppSearchQuery,
|
||||
} = ctx.params;
|
||||
const airDCPPSocket = new AirDCPPSocket({
|
||||
protocol,
|
||||
hostname: `${hostname}:${port}`,
|
||||
username,
|
||||
password,
|
||||
});
|
||||
await airDCPPSocket.connect();
|
||||
const searchInstance = await airDCPPSocket.post(
|
||||
`search`
|
||||
);
|
||||
|
||||
// Post the search
|
||||
const searchInfo = await airDCPPSocket.post(
|
||||
`search/${searchInstance.id}/hub_search`,
|
||||
dcppSearchQuery
|
||||
);
|
||||
await this.sleep(10000);
|
||||
const results = await airDCPPSocket.get(
|
||||
`search/${searchInstance.id}/results/0/5`
|
||||
);
|
||||
return results;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
sleep: (ms: number) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
},
|
||||
},
|
||||
methods: {},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,12 @@ export default class SocketService extends Service {
|
||||
port: process.env.PORT || 3001,
|
||||
io: {
|
||||
namespaces: {
|
||||
"/": {
|
||||
"/automated": {
|
||||
events: {
|
||||
call: {
|
||||
whitelist: ["socket.*"],
|
||||
whitelist: [
|
||||
"socket.*", // Allow 'search' in the automated namespace
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -123,8 +125,12 @@ export default class SocketService extends Service {
|
||||
config: "object",
|
||||
},
|
||||
async handler(ctx) {
|
||||
const { query, config } = ctx.params;
|
||||
console.log("a, a kanha kanha...");
|
||||
|
||||
const { query, config, namespace } = ctx.params;
|
||||
const namespacedInstance = this.io.of(namespace || "/");
|
||||
const ADCPPSocket = new AirDCPPSocket(config);
|
||||
console.log("asdas", ADCPPSocket);
|
||||
try {
|
||||
await ADCPPSocket.connect();
|
||||
const instance = await ADCPPSocket.post(
|
||||
@@ -133,7 +139,7 @@ export default class SocketService extends Service {
|
||||
);
|
||||
|
||||
// Send the instance to the client
|
||||
await this.io.emit("searchInitiated", {
|
||||
await namespacedInstance.emit("searchInitiated", {
|
||||
instance,
|
||||
});
|
||||
|
||||
@@ -142,7 +148,7 @@ export default class SocketService extends Service {
|
||||
`search`,
|
||||
`search_result_added`,
|
||||
(groupedResult) => {
|
||||
this.io.emit(
|
||||
namespacedInstance.emit(
|
||||
"searchResultAdded",
|
||||
groupedResult
|
||||
);
|
||||
@@ -154,8 +160,7 @@ export default class SocketService extends Service {
|
||||
`search`,
|
||||
`search_result_updated`,
|
||||
(updatedResult) => {
|
||||
console.log("hi", updatedResult);
|
||||
this.io.emit(
|
||||
namespacedInstance.emit(
|
||||
"searchResultUpdated",
|
||||
updatedResult
|
||||
);
|
||||
@@ -173,14 +178,21 @@ export default class SocketService extends Service {
|
||||
`search/${instance.id}`
|
||||
);
|
||||
// Send the instance to the client
|
||||
await this.io.emit("searchesSent", {
|
||||
searchInfo,
|
||||
});
|
||||
await namespacedInstance.emit(
|
||||
"searchesSent",
|
||||
{
|
||||
searchInfo,
|
||||
}
|
||||
);
|
||||
if (currentInstance.result_count === 0) {
|
||||
console.log("No more search results.");
|
||||
this.io.emit("searchComplete", {
|
||||
message: "No more search results.",
|
||||
});
|
||||
namespacedInstance.emit(
|
||||
"searchComplete",
|
||||
{
|
||||
message:
|
||||
"No more search results.",
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
instance.id
|
||||
@@ -192,7 +204,10 @@ export default class SocketService extends Service {
|
||||
query
|
||||
);
|
||||
} catch (error) {
|
||||
await this.io.emit("searchError", error.message);
|
||||
await namespacedInstance.emit(
|
||||
"searchError",
|
||||
error.message
|
||||
);
|
||||
throw new MoleculerError(
|
||||
"Search failed",
|
||||
500,
|
||||
|
||||
Reference in New Issue
Block a user