···11import type { Label } from "@atcute/atproto/types/label/defs";
22import type { LabelerConfig } from "../types/settings.js";
33import { logger } from "../logger.js";
44+import type { LibSQLDatabase } from "drizzle-orm/libsql";
55+import * as schema from "../db/schema.js";
4655-export const handleNewLabel = async (config: LabelerConfig, label: Label) => {
77+export const handleNewLabel = async (
88+ config: LabelerConfig,
99+ label: Label,
1010+ db: LibSQLDatabase<typeof schema>,
1111+) => {
612 // TODO: MAKE SURE TO CHECK NEG
713 logger.info({ host: config.host }, "From");
814···1420 "Listed label found. Performing the action",
1521 );
1622 }
1717- logger.info({ src: label.src, val: label.val, uri: label.uri, neg: label.neg }, "Label");
2323+ logger.info(
2424+ { src: label.src, val: label.val, uri: label.uri, neg: label.neg },
2525+ "Label",
2626+ );
1827};
+2-2
src/handlers/lablerSubscriber.ts
···66import { logger } from "../logger.js";
77import type { LibSQLDatabase } from "drizzle-orm/libsql";
88import { labelerCursor } from "../db/schema.js";
99-import { eq } from "drizzle-orm";
109import * as schema from "../db/schema.js";
11101211export const labelerSubscriber = (
···3130 const run = async () => {
3231 logger.info({ host: config.host }, "Listening");
3332 for await (const message of iterator) {
3333+ // Saves the cursor for resume and re connect
3434 if ("seq" in message) {
3535 cursor = message.seq;
3636 await db
···4949 case "com.atproto.label.subscribeLabels#labels": {
5050 for (const label of message.labels) {
5151 queue.add(async () => {
5252- await handleNewLabel(config, label);
5252+ await handleNewLabel(config, label, db);
5353 });
5454 }
5555 break;
+5-4
src/index.ts
···77import type { Settings } from "./types/settings.js";
88import { logger } from "./logger.js";
99import { labelerCursor } from "./db/schema.js";
1010-import { eq } from "drizzle-orm";
1010+1111const queue = new PQueue({ concurrency: 2 });
12121313// TODO
···2525//TODO I really really don't like this unknown to settings. Figure that out later. Cause. It does work >.>
2626const settings = parse(settingsFile) as unknown as Settings;
27272828+// Gets the last saved cursors for Labelers from db for resume
2929+const lastCursors = await db.select().from(labelerCursor);
3030+2831const labelers = settings.labeler;
2929-3030-const lastCursors = await db.select().from(labelerCursor);
31323233const subscribers = Object.entries(labelers).map(([_, config]) => {
3334 let lastCursorRow = lastCursors.find(
···3738 return labelerSubscriber(config, lastCursor, db, queue);
3839});
39404040-// --- Graceful shutdown ---
4141+// Graceful shutdown
4142async function shutdown(signal: string) {
4243 logger.info(`Received ${signal}, shutting down...`);
4344