feat: 切换为MariaDB数据库存储

This commit is contained in:
Cuishibing
2026-03-22 22:10:41 +08:00
parent a105f4aecb
commit fbd5f94a43
10 changed files with 346 additions and 299 deletions

View File

@@ -1,17 +1,21 @@
import { NextResponse } from 'next/server';
import fs from 'fs/promises';
import path from 'path';
const DATA_DIR = path.join(process.cwd(), 'data');
const DISTRICTS_FILE = path.join(DATA_DIR, 'districts.json');
import pool from '@/lib/db';
export async function GET() {
let connection;
try {
const data = await fs.readFile(DISTRICTS_FILE, 'utf-8');
const districts = JSON.parse(data);
connection = await pool.getConnection();
const [rows] = await connection.query<any[]>('SELECT name FROM districts ORDER BY sort_order, id');
const districts = rows.map((row: any) => row.name);
connection.release();
return NextResponse.json({ districts });
} catch (error) {
console.error('Get districts error:', error);
return NextResponse.json({ districts: [] });
} finally {
if (connection) connection.release();
}
}