remove unused code, add try/catch block

This commit is contained in:
2025-07-01 15:30:33 -04:00
parent c0ed38ac1a
commit 379099dc7a

View File

@ -11,28 +11,6 @@ import { createWebsocket } from "./websocket.js";
const prisma = new PrismaClient();
// const getNotifications = async () => {
// try {
// const request = await fetch(
// `${process.env.PLEROMA_INSTANCE_URL}/api/v1/notifications?types[]=mention`,
// {
// method: "GET",
// headers: {
// Authorization: `Bearer ${process.env.INSTANCE_BEARER_TOKEN}`,
// },
// }
// );
// const notifications: Notification[] = await request.json();
// return notifications;
// } catch (error: any) {
// throw new Error(error.message);
// }
// };
// const notifications = await getNotifications();
const storeUserData = async (notification: Notification): Promise<void> => {
try {
await prisma.user.upsert({
@ -182,26 +160,19 @@ ws.on("upgrade", () => {
});
ws.on("message", async (data) => {
const message: WSEvent = JSON.parse(data.toString("utf-8"));
if (message.event !== "notification") {
// only watch for notification events
return;
}
console.log("Websocket message received.");
const payload = JSON.parse(message.payload) as Notification;
const ollamaResponse = await generateOllamaRequest(payload);
if (ollamaResponse) {
await postReplyToStatus(payload, ollamaResponse);
try {
const message: WSEvent = JSON.parse(data.toString("utf-8"));
if (message.event !== "notification") {
// only watch for notification events
return;
}
console.log("Websocket message received.");
const payload = JSON.parse(message.payload) as Notification;
const ollamaResponse = await generateOllamaRequest(payload);
if (ollamaResponse) {
await postReplyToStatus(payload, ollamaResponse);
}
} catch (error: any) {
console.error(error.message);
}
});
// if (notifications) {
// await Promise.all(
// notifications.map(async (notification) => {
// const ollamaResponse = await generateOllamaRequest(notification);
// if (ollamaResponse) {
// postReplyToStatus(notification, ollamaResponse);
// }
// })
// );
// }