mirror of
https://github.com/aljazceru/bakery.git
synced 2025-12-17 12:45:20 +01:00
cleanup old scrapper actions
This commit is contained in:
@@ -14,7 +14,6 @@ import { NIP_11_SOFTWARE_URL, SENSITIVE_KINDS } from "../const.js";
|
||||
import { OWNER_PUBKEY, BAKERY_PORT } from "../env.js";
|
||||
|
||||
import ControlApi from "../modules/control/control-api.js";
|
||||
import ConfigActions from "../modules/control/config-actions.js";
|
||||
import DirectMessageManager from "../modules/direct-message-manager.js";
|
||||
import DirectMessageActions from "../modules/control/dm-actions.js";
|
||||
import AddressBook from "../modules/address-book.js";
|
||||
@@ -170,7 +169,6 @@ export default class App extends EventEmitter<EventMap> {
|
||||
|
||||
// API for controlling the node
|
||||
this.control = new ControlApi(this);
|
||||
this.control.registerHandler(new ConfigActions(this));
|
||||
this.control.registerHandler(new DirectMessageActions(this));
|
||||
this.control.registerHandler(new NotificationActions(this));
|
||||
this.control.registerHandler(new RemoteAuthActions(this));
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "applesauce-core/helpers";
|
||||
import { simpleTimeout } from "applesauce-core/observable";
|
||||
import { ReplaceableLoader, SingleEventLoader } from "applesauce-loaders/loaders";
|
||||
import { filter, firstValueFrom, map, of, OperatorFunction } from "rxjs";
|
||||
import { filter, firstValueFrom, OperatorFunction } from "rxjs";
|
||||
import { kinds } from "nostr-tools";
|
||||
|
||||
/** Helper class for asynchronously loading event data */
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
import { WebSocket } from "ws";
|
||||
import { ConfigMessage, ConfigResponse } from "@satellite-earth/core/types/control-api/config.js";
|
||||
|
||||
import type App from "../../app/index.js";
|
||||
import { type ControlMessageHandler } from "./control-api.js";
|
||||
|
||||
/** handles ['CONTROL', 'CONFIG', ...] messages */
|
||||
export default class ConfigActions implements ControlMessageHandler {
|
||||
app: App;
|
||||
name = "CONFIG";
|
||||
|
||||
private subscribed = new Set<WebSocket | NodeJS.Process>();
|
||||
|
||||
constructor(app: App) {
|
||||
this.app = app;
|
||||
|
||||
// when config changes send it to the subscribed sockets
|
||||
this.app.config.on("changed", (config) => {
|
||||
for (const sock of this.subscribed) {
|
||||
this.send(sock, ["CONTROL", "CONFIG", "CHANGED", config]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleMessage(sock: WebSocket | NodeJS.Process, message: ConfigMessage) {
|
||||
const method = message[2];
|
||||
switch (method) {
|
||||
case "SUBSCRIBE":
|
||||
this.subscribed.add(sock);
|
||||
sock.once("close", () => this.subscribed.delete(sock));
|
||||
this.send(sock, ["CONTROL", "CONFIG", "CHANGED", this.app.config.data]);
|
||||
return true;
|
||||
|
||||
case "SET":
|
||||
const field = message[3];
|
||||
const value = message[4];
|
||||
|
||||
// @ts-expect-error
|
||||
this.app.config.setField(field, value);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
send(sock: WebSocket | NodeJS.Process, response: ConfigResponse) {
|
||||
sock.send?.(JSON.stringify(response));
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import { WebSocket } from "ws";
|
||||
import { ScrapperMessage } from "@satellite-earth/core/types/control-api/scrapper.js";
|
||||
|
||||
import type App from "../../app/index.js";
|
||||
import { type ControlMessageHandler } from "./control-api.js";
|
||||
|
||||
export default class ScrapperActions implements ControlMessageHandler {
|
||||
app: App;
|
||||
name = "SCRAPPER";
|
||||
|
||||
constructor(app: App) {
|
||||
this.app = app;
|
||||
}
|
||||
handleMessage(sock: WebSocket | NodeJS.Process, message: ScrapperMessage): boolean {
|
||||
const action = message[2];
|
||||
switch (action) {
|
||||
case "START":
|
||||
this.app.scrapper.start();
|
||||
return true;
|
||||
|
||||
case "STOP":
|
||||
this.app.scrapper.stop();
|
||||
return true;
|
||||
|
||||
case "ADD-PUBKEY":
|
||||
this.app.scrapper.addPubkey(message[3]);
|
||||
return true;
|
||||
|
||||
case "REMOVE-PUBKEY":
|
||||
this.app.scrapper.removePubkey(message[3]);
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user