@@ -4,7 +4,7 @@ import { createClient } from "@supabase/supabase-js";
44import dotenv from "dotenv" ;
55import WebSocket from "ws" ;
66import validateRecord from "./validate" ;
7- import { dummyEvent } from "./schema" ;
7+ import { dummyEvent , schema } from "./schema" ;
88import { api } from "./atproto" ;
99
1010dotenv . config ( ) ;
@@ -18,16 +18,10 @@ const supabase = createClient(
1818 process . env . SUPABASE_KEY !
1919) ;
2020
21- // Initialize BskyAgent
22- const agent = new BskyAgent ( {
23- service : "https://bsky.social" ,
24- } ) ;
25-
2621// Target lexicon details
27- const LEXICON_DID = "did:plc:dhnigydy24fp542wu5sxqy33" ; // devcon did
28- const COLLECTION_NAME = "org.devcon.event.test" ;
29- const LEXICON_NSID = "com.atproto.lexicon.schema/org.devcon.event.test" ;
30- const FULL_LEXICON_URI = `${ LEXICON_DID } /${ LEXICON_NSID } ` ;
22+ // const LEXICON_DID = "did:plc:dhnigydy24fp542wu5sxqy33"; // devcon did
23+ const COLLECTION_NAME = "org.devcon.event.vone" ;
24+ // const LEXICON_NSID = "com.atproto.lexicon.schema/org.devcon.event.vone";
3125
3226// Store cursor in memory and sync with Supabase
3327let currentCursor : string | undefined ;
@@ -108,12 +102,12 @@ async function startFirehose() {
108102
109103 // Subtract a buffer (5 seconds worth of microseconds) to ensure gapless playback
110104 let cursorForConnection = cursor ;
111- // if (cursorForConnection) {
112- // const cursorValue = BigInt(cursorForConnection);
113- // const fiveSecondsInMicroseconds = BigInt(5 * 1000 * 1000);
114- // cursorForConnection = String(cursorValue - fiveSecondsInMicroseconds);
115- // console.log("Using cursor with 5 second buffer:", cursorForConnection);
116- // }
105+ if ( cursorForConnection ) {
106+ const cursorValue = BigInt ( cursorForConnection ) ;
107+ const fiveSecondsInMicroseconds = BigInt ( 5 * 1000 * 1000 ) ;
108+ cursorForConnection = String ( cursorValue - fiveSecondsInMicroseconds ) ;
109+ console . log ( "Using cursor with 5 second buffer:" , cursorForConnection ) ;
110+ }
117111
118112 // Add cursor as a query parameter if it exists
119113 const wsUrl = cursorForConnection
@@ -267,37 +261,18 @@ app.get("/all-events", async (req, res) => {
267261 const { data, error } = await supabase
268262 . from ( "atproto-events" )
269263 . select ( "did, record" ) ;
270- res . json ( data ) ;
271- } ) ;
272-
273- app . get ( "/validate-event" , async ( req , res ) => {
274- // const record = req.body.record;
275-
276- const { valid, error } = validateRecord ( dummyEvent ) ;
277264
278- if ( valid ) {
279- res . status ( 200 ) . json ( { valid : true } ) ;
280- } else {
281- res . status ( 400 ) . json ( { valid : false , error } ) ;
282- }
283- } ) ;
284-
285- app . get ( "/submit-event" , async ( req , res ) => {
286- const { valid, error } = validateRecord ( req . body ) ;
287-
288- res . json ( { valid, error } ) ;
289-
290- if ( valid ) {
291- res . status ( 200 ) . json ( { valid : true } ) ;
265+ if ( error ) {
266+ res . status ( 500 ) . json ( { error } ) ;
292267 } else {
293- res . status ( 400 ) . json ( { valid : false , error } ) ;
268+ res . json ( data ) ;
294269 }
295270} ) ;
296271
297- app . get ( "/submit -event-to-devcon-pds " , async ( req , res ) => {
298- const { valid , error } = validateRecord ( req . body ) ;
272+ app . get ( "/validate -event" , async ( req , res ) => {
273+ const record = req . body . record ;
299274
300- res . json ( { valid, error } ) ;
275+ const { valid, error } = validateRecord ( record ) ;
301276
302277 if ( valid ) {
303278 res . status ( 200 ) . json ( { valid : true } ) ;
@@ -306,42 +281,9 @@ app.get("/submit-event-to-devcon-pds", async (req, res) => {
306281 }
307282} ) ;
308283
309- // app.get("/add-record-to-devcon-pds", async (req, res) => {
310- // const { valid, error } = validateRecord(req.body);
311-
312- // if (valid) {
313- // const result = await api.addRecordToDevconPds(
314- // "https://bsky.social",
315- // process.env.AT_USERNAME!,
316- // process.env.AT_PASSWORD!,
317- // req.body
318- // );
319-
320- // res.json({ valid, error });
321- // }
322- // });
323-
324- // app.get("/add-schema", async (req, res) => {
325- // if (valid) {
326- // res.status(200).json({ valid: true });
327- // } else {
328- // res.status(400).json({ valid: false, error });
329- // }
330- // });
331-
332284// Start the server
333285app . listen ( port , ( ) => {
334286 console . log ( `Server running on port ${ port } ` ) ;
335- // startFirehose();
336287
337- const result = validateRecord ( dummyEvent ) ;
338- console . log ( result ) ;
288+ startFirehose ( ) ;
339289} ) ;
340-
341- /*
342- TODO:
343- - frontend to submit events
344- - update schema to v1
345- - update validate to v1
346- -
347- */
0 commit comments