88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { prisma, projectService } from '@/lib/prisma';
|
|
import { requireSessionAuth } from '@/lib/auth';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const isAdminRequest = request.headers.get('x-admin-request') === 'true';
|
|
if (!isAdminRequest) return NextResponse.json({ error: 'Admin access required' }, { status: 403 });
|
|
const authError = requireSessionAuth(request);
|
|
if (authError) return authError;
|
|
|
|
// Projects (with translations)
|
|
const projectsResult = await projectService.getAllProjects({ limit: 10000 });
|
|
const projects = projectsResult.projects || projectsResult;
|
|
const projectIds = projects.map((p: { id: number }) => p.id);
|
|
|
|
const projectTranslations = await prisma.projectTranslation.findMany({
|
|
where: { projectId: { in: projectIds } },
|
|
orderBy: [{ projectId: 'asc' }, { locale: 'asc' }],
|
|
});
|
|
|
|
// CMS content pages (with translations)
|
|
const contentPages = await prisma.contentPage.findMany({
|
|
orderBy: { key: 'asc' },
|
|
include: {
|
|
translations: {
|
|
orderBy: { locale: 'asc' },
|
|
},
|
|
},
|
|
});
|
|
|
|
const siteSettings = await prisma.siteSettings.findUnique({ where: { id: 1 } });
|
|
|
|
// Format for export
|
|
const exportData = {
|
|
version: '2.0',
|
|
exportDate: new Date().toISOString(),
|
|
siteSettings,
|
|
contentPages,
|
|
projectTranslations,
|
|
projects: projects.map(project => ({
|
|
id: project.id,
|
|
slug: (project as unknown as { slug?: string }).slug,
|
|
defaultLocale: (project as unknown as { defaultLocale?: string }).defaultLocale,
|
|
title: project.title,
|
|
description: project.description,
|
|
content: project.content,
|
|
tags: project.tags,
|
|
category: project.category,
|
|
featured: project.featured,
|
|
github: project.github,
|
|
live: project.live,
|
|
published: project.published,
|
|
imageUrl: project.imageUrl,
|
|
difficulty: project.difficulty,
|
|
timeToComplete: project.timeToComplete,
|
|
technologies: project.technologies,
|
|
challenges: project.challenges,
|
|
lessonsLearned: project.lessonsLearned,
|
|
futureImprovements: project.futureImprovements,
|
|
demoVideo: project.demoVideo,
|
|
screenshots: project.screenshots,
|
|
colorScheme: project.colorScheme,
|
|
accessibility: project.accessibility,
|
|
performance: project.performance,
|
|
analytics: project.analytics,
|
|
createdAt: project.createdAt,
|
|
updatedAt: project.updatedAt
|
|
}))
|
|
};
|
|
|
|
// Return as downloadable JSON file
|
|
return new NextResponse(JSON.stringify(exportData, null, 2), {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Content-Disposition': `attachment; filename="portfolio-projects-${new Date().toISOString().split('T')[0]}.json"`
|
|
}
|
|
});
|
|
} catch (error) {
|
|
console.error('Export error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to export projects' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|