- Add comprehensive database migrations (001-024) for schema evolution - Enhance API schema with expanded type definitions and resolvers - Add new middleware: audit logging, rate limiting, MFA enforcement, security, tenant auth - Implement new services: AI optimization, billing, blockchain, compliance, marketplace - Add adapter layer for cloud integrations (Cloudflare, Kubernetes, Proxmox, storage) - Update Crossplane provider with enhanced VM management capabilities - Add comprehensive test suite for API endpoints and services - Update frontend components with improved GraphQL subscriptions and real-time updates - Enhance security configurations and headers (CSP, CORS, etc.) - Update documentation and configuration files - Add new CI/CD workflows and validation scripts - Implement design system improvements and UI enhancements
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import * as fs from 'fs'
|
|
import * as path from 'path'
|
|
import * as XLSX from 'xlsx'
|
|
|
|
const DATA_DIR = path.join(process.cwd(), 'docs/infrastructure/data')
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const formData = await request.formData()
|
|
const file = formData.get('file') as File
|
|
const targetFile = formData.get('targetFile') as string
|
|
|
|
if (!file || !targetFile) {
|
|
return NextResponse.json(
|
|
{ error: 'File and targetFile are required' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
const buffer = Buffer.from(await file.arrayBuffer())
|
|
const filePath = path.join(DATA_DIR, targetFile)
|
|
|
|
// Handle different file types
|
|
if (file.name.endsWith('.json')) {
|
|
const data = JSON.parse(buffer.toString())
|
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2))
|
|
} else if (file.name.endsWith('.xlsx') || file.name.endsWith('.xls')) {
|
|
const workbook = XLSX.read(buffer, { type: 'buffer' })
|
|
const sheetName = workbook.SheetNames[0]
|
|
const worksheet = workbook.Sheets[sheetName]
|
|
const data = XLSX.utils.sheet_to_json(worksheet)
|
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2))
|
|
} else if (file.name.endsWith('.csv')) {
|
|
const csv = buffer.toString()
|
|
const lines = csv.split('\n')
|
|
const headers = lines[0].split(',').map((h) => h.trim().replace(/^"|"$/g, ''))
|
|
const data = lines.slice(1).map((line) => {
|
|
const values = line.split(',').map((v) => v.trim().replace(/^"|"$/g, ''))
|
|
return headers.reduce((obj, header, idx) => {
|
|
obj[header] = values[idx] || ''
|
|
return obj
|
|
}, {} as Record<string, any>)
|
|
})
|
|
fs.writeFileSync(filePath, JSON.stringify(data, null, 2))
|
|
} else {
|
|
return NextResponse.json({ error: 'Unsupported file type' }, { status: 400 })
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
filename: targetFile,
|
|
records: Array.isArray(JSON.parse(fs.readFileSync(filePath, 'utf-8')))
|
|
? JSON.parse(fs.readFileSync(filePath, 'utf-8')).length
|
|
: 1,
|
|
})
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
error: 'Failed to import file',
|
|
message: error instanceof Error ? error.message : 'Unknown error',
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|