full upgrade to dev

This commit is contained in:
2026-01-08 04:24:22 +01:00
parent e2c2585468
commit 884d7f984b
15 changed files with 2371 additions and 369 deletions

View File

@@ -1,13 +1,17 @@
import { NextResponse } from 'next/server';
import { NextResponse } from "next/server";
export async function POST(request: Request) {
try {
const { message } = await request.json();
let userMessage = "";
if (!message || typeof message !== 'string') {
try {
const json = await request.json();
userMessage = json.message;
const history = json.history || [];
if (!userMessage || typeof userMessage !== "string") {
return NextResponse.json(
{ error: 'Message is required' },
{ status: 400 }
{ error: "Message is required" },
{ status: 400 },
);
}
@@ -15,72 +19,144 @@ export async function POST(request: Request) {
const n8nWebhookUrl = process.env.N8N_WEBHOOK_URL;
if (!n8nWebhookUrl) {
console.error('N8N_WEBHOOK_URL not configured');
// Return fallback response
console.error("N8N_WEBHOOK_URL not configured");
return NextResponse.json({
reply: getFallbackResponse(message)
reply: getFallbackResponse(userMessage),
});
}
console.log(`Sending to n8n: ${n8nWebhookUrl}/webhook/chat`);
const response = await fetch(`${n8nWebhookUrl}/webhook/chat`, {
method: 'POST',
method: "POST",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
...(process.env.N8N_API_KEY && {
'Authorization': `Bearer ${process.env.N8N_API_KEY}`
Authorization: `Bearer ${process.env.N8N_API_KEY}`,
}),
},
body: JSON.stringify({ message }),
body: JSON.stringify({
message: userMessage,
history: history,
}),
});
if (!response.ok) {
console.error(`n8n webhook failed with status: ${response.status}`);
throw new Error(`n8n webhook failed: ${response.status}`);
}
const data = await response.json();
return NextResponse.json({ reply: data.reply || data.message || data.response });
} catch (error) {
console.error('Chat API error:', error);
// Fallback to mock responses if n8n is down
const { message } = await request.json();
return NextResponse.json(
{ reply: getFallbackResponse(message) }
);
console.log("n8n response data:", data);
const reply =
data.reply ||
data.message ||
data.response ||
data.text ||
data.content ||
(Array.isArray(data) && data[0]?.reply);
if (!reply) {
console.warn("n8n response missing reply field:", data);
// If n8n returns successfully but without a clear reply field,
// we might want to show the fallback or a generic error,
// but strictly speaking we shouldn't show "Couldn't process".
// Let's try to stringify the whole data if it's small, or use fallback.
if (data && typeof data === "object" && Object.keys(data).length > 0) {
// It returned something, but we don't know what field to use.
// Check for common n8n structure
if (data.output) return NextResponse.json({ reply: data.output });
if (data.data) return NextResponse.json({ reply: data.data });
}
throw new Error("Invalid response format from n8n");
}
return NextResponse.json({
reply: reply,
});
} catch (error) {
console.error("Chat API error:", error);
// Fallback to mock responses
// Now using the variable captured at the start
return NextResponse.json({ reply: getFallbackResponse(userMessage) });
}
}
function getFallbackResponse(message: string): string {
if (!message || typeof message !== "string") {
return "I'm having a bit of trouble understanding. Could you try asking again?";
}
const lowerMessage = message.toLowerCase();
if (lowerMessage.includes('skill') || lowerMessage.includes('tech')) {
return "Dennis specializes in full-stack development with Next.js, Flutter for mobile, and DevOps with Docker Swarm. He's passionate about self-hosting and runs his own infrastructure!";
if (
lowerMessage.includes("skill") ||
lowerMessage.includes("tech") ||
lowerMessage.includes("stack")
) {
return "I specialize in full-stack development with Next.js, React, and Flutter for mobile. On the DevOps side, I love working with Docker Swarm, Traefik, and CI/CD pipelines. Basically, if it involves code or servers, I'm interested!";
}
if (lowerMessage.includes('project')) {
return "Dennis has built Clarity (a Flutter app for people with dyslexia) and runs a complete self-hosted infrastructure with Docker Swarm, Traefik, and automated CI/CD pipelines. Check out the Projects section for more!";
if (
lowerMessage.includes("project") ||
lowerMessage.includes("built") ||
lowerMessage.includes("work")
) {
return "One of my key projects is Clarity, a Flutter app designed to help people with dyslexia. I also maintain a comprehensive self-hosted infrastructure with Docker Swarm. You can check out more details in the Projects section!";
}
if (lowerMessage.includes('contact') || lowerMessage.includes('email') || lowerMessage.includes('reach')) {
return "You can reach Dennis via the contact form on this site or email him at contact@dk0.dev. He's always open to discussing new opportunities and interesting projects!";
if (
lowerMessage.includes("contact") ||
lowerMessage.includes("email") ||
lowerMessage.includes("reach") ||
lowerMessage.includes("hire")
) {
return "The best way to reach me is through the contact form below or by emailing contact@dk0.dev. I'm always open to discussing new ideas, opportunities, or just chatting about tech!";
}
if (lowerMessage.includes('location') || lowerMessage.includes('where')) {
return "Dennis is based in Osnabrück, Germany. He's a student who's passionate about technology and self-hosting.";
if (
lowerMessage.includes("location") ||
lowerMessage.includes("where") ||
lowerMessage.includes("live")
) {
return "I'm based in Osnabrück, Germany. It's a great place to be a student and work on tech projects!";
}
if (lowerMessage.includes('hobby') || lowerMessage.includes('free time')) {
return "When Dennis isn't coding or managing servers, he enjoys gaming, jogging, and experimenting with new technologies. He also uses pen and paper for notes despite automating everything else!";
if (
lowerMessage.includes("hobby") ||
lowerMessage.includes("free time") ||
lowerMessage.includes("fun")
) {
return "When I'm not coding or tweaking my servers, I enjoy gaming, going for a jog, or experimenting with new tech. Fun fact: I still use pen and paper for my calendar, even though I automate everything else!";
}
if (lowerMessage.includes('devops') || lowerMessage.includes('docker') || lowerMessage.includes('infrastructure')) {
return "Dennis runs his own infrastructure on IONOS and OVHcloud using Docker Swarm, Traefik for reverse proxy, and custom CI/CD pipelines. He loves self-hosting and managing game servers!";
if (
lowerMessage.includes("devops") ||
lowerMessage.includes("docker") ||
lowerMessage.includes("server") ||
lowerMessage.includes("hosting")
) {
return "I'm really into DevOps! I run my own infrastructure on IONOS and OVHcloud using Docker Swarm and Traefik. It allows me to host various services and game servers efficiently while learning a ton about system administration.";
}
if (lowerMessage.includes('student') || lowerMessage.includes('study')) {
return "Yes, Dennis is currently a student in Osnabrück while also working on various tech projects and managing his own infrastructure. He's always learning and exploring new technologies!";
if (
lowerMessage.includes("student") ||
lowerMessage.includes("study") ||
lowerMessage.includes("education")
) {
return "Yes, I'm currently a student in Osnabrück. I balance my studies with working on personal projects and managing my self-hosted infrastructure. It keeps me busy but I learn something new every day!";
}
if (
lowerMessage.includes("hello") ||
lowerMessage.includes("hi ") ||
lowerMessage.includes("hey")
) {
return "Hi there! I'm Dennis's AI assistant (currently in offline mode). How can I help you learn more about Dennis today?";
}
// Default response
return "That's a great question! Dennis is a full-stack developer and DevOps enthusiast who loves building things with Next.js, Flutter, and Docker. Feel free to ask me more specific questions about his skills, projects, or experience!";
return "That's an interesting question! I'm currently operating in fallback mode, so my knowledge is a bit limited right now. But I can tell you that Dennis is a full-stack developer and DevOps enthusiast who loves building with Next.js and Docker. Feel free to ask about his skills, projects, or how to contact him!";
}

View File

@@ -68,21 +68,24 @@ export async function POST(req: NextRequest) {
}
// Call n8n webhook to trigger AI image generation
const n8nResponse = await fetch(`${n8nWebhookUrl}/ai-image-generation`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(n8nSecretToken && {
Authorization: `Bearer ${n8nSecretToken}`,
const n8nResponse = await fetch(
`${n8nWebhookUrl}/webhook/ai-image-generation`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
...(n8nSecretToken && {
Authorization: `Bearer ${n8nSecretToken}`,
}),
},
body: JSON.stringify({
projectId: projectId,
regenerate: regenerate,
triggeredBy: "api",
timestamp: new Date().toISOString(),
}),
},
body: JSON.stringify({
projectId: projectId,
regenerate: regenerate,
triggeredBy: "api",
timestamp: new Date().toISOString(),
}),
});
);
if (!n8nResponse.ok) {
const errorText = await n8nResponse.text();

View File

@@ -7,14 +7,17 @@ export const revalidate = 30;
export async function GET() {
try {
// Rufe den n8n Webhook auf
const res = await fetch(`${process.env.N8N_WEBHOOK_URL}/denshooter-71242/status`, {
method: "GET",
headers: {
"Content-Type": "application/json",
// Add timestamp to query to bypass Cloudflare cache
const res = await fetch(
`${process.env.N8N_WEBHOOK_URL}/webhook/denshooter-71242/status?t=${Date.now()}`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
},
next: { revalidate: 30 },
},
// Cache-Optionen für Next.js
next: { revalidate: 30 }
});
);
if (!res.ok) {
throw new Error(`n8n error: ${res.status}`);
@@ -25,6 +28,19 @@ export async function GET() {
// n8n gibt oft ein Array zurück: [{...}]. Wir wollen nur das Objekt.
const statusData = Array.isArray(data) ? data[0] : data;
// Safety check: if statusData is still undefined/null (e.g. empty array), use fallback
if (!statusData) {
throw new Error("Empty data received from n8n");
}
// Ensure coding object has proper structure
if (statusData.coding && typeof statusData.coding === "object") {
// Already properly formatted from n8n
} else if (statusData.coding === null || statusData.coding === undefined) {
// No coding data - keep as null
statusData.coding = null;
}
return NextResponse.json(statusData);
} catch (error) {
console.error("Error fetching n8n status:", error);
@@ -33,7 +49,7 @@ export async function GET() {
status: { text: "offline", color: "gray" },
music: null,
gaming: null,
coding: null
coding: null,
});
}
}
}