Skip to content

Commit

Permalink
iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Jun 3, 2024
1 parent f2cc660 commit 79b4739
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
30 changes: 22 additions & 8 deletions api/src/controllers/farcaster.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 });
}
};
3 changes: 3 additions & 0 deletions api/src/packages/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 () => {
Expand Down

0 comments on commit 79b4739

Please sign in to comment.