Initial commit: Cat Sitting Planner with PWA, SQLite, and Webhook Notifications
This commit is contained in:
23
lib/notifications.ts
Normal file
23
lib/notifications.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export async function sendNotification(webhookUrl: string | null, message: string) {
|
||||
if (!webhookUrl) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(webhookUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "CatSittingPlanner/1.0"
|
||||
},
|
||||
// Works for Discord (content) and generic Telegram Webhook bridges (text)
|
||||
body: JSON.stringify({
|
||||
content: message,
|
||||
text: message
|
||||
}),
|
||||
});
|
||||
if (!response.ok) {
|
||||
console.error(`[Notification] Webhook failed with status ${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to send notification:", error);
|
||||
}
|
||||
}
|
||||
17
lib/prisma.ts
Normal file
17
lib/prisma.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient()
|
||||
}
|
||||
|
||||
type PrismaClientSingleton = ReturnType<typeof prismaClientSingleton>
|
||||
|
||||
const globalForPrisma = globalThis as unknown as {
|
||||
prisma: PrismaClientSingleton | undefined
|
||||
}
|
||||
|
||||
const prisma = globalForPrisma.prisma ?? prismaClientSingleton()
|
||||
|
||||
export default prisma
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
||||
6
lib/utils.ts
Normal file
6
lib/utils.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { clsx, type ClassValue } from "clsx"
|
||||
import { twMerge } from "tailwind-merge"
|
||||
|
||||
export function cn(...inputs: ClassValue[]) {
|
||||
return twMerge(clsx(inputs))
|
||||
}
|
||||
Reference in New Issue
Block a user