[READ-ONLY] Mirror of https://github.com/flo-bit/skywatched-backend. backend/jetstream consumer for skywatched.app skywatched.app
0

Configure Feed

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

allow editing of reviews

Florian (Jan 22, 2025, 7:52 PM +0100) 73324c0c 2b676f69

+18 -7
+5 -2
src/database.ts
··· 210 210 return rows.map((row) => row.author_did); 211 211 } 212 212 213 - export function createRecord(record: MainRecord): void { 213 + export function createRecord( 214 + record: MainRecord, 215 + override: boolean = false 216 + ): void { 214 217 const sql = ` 215 - INSERT INTO records ( 218 + INSERT ${override ? "OR REPLACE" : ""} INTO records ( 216 219 uri, cid, 217 220 218 221 author_did, author_handle, author_displayName, author_avatar,
+13 -5
src/jetstream.ts
··· 1 - 2 - import WebSocket from 'ws'; 1 + import WebSocket from "ws"; 3 2 import { 4 3 backfillUserIfNecessary, 5 4 createRecord, ··· 62 61 63 62 if ( 64 63 json.kind === "commit" && 64 + json.commit.operation === "update" && 65 + json.commit.collection === "my.skylights.rel" 66 + ) { 67 + saveRatingToDatabase(json, true); 68 + } 69 + 70 + if ( 71 + json.kind === "commit" && 65 72 json.commit.collection === "community.lexicon.interaction.like" && 66 73 json.commit.operation === "create" 67 74 ) { ··· 90 97 }; 91 98 } 92 99 93 - async function saveRatingToDatabase(json: any) { 100 + async function saveRatingToDatabase(json: any, update: boolean = false) { 101 + console.log(JSON.stringify(json, null, 2)); 94 102 if ( 95 103 json.commit.record.item.ref !== "tmdb:s" && 96 104 json.commit.record.item.ref !== "tmdb:m" ··· 153 161 }; 154 162 } 155 163 try { 156 - createRecord(record); 164 + createRecord(record, update); 157 165 } catch (e: any) { 158 166 if (e.code === "SQLITE_CONSTRAINT_PRIMARYKEY") { 159 167 console.log("not saving record, already exists", record.uri); ··· 215 223 printTimestamp(currentTimestamp); 216 224 217 225 startWebSocket(currentTimestamp); 218 - } 226 + }