✅ Updated Middleware Logic: - Enhanced admin route protection with Basic Auth for legacy routes and session-based auth for `/manage` and `/editor`. ✅ Improved Admin Panel Styles: - Added glassmorphism styles for admin components to enhance UI aesthetics. ✅ Refined Rate Limiting: - Adjusted rate limits for admin dashboard requests to allow more generous access. ✅ Introduced Analytics Reset API: - Added a new endpoint for resetting analytics data with rate limiting and admin authentication. 🎯 Overall Improvements: - Strengthened security and user experience for admin functionalities. - Enhanced visual design for better usability. - Streamlined analytics management processes.
90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { projectService } from '@/lib/prisma';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
|
|
// Validate import data structure
|
|
if (!body.projects || !Array.isArray(body.projects)) {
|
|
return NextResponse.json(
|
|
{ error: 'Invalid import data format' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const results = {
|
|
imported: 0,
|
|
skipped: 0,
|
|
errors: [] as string[]
|
|
};
|
|
|
|
// Process each project
|
|
for (const projectData of body.projects) {
|
|
try {
|
|
// Check if project already exists (by title)
|
|
const existingProjectsResult = await projectService.getAllProjects();
|
|
const existingProjects = existingProjectsResult.projects || existingProjectsResult;
|
|
const exists = existingProjects.some(p => p.title === projectData.title);
|
|
|
|
if (exists) {
|
|
results.skipped++;
|
|
results.errors.push(`Project "${projectData.title}" already exists`);
|
|
continue;
|
|
}
|
|
|
|
// Create new project
|
|
await projectService.createProject({
|
|
title: projectData.title,
|
|
description: projectData.description,
|
|
content: projectData.content,
|
|
tags: projectData.tags || [],
|
|
category: projectData.category,
|
|
featured: projectData.featured || false,
|
|
github: projectData.github,
|
|
live: projectData.live,
|
|
published: projectData.published !== false, // Default to true
|
|
imageUrl: projectData.imageUrl,
|
|
difficulty: projectData.difficulty || 'Intermediate',
|
|
timeToComplete: projectData.timeToComplete,
|
|
technologies: projectData.technologies || [],
|
|
challenges: projectData.challenges || [],
|
|
lessonsLearned: projectData.lessonsLearned || [],
|
|
futureImprovements: projectData.futureImprovements || [],
|
|
demoVideo: projectData.demoVideo,
|
|
screenshots: projectData.screenshots || [],
|
|
colorScheme: projectData.colorScheme || 'Dark',
|
|
accessibility: projectData.accessibility !== false, // Default to true
|
|
performance: projectData.performance || {
|
|
lighthouse: 0,
|
|
bundleSize: '0KB',
|
|
loadTime: '0s'
|
|
},
|
|
analytics: projectData.analytics || {
|
|
views: 0,
|
|
likes: 0,
|
|
shares: 0
|
|
}
|
|
});
|
|
|
|
results.imported++;
|
|
} catch (error) {
|
|
results.skipped++;
|
|
results.errors.push(`Failed to import "${projectData.title}": ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: `Import completed: ${results.imported} imported, ${results.skipped} skipped`,
|
|
results
|
|
});
|
|
} catch (error) {
|
|
console.error('Import error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to import projects' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|