this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

prettier, editorconfig

alice 06fa03c2 4bd2ac11

+47 -49
+12
.editorconfig
··· 1 + # EditorConfig is awesome: https://EditorConfig.org 2 + 3 + # top-most EditorConfig file 4 + root = true 5 + 6 + [*] 7 + indent_style = space 8 + indent_size = 2 9 + end_of_line = lf 10 + charset = utf-8 11 + trim_trailing_whitespace = false 12 + insert_final_newline = true
+7
.prettierrc
··· 1 + { 2 + "trailingComma": "all", 3 + "tabWidth": 2, 4 + "semi": true, 5 + "singleQuote": true, 6 + "printWidth": 120 7 + }
setup.ts

This is a binary file and will not be displayed.

+5 -10
src/constants.ts
··· 1 - import "dotenv/config"; 1 + import 'dotenv/config'; 2 2 3 - export const DID = process.env.DID ?? ""; 4 - export const SIGNING_KEY = process.env.SIGNING_KEY ?? ""; 3 + export const DID = process.env.DID ?? ''; 4 + export const SIGNING_KEY = process.env.SIGNING_KEY ?? ''; 5 5 export const PORT = 4001; 6 - export const DELETE = "3l3izhv734g2o"; 7 - export const HOUSES = [ 8 - "gryffindor", 9 - "slytherin", 10 - "ravenclaw", 11 - "hufflepuff", 12 - ]; 6 + export const DELETE = '3l3izhv734g2o'; 7 + export const HOUSES = ['gryffindor', 'slytherin', 'ravenclaw', 'hufflepuff'];
+7 -20
src/label.ts
··· 1 - import { AppBskyActorDefs, ComAtprotoLabelDefs } from "@atproto/api"; 2 - import { 3 - DID, 4 - PORT, 5 - HOUSES, 6 - SIGNING_KEY, 7 - DELETE, 8 - } from "./constants.js"; 9 - import { LabelerServer } from "@skyware/labeler"; 1 + import { AppBskyActorDefs, ComAtprotoLabelDefs } from '@atproto/api'; 2 + import { DID, PORT, HOUSES, SIGNING_KEY, DELETE } from './constants.js'; 3 + import { LabelerServer } from '@skyware/labeler'; 10 4 11 5 const server = new LabelerServer({ did: DID, signingKey: SIGNING_KEY }); 12 6 ··· 18 12 } 19 13 }); 20 14 21 - export const label = async ( 22 - subject: string | AppBskyActorDefs.ProfileView, 23 - rkey: string, 24 - ) => { 15 + export const label = async (subject: string | AppBskyActorDefs.ProfileView, rkey: string) => { 25 16 const did = AppBskyActorDefs.isProfileView(subject) ? subject.did : subject; 26 17 27 - const query = server.db 28 - .prepare< 29 - unknown[], 30 - ComAtprotoLabelDefs.Label 31 - >(`SELECT * FROM labels WHERE uri = ?`) 32 - .all(did); 18 + const query = server.db.prepare<unknown[], ComAtprotoLabelDefs.Label>(`SELECT * FROM labels WHERE uri = ?`).all(did); 33 19 34 20 const labels = query.reduce((set, label) => { 35 21 if (!label.neg) set.add(label.val); ··· 37 23 return set; 38 24 }, new Set<string>()); 39 25 40 - if (rkey.includes(DELETE)) { await server 26 + if (rkey.includes(DELETE)) { 27 + await server 41 28 .createLabels({ uri: did }, { negate: [...labels] }) 42 29 .catch((err) => { 43 30 console.log(err);
+14 -17
src/main.ts
··· 1 - import { AppBskyFeedLike } from "@atproto/api"; 2 - import { Firehose } from "@skyware/firehose"; 3 - import { label } from "./label.js"; 4 - import { DID } from "./constants.js"; 5 - import fs from "node:fs"; 1 + import { AppBskyFeedLike } from '@atproto/api'; 2 + import { Firehose } from '@skyware/firehose'; 3 + import { label } from './label.js'; 4 + import { DID } from './constants.js'; 5 + import fs from 'node:fs'; 6 6 7 7 const subscribe = async () => { 8 8 let cursorFirehose = 0; 9 9 let intervalID: NodeJS.Timeout; 10 - const cursorFile = fs.readFileSync("cursor.txt", "utf8"); 10 + const cursorFile = fs.readFileSync('cursor.txt', 'utf8'); 11 11 12 - const firehose = new Firehose({ cursor: cursorFile ?? "" }); 12 + const firehose = new Firehose({ cursor: cursorFile ?? '' }); 13 13 if (cursorFile) console.log(`Initiate firehose at cursor ${cursorFile}`); 14 14 15 - firehose.on("error", ({ cursor, error }) => { 15 + firehose.on('error', ({ cursor, error }) => { 16 16 console.log(`Firehose errored on cursor: ${cursor}`, error); 17 17 }); 18 18 19 - firehose.on("open", () => { 19 + firehose.on('open', () => { 20 20 intervalID = setInterval(() => { 21 21 const timestamp = new Date().toISOString(); 22 22 console.log(`${timestamp} cursor: ${cursorFirehose}`); 23 - fs.writeFile("cursor.txt", cursorFirehose.toString(), (err) => { 23 + fs.writeFile('cursor.txt', cursorFirehose.toString(), (err) => { 24 24 if (err) console.error(err); 25 25 }); 26 26 }, 60000); 27 27 }); 28 28 29 - firehose.on("close", () => { 29 + firehose.on('close', () => { 30 30 clearInterval(intervalID); 31 31 }); 32 32 33 - firehose.on("commit", (commit) => { 33 + firehose.on('commit', (commit) => { 34 34 cursorFirehose = commit.seq; 35 35 commit.ops.forEach(async (op) => { 36 - if (op.action !== "delete" && AppBskyFeedLike.isRecord(op.record)) { 36 + if (op.action !== 'delete' && AppBskyFeedLike.isRecord(op.record)) { 37 37 if (op.record.subject.uri.includes(DID)) { 38 - await label( 39 - commit.repo, 40 - op.record.subject.uri.split("/").pop()!, 41 - ).catch((err) => console.error(err)); 38 + await label(commit.repo, op.record.subject.uri.split('/').pop()!).catch((err) => console.error(err)); 42 39 } 43 40 } 44 41 });
+2 -2
tsconfig.json
··· 5 5 "module": "ESNext", 6 6 "moduleResolution": "node", 7 7 "allowSyntheticDefaultImports": true, 8 - "esModuleInterop": true, 9 - }, 8 + "esModuleInterop": true 9 + } 10 10 }