full upgrade to dev
This commit is contained in:
@@ -1,19 +1,115 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { NextResponse } from "next/server";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
export const revalidate = 0;
|
||||
|
||||
export async function GET() {
|
||||
// Mock data - in real integration this would fetch from n8n webhook or database
|
||||
return NextResponse.json({
|
||||
activity: {
|
||||
type: 'coding', // coding, listening, watching
|
||||
details: 'Portfolio Website',
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
music: {
|
||||
isPlaying: true,
|
||||
track: 'Midnight City',
|
||||
artist: 'M83',
|
||||
platform: 'spotify'
|
||||
},
|
||||
watching: null
|
||||
});
|
||||
try {
|
||||
// Fetch from activity_status table
|
||||
const result = await prisma.$queryRawUnsafe<any[]>(
|
||||
`SELECT * FROM activity_status WHERE id = 1 LIMIT 1`,
|
||||
);
|
||||
|
||||
if (!result || result.length === 0) {
|
||||
return NextResponse.json({
|
||||
activity: null,
|
||||
music: null,
|
||||
watching: null,
|
||||
gaming: null,
|
||||
status: null,
|
||||
});
|
||||
}
|
||||
|
||||
const data = result[0];
|
||||
|
||||
// Check if activity is recent (within last 2 hours)
|
||||
const lastUpdate = new Date(data.updated_at);
|
||||
const now = new Date();
|
||||
const hoursSinceUpdate =
|
||||
(now.getTime() - lastUpdate.getTime()) / (1000 * 60 * 60);
|
||||
const isRecent = hoursSinceUpdate < 2;
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
activity:
|
||||
data.activity_type && isRecent
|
||||
? {
|
||||
type: data.activity_type,
|
||||
details: data.activity_details,
|
||||
project: data.activity_project,
|
||||
language: data.activity_language,
|
||||
repo: data.activity_repo,
|
||||
link: data.activity_repo, // Use repo URL as link
|
||||
timestamp: data.updated_at,
|
||||
}
|
||||
: null,
|
||||
|
||||
music: data.music_playing
|
||||
? {
|
||||
isPlaying: data.music_playing,
|
||||
track: data.music_track,
|
||||
artist: data.music_artist,
|
||||
album: data.music_album,
|
||||
platform: data.music_platform || "spotify",
|
||||
progress: data.music_progress,
|
||||
albumArt: data.music_album_art,
|
||||
spotifyUrl: data.music_track
|
||||
? `https://open.spotify.com/search/${encodeURIComponent(data.music_track + " " + data.music_artist)}`
|
||||
: null,
|
||||
}
|
||||
: null,
|
||||
|
||||
watching: data.watching_title
|
||||
? {
|
||||
title: data.watching_title,
|
||||
platform: data.watching_platform || "youtube",
|
||||
type: data.watching_type || "video",
|
||||
}
|
||||
: null,
|
||||
|
||||
gaming: data.gaming_game
|
||||
? {
|
||||
game: data.gaming_game,
|
||||
platform: data.gaming_platform || "steam",
|
||||
status: data.gaming_status || "playing",
|
||||
}
|
||||
: null,
|
||||
|
||||
status: data.status_mood
|
||||
? {
|
||||
mood: data.status_mood,
|
||||
customMessage: data.status_message,
|
||||
}
|
||||
: null,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
|
||||
Pragma: "no-cache",
|
||||
},
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error fetching activity status:", error);
|
||||
|
||||
// Return empty state on error (graceful degradation)
|
||||
return NextResponse.json(
|
||||
{
|
||||
activity: null,
|
||||
music: null,
|
||||
watching: null,
|
||||
gaming: null,
|
||||
status: null,
|
||||
},
|
||||
{
|
||||
status: 200, // Return 200 to prevent frontend errors
|
||||
headers: {
|
||||
"Cache-Control": "no-store, no-cache, must-revalidate, max-age=0",
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user