this repo has no description
0
fork

Configure Feed

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

Fix ESLint/TS errors

Code still buggy

alice b3130dff 796c182c

+74 -138
+20 -117
src/constants.ts
··· 1 + import type { SignsRecord } from './types.js'; 1 2 import 'dotenv/config'; 2 3 3 4 export const DID = process.env.DID ?? ''; 4 5 export const SIGNING_KEY = process.env.SIGNING_KEY ?? ''; 5 - export const PORT = 4002; 6 + export const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 4002; 6 7 export const DELETE = '3l3lu2lrpkl2a'; 7 - export const SIGNS: Record< 8 - 'sun' | 'moon' | 'rising', 9 - Array<{ post: string; label: string; displayLabel: string; enDesc: string; brDesc: string }> 10 - > = { 8 + 9 + export const SIGNS: SignsRecord = { 11 10 sun: [ 12 11 { post: '3l3lfvkycmr2n', label: 'aaa-sun-aries', displayLabel: '♈\u202F☀️', enDesc: 'Aries', brDesc: 'Áries' }, 13 12 { post: '3l3lfw3vfwl2c', label: 'aaa-sun-taurus', displayLabel: '♉\u202F☀️', enDesc: 'Taurus', brDesc: 'Touro' }, ··· 16 15 { post: '3l3lfwp2nu72y', label: 'aaa-sun-leo', displayLabel: '♌\u202F☀️', enDesc: 'Leo', brDesc: 'Leão' }, 17 16 { post: '3l3lfwvsi472y', label: 'aaa-sun-virgo', displayLabel: '♍\u202F☀️', enDesc: 'Virgo', brDesc: 'Virgem' }, 18 17 { post: '3l3lfx456nm2m', label: 'aaa-sun-libra', displayLabel: '♎\u202F☀️', enDesc: 'Libra', brDesc: 'Libra' }, 19 - { 20 - post: '3l3lfxezjxm2o', 21 - label: 'aaa-sun-scorpio', 22 - displayLabel: '♏\u202F☀️', 23 - enDesc: 'Scorpio', 24 - brDesc: 'Escorpião', 25 - }, 26 - { 27 - post: '3l3lfxkifbh27', 28 - label: 'aaa-sun-sagittarius', 29 - displayLabel: '♐\u202F☀️', 30 - enDesc: 'Sagittarius', 31 - brDesc: 'Sagitário', 32 - }, 33 - { 34 - post: '3l3lfxqfxie2n', 35 - label: 'aaa-sun-capricorn', 36 - displayLabel: '♑\u202F☀️', 37 - enDesc: 'Capricorn', 38 - brDesc: 'Capricórnio', 39 - }, 40 - { 41 - post: '3l3lfxvt5672y', 42 - label: 'aaa-sun-aquarius', 43 - displayLabel: '♒\u202F☀️', 44 - enDesc: 'Aquarius', 45 - brDesc: 'Aquário', 46 - }, 18 + { post: '3l3lfxezjxm2o', label: 'aaa-sun-scorpio', displayLabel: '♏\u202F☀️', enDesc: 'Scorpio', brDesc: 'Escorpião' }, 19 + { post: '3l3lfxkifbh27', label: 'aaa-sun-sagittarius', displayLabel: '♐\u202F☀️', enDesc: 'Sagittarius', brDesc: 'Sagitário' }, 20 + { post: '3l3lfxqfxie2n', label: 'aaa-sun-capricorn', displayLabel: '♑\u202F☀️', enDesc: 'Capricorn', brDesc: 'Capricórnio' }, 21 + { post: '3l3lfxvt5672y', label: 'aaa-sun-aquarius', displayLabel: '♒\u202F☀️', enDesc: 'Aquarius', brDesc: 'Aquário' }, 47 22 { post: '3l3lfy74k242r', label: 'aaa-sun-pisces', displayLabel: '♓\u202F☀️', enDesc: 'Pisces', brDesc: 'Peixes' }, 48 23 ], 49 24 moon: [ ··· 54 29 { post: '3l3lhhikpzf2x', label: 'bbb-moon-leo', displayLabel: '♌\u202F🌙', enDesc: 'Leo', brDesc: 'Leão' }, 55 30 { post: '3l3lhivrrem2n', label: 'bbb-moon-virgo', displayLabel: '♍\u202F🌙', enDesc: 'Virgo', brDesc: 'Virgem' }, 56 31 { post: '3l3lhj55tvo2t', label: 'bbb-moon-libra', displayLabel: '♎\u202F🌙', enDesc: 'Libra', brDesc: 'Libra' }, 57 - { 58 - post: '3l3lhjd5dvj2n', 59 - label: 'bbb-moon-scorpio', 60 - displayLabel: '♏\u202F🌙', 61 - enDesc: 'Scorpio', 62 - brDesc: 'Escorpião', 63 - }, 64 - { 65 - post: '3l3lhjjlnyg2j', 66 - label: 'bbb-moon-sagittarius', 67 - displayLabel: '♐\u202F🌙', 68 - enDesc: 'Sagittarius', 69 - brDesc: 'Sagitário', 70 - }, 71 - { 72 - post: '3l3lhjqpcmb2r', 73 - label: 'bbb-moon-capricorn', 74 - displayLabel: '♑\u202F🌙', 75 - enDesc: 'Capricorn', 76 - brDesc: 'Capricórnio', 77 - }, 78 - { 79 - post: '3l3lhjwjny22h', 80 - label: 'bbb-moon-aquarius', 81 - displayLabel: '♒\u202F🌙', 82 - enDesc: 'Aquarius', 83 - brDesc: 'Aquário', 84 - }, 32 + { post: '3l3lhjd5dvj2n', label: 'bbb-moon-scorpio', displayLabel: '♏\u202F🌙', enDesc: 'Scorpio', brDesc: 'Escorpião' }, 33 + { post: '3l3lhjjlnyg2j', label: 'bbb-moon-sagittarius', displayLabel: '♐\u202F🌙', enDesc: 'Sagittarius', brDesc: 'Sagitário' }, 34 + { post: '3l3lhjqpcmb2r', label: 'bbb-moon-capricorn', displayLabel: '♑\u202F🌙', enDesc: 'Capricorn', brDesc: 'Capricórnio' }, 35 + { post: '3l3lhjwjny22h', label: 'bbb-moon-aquarius', displayLabel: '♒\u202F🌙', enDesc: 'Aquarius', brDesc: 'Aquário' }, 85 36 { post: '3l3lhkcfc7x27', label: 'bbb-moon-pisces', displayLabel: '♓\u202F🌙', enDesc: 'Pisces', brDesc: 'Peixes' }, 86 37 ], 87 38 rising: [ 88 39 { post: '3l3lhsnuiqx27', label: 'ccc-rising-aries', displayLabel: '♈\u202F⬆️', enDesc: 'Aries', brDesc: 'Áries' }, 89 - { 90 - post: '3l3lhsu7qtk2q', 91 - label: 'ccc-rising-taurus', 92 - displayLabel: '♉\u202F⬆️', 93 - enDesc: 'Taurus', 94 - brDesc: 'Touro', 95 - }, 96 - { 97 - post: '3l3lht44nz32c', 98 - label: 'ccc-rising-gemini', 99 - displayLabel: '♊\u202F⬆️', 100 - enDesc: 'Gemini', 101 - brDesc: 'Gêmeos', 102 - }, 103 - { 104 - post: '3l3lhtbxbrt2n', 105 - label: 'ccc-rising-cancer', 106 - displayLabel: '♋\u202F⬆️', 107 - enDesc: 'Cancer', 108 - brDesc: 'Câncer', 109 - }, 40 + { post: '3l3lhsu7qtk2q', label: 'ccc-rising-taurus', displayLabel: '♉\u202F⬆️', enDesc: 'Taurus', brDesc: 'Touro' }, 41 + { post: '3l3lht44nz32c', label: 'ccc-rising-gemini', displayLabel: '♊\u202F⬆️', enDesc: 'Gemini', brDesc: 'Gêmeos' }, 42 + { post: '3l3lhtbxbrt2n', label: 'ccc-rising-cancer', displayLabel: '♋\u202F⬆️', enDesc: 'Cancer', brDesc: 'Câncer' }, 110 43 { post: '3l3lhtjco7g2f', label: 'ccc-rising-leo', displayLabel: '♌\u202F⬆️', enDesc: 'Leo', brDesc: 'Leão' }, 111 44 { post: '3l3lhtoxwyo2p', label: 'ccc-rising-virgo', displayLabel: '♍\u202F⬆️', enDesc: 'Virgo', brDesc: 'Virgem' }, 112 45 { post: '3l3lhtubu4b23', label: 'ccc-rising-libra', displayLabel: '♎\u202F⬆️', enDesc: 'Libra', brDesc: 'Libra' }, 113 - { 114 - post: '3l3lhu2qoyf2h', 115 - label: 'ccc-rising-scorpio', 116 - displayLabel: '♏\u202F⬆️', 117 - enDesc: 'Scorpio', 118 - brDesc: 'Escorpião', 119 - }, 120 - { 121 - post: '3l3lhu77pvx27', 122 - label: 'ccc-rising-sagittarius', 123 - displayLabel: '♐\u202F⬆️', 124 - enDesc: 'Sagittarius', 125 - brDesc: 'Sagitário', 126 - }, 127 - { 128 - post: '3l3lhueqe5l2n', 129 - label: 'ccc-rising-capricorn', 130 - displayLabel: '♑\u202F⬆️', 131 - enDesc: 'Capricorn', 132 - brDesc: 'Capricórnio', 133 - }, 134 - { 135 - post: '3l3lhujywjw2t', 136 - label: 'ccc-rising-aquarius', 137 - displayLabel: '♒\u202F⬆️', 138 - enDesc: 'Aquarius', 139 - brDesc: 'Aquário', 140 - }, 141 - { 142 - post: '3l3lhuqczcj2n', 143 - label: 'ccc-rising-pisces', 144 - displayLabel: '♓\u202F⬆️', 145 - enDesc: 'Pisces', 146 - brDesc: 'Peixes', 147 - }, 46 + { post: '3l3lhu2qoyf2h', label: 'ccc-rising-scorpio', displayLabel: '♏\u202F⬆️', enDesc: 'Scorpio', brDesc: 'Escorpião' }, 47 + { post: '3l3lhu77pvx27', label: 'ccc-rising-sagittarius', displayLabel: '♐\u202F⬆️', enDesc: 'Sagittarius', brDesc: 'Sagitário' }, 48 + { post: '3l3lhueqe5l2n', label: 'ccc-rising-capricorn', displayLabel: '♑\u202F⬆️', enDesc: 'Capricorn', brDesc: 'Capricórnio' }, 49 + { post: '3l3lhujywjw2t', label: 'ccc-rising-aquarius', displayLabel: '♒\u202F⬆️', enDesc: 'Aquarius', brDesc: 'Aquário' }, 50 + { post: '3l3lhuqczcj2n', label: 'ccc-rising-pisces', displayLabel: '♓\u202F⬆️', enDesc: 'Pisces', brDesc: 'Peixes' }, 148 51 ], 149 52 };
+17 -14
src/label.ts
··· 1 1 import { AppBskyActorDefs, ComAtprotoLabelDefs } from '@atproto/api'; 2 2 import { DID, PORT, SIGNS, SIGNING_KEY, DELETE } from './constants.js'; 3 + import { CATEGORY_PREFIXES } from './types.js'; 4 + import type { Category } from './types.js'; 3 5 import { LabelerServer } from '@skyware/labeler'; 4 6 5 7 const server = new LabelerServer({ did: DID, signingKey: SIGNING_KEY }); ··· 15 17 export const label = async (subject: string | AppBskyActorDefs.ProfileView, rkey: string) => { 16 18 const did = AppBskyActorDefs.isProfileView(subject) ? subject.did : subject; 17 19 console.log(`Labeling ${did}...`); 18 - console.log('Received rkey:', rkey); 20 + console.log(`Received rkey: ${rkey}`); 19 21 20 22 try { 21 - const labelCategories = await fetchCurrentLabels(did); 23 + const labelCategories = fetchCurrentLabels(did); 22 24 23 25 if (rkey.includes(DELETE)) { 24 26 console.log('Delete operation detected'); 25 - await massDeleteLabels(did, labelCategories); 27 + await deleteAllLabels(did, labelCategories); 26 28 } else { 27 29 console.log('Add/Update operation detected'); 28 30 await addOrUpdateLabel(did, rkey, labelCategories); ··· 32 34 } 33 35 }; 34 36 35 - async function fetchCurrentLabels(did: string) { 37 + function fetchCurrentLabels(did: string) { 36 38 console.log('Fetching current labels for:', did); 37 39 const categories = ['sun', 'moon', 'rising']; 38 40 const labelCategories: Record<string, string | null> = {}; ··· 73 75 return labelCategories; 74 76 } 75 77 76 - async function massDeleteLabels(did: string, labelCategories: Record<string, string | null>) { 77 - console.log('Attempting to mass-delete labels for:', did); 78 - const labelsToDelete = Object.values(labelCategories).filter((label) => label !== null) as string[]; 78 + async function deleteAllLabels(did: string, labelCategories: Record<string, string | null>) { 79 + console.log('Attempting to delete all labels for:', did); 80 + const labelsToDelete = Object.values(labelCategories).filter((label) => label !== null); 79 81 80 82 if (labelsToDelete.length === 0) { 81 - console.log('No labels to mass-delete for', did); 83 + console.log('No labels to delete for', did); 82 84 return; 83 85 } 84 86 ··· 143 145 return null; 144 146 } 145 147 146 - function getCategoryFromLabel(label: string): 'sun' | 'moon' | 'rising' { 147 - console.log('Getting category for label:', label); 148 - if (label.startsWith('aaa-sun-')) return 'sun'; 149 - if (label.startsWith('bbb-moon-')) return 'moon'; 150 - if (label.startsWith('ccc-rising-')) return 'rising'; 151 - console.error('Invalid label:', label); 148 + function getCategoryFromLabel(label: string): Category { 149 + for (const [category, prefix] of Object.entries(CATEGORY_PREFIXES)) { 150 + if (label.startsWith(`${prefix}-${category}-`)) { 151 + return category as Category; 152 + } 153 + } 154 + 152 155 throw new Error(`Invalid label: ${label}`); 153 156 }
+18 -7
src/main.ts
··· 4 4 import { DID } from './constants.js'; 5 5 import fs from 'node:fs'; 6 6 7 - const subscribe = async () => { 7 + const subscribe = () => { 8 8 let cursorFirehose = 0; 9 9 let intervalID: NodeJS.Timeout; 10 - const cursorFile = fs.readFileSync('cursor.txt', 'utf8'); 10 + let cursor: string | undefined = undefined; 11 + 12 + if (fs.existsSync('cursor.txt')) { 13 + console.log('Loading cursor from cursor.txt'); 14 + cursor = fs.readFileSync('cursor.txt', 'utf8'); 15 + } else { 16 + fs.writeFileSync('cursor.txt', '', 'utf8'); 17 + console.log('Created new empty cursor.txt file, as it did not exist'); 18 + } 11 19 12 - const firehose = new Firehose({ cursor: cursorFile ?? '' }); 13 - if (cursorFile) console.log(`Initiate firehose at cursor ${cursorFile}`); 20 + const firehose = new Firehose({ cursor }); 21 + if (cursor) console.log(`Initiate firehose at cursor ${cursor}`); 14 22 15 23 firehose.on('error', ({ cursor, error }) => { 16 - console.log(`Firehose errored on cursor: ${cursor}`, error); 24 + // this is a noisy bug with brid.gy, ignore it for now 25 + if (!(error.name === 'RangeError' && error.message.includes('Could not decode varint'))) { 26 + console.error(`Firehose errored on cursor: ${cursor}`, error); 27 + } 17 28 }); 18 29 19 30 firehose.on('open', () => { ··· 32 43 33 44 firehose.on('commit', (commit) => { 34 45 cursorFirehose = commit.seq; 35 - commit.ops.forEach(async (op) => { 46 + commit.ops.forEach((op) => { 36 47 if (op.action !== 'delete' && AppBskyFeedLike.isRecord(op.record)) { 37 48 if (op.record.subject.uri.includes(DID)) { 38 49 if (op.record.subject.uri.includes('app.bsky.feed.post')) { 39 - await label(commit.repo, op.record.subject.uri.split('/').pop()!).catch((err) => console.error(err)); 50 + label(commit.repo, op.record.subject.uri.split('/').pop()!).catch((err: unknown) => { console.error(err); }); 40 51 } 41 52 } 42 53 }
+19
src/types.ts
··· 1 + export type Category = 'sun' | 'moon' | 'rising'; 2 + // we need this to keep the sun - moon - rising order on the frontend 3 + type CategoryPrefix = 'aaa' | 'bbb' | 'ccc'; 4 + 5 + interface ZodiacSign { 6 + post: string; 7 + label: `${CategoryPrefix}-${Category}-${string}`; 8 + displayLabel: string; 9 + enDesc: string; 10 + brDesc: string; 11 + } 12 + 13 + export type SignsRecord = Record<Category, ZodiacSign[]>; 14 + 15 + export const CATEGORY_PREFIXES: Record<Category, CategoryPrefix> = { 16 + sun: 'aaa', 17 + moon: 'bbb', 18 + rising: 'ccc', 19 + };