diff --git a/api/src/controllers/farcaster.js b/api/src/controllers/farcaster.js index 79b5a15a..1555374c 100644 --- a/api/src/controllers/farcaster.js +++ b/api/src/controllers/farcaster.js @@ -1,10 +1,13 @@ +import { getPKPSession, getPKPSessionForIndexer } from "../libs/lit/index.js"; import { ComposeDBService } from "../services/composedb.js"; +import { IndexService } from "../services/index.js"; +import { ItemService } from "../services/item.js"; -export const createWebPage = async (req, res, next) => { +export const createCast = async (req, res, next) => { const definition = req.app.get("runtimeDefinition"); const modelFragments = req.app.get("modelFragments"); const castFragment = modelFragments.filter( - (fragment) => fragment.name === "FarcasterCast", + (fragment) => fragment.name === "Cast", )[0]; //todo get fragment @@ -15,11 +18,22 @@ export const createWebPage = async (req, res, next) => { ).setSession(req.session); const cast = await composeDBService.createNode({ - ...req.body, + ...req.body.data, }); - res.status(201).json(cast); - } catch (error) { - res.status(500).json({ error: error.message }); - } -}; + + const indexId = `kjzl6kcym7w8y97yfoer7bb20k4j3x3jb64t6nk714879q9cqyr3s8kuhpg9b84` + + try { + const indexService = new IndexService(definition); + const index = await indexService.getIndexById(indexId); + const pkpSession = await getPKPSessionForIndexer(index); + + const itemService = new ItemService(definition).setSession(pkpSession); + const item = await itemService.addItem(indexId, cast.id); + + res.status(201).json({ cast, item }); + } catch (error) { + res.status(500).json({ error: error.message }); + } + }; diff --git a/api/src/packages/api.js b/api/src/packages/api.js index bfd1f0c6..b36a609d 100644 --- a/api/src/packages/api.js +++ b/api/src/packages/api.js @@ -27,6 +27,8 @@ import * as embeddingController from "../controllers/embedding.js"; import * as didController from "../controllers/did.js"; import * as discoveryController from "../controllers/discovery.js"; +import * as farcasterController from "../controllers/farcaster.js"; + import * as litProtocol from "../controllers/lit-protocol.js"; import * as fileController from "../controllers/file.js"; @@ -520,6 +522,7 @@ app.delete( // Validators app.use(errorMiddleware); +app.post("/farcaster/updates", farcasterController.createCast); app.ws("/discovery/:chatId/updates", discoveryController.updates); const start = async () => {