remove unused code, add try/catch block
This commit is contained in:
57
src/main.ts
57
src/main.ts
@ -11,28 +11,6 @@ import { createWebsocket } from "./websocket.js";
|
|||||||
|
|
||||||
const prisma = new PrismaClient();
|
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> => {
|
const storeUserData = async (notification: Notification): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
@ -182,26 +160,19 @@ ws.on("upgrade", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ws.on("message", async (data) => {
|
ws.on("message", async (data) => {
|
||||||
const message: WSEvent = JSON.parse(data.toString("utf-8"));
|
try {
|
||||||
if (message.event !== "notification") {
|
const message: WSEvent = JSON.parse(data.toString("utf-8"));
|
||||||
// only watch for notification events
|
if (message.event !== "notification") {
|
||||||
return;
|
// only watch for notification events
|
||||||
}
|
return;
|
||||||
console.log("Websocket message received.");
|
}
|
||||||
const payload = JSON.parse(message.payload) as Notification;
|
console.log("Websocket message received.");
|
||||||
const ollamaResponse = await generateOllamaRequest(payload);
|
const payload = JSON.parse(message.payload) as Notification;
|
||||||
if (ollamaResponse) {
|
const ollamaResponse = await generateOllamaRequest(payload);
|
||||||
await postReplyToStatus(payload, ollamaResponse);
|
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);
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
Reference in New Issue
Block a user