新增頭像圖片上傳

This commit is contained in:
2025-09-21 22:11:20 +08:00
parent 38ae30d611
commit 59d22966c2
22 changed files with 1904 additions and 1437 deletions

View File

@@ -1,76 +0,0 @@
// =====================================================
// 調試競賽數據 API
// =====================================================
import { NextRequest, NextResponse } from 'next/server';
import { DatabaseServiceBase } from '@/lib/services/database-service';
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const competitionId = searchParams.get('competitionId') || '07e2303e-9647-11f0-b5d9-6e36c63cdb98';
console.log('🔍 開始調試競賽數據...');
console.log('競賽ID:', competitionId);
// 1. 檢查競賽是否存在
const competitionCheck = await DatabaseServiceBase.safeQuery(
'SELECT * FROM competitions WHERE id = ?',
[competitionId]
);
console.log('📊 競賽檢查結果:', competitionCheck);
// 2. 檢查競賽應用關聯
const competitionAppsCheck = await DatabaseServiceBase.safeQuery(
'SELECT * FROM competition_apps WHERE competition_id = ?',
[competitionId]
);
console.log('📊 競賽應用關聯檢查結果:', competitionAppsCheck);
// 3. 檢查所有應用程式
const allAppsCheck = await DatabaseServiceBase.safeQuery(
'SELECT id, name, is_active FROM apps WHERE is_active = 1 LIMIT 10',
[]
);
console.log('📊 所有應用程式檢查結果:', allAppsCheck);
// 4. 檢查競賽規則
const competitionRulesCheck = await DatabaseServiceBase.safeQuery(
'SELECT * FROM competition_rules WHERE competition_id = ?',
[competitionId]
);
console.log('📊 競賽規則檢查結果:', competitionRulesCheck);
// 5. 檢查評審
const judgesCheck = await DatabaseServiceBase.safeQuery(
'SELECT id, name, title, department FROM judges WHERE is_active = 1 LIMIT 5',
[]
);
console.log('📊 評審檢查結果:', judgesCheck);
return NextResponse.json({
success: true,
message: '調試數據獲取成功',
data: {
competition: competitionCheck,
competitionApps: competitionAppsCheck,
allApps: allAppsCheck,
competitionRules: competitionRulesCheck,
judges: judgesCheck
}
});
} catch (error) {
console.error('❌ 調試競賽數據失敗:', error);
return NextResponse.json({
success: false,
message: '調試競賽數據失敗',
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}

View File

@@ -1,66 +0,0 @@
// =====================================================
// 強制清理連線 API
// =====================================================
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/database';
import { connectionMonitor } from '@/lib/connection-monitor';
export async function POST(request: NextRequest) {
try {
console.log('🧹 開始強制清理資料庫連線...');
// 獲取清理前的連線狀態
const beforeStats = await connectionMonitor.getConnectionStats();
console.log(`清理前連線數: ${beforeStats.activeConnections}`);
// 強制關閉連線池
try {
await db.close();
console.log('✅ 主要資料庫連線池已關閉');
} catch (error) {
console.error('❌ 關閉主要連線池失敗:', error);
}
// 等待一段時間讓連線完全關閉
await new Promise(resolve => setTimeout(resolve, 2000));
// 重新初始化連線池
try {
// 重新創建連線池實例
const { Database } = await import('@/lib/database');
const newDb = Database.getInstance();
console.log('✅ 資料庫連線池已重新初始化');
} catch (error) {
console.error('❌ 重新初始化連線池失敗:', error);
}
// 獲取清理後的連線狀態
const afterStats = await connectionMonitor.getConnectionStats();
console.log(`清理後連線數: ${afterStats.activeConnections}`);
return NextResponse.json({
success: true,
message: '強制清理完成',
data: {
before: {
activeConnections: beforeStats.activeConnections,
usagePercentage: beforeStats.usagePercentage
},
after: {
activeConnections: afterStats.activeConnections,
usagePercentage: afterStats.usagePercentage
},
cleaned: beforeStats.activeConnections - afterStats.activeConnections
}
});
} catch (error) {
console.error('強制清理失敗:', error);
return NextResponse.json({
success: false,
message: '強制清理失敗',
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}

View File

@@ -1,70 +0,0 @@
// =====================================================
// 強制終止連線 API
// =====================================================
import { NextRequest, NextResponse } from 'next/server';
import { db } from '@/lib/database';
export async function POST(request: NextRequest) {
try {
console.log('💀 開始強制終止所有資料庫連線...');
// 獲取所有 AI_Platform 的連線
const connections = await db.query(`
SELECT ID, USER, HOST, DB, COMMAND, TIME, STATE
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE USER = 'AI_Platform' AND DB = 'db_AI_Platform'
`);
console.log(`找到 ${connections.length} 個 AI_Platform 連線`);
const killedConnections = [];
// 終止每個連線
for (const conn of connections) {
try {
await db.query(`KILL CONNECTION ${conn.ID}`);
killedConnections.push({
id: conn.ID,
host: conn.HOST,
time: conn.TIME,
command: conn.COMMAND
});
console.log(`✅ 已終止連線 ${conn.ID} (閒置 ${conn.TIME} 秒)`);
} catch (error) {
console.error(`❌ 終止連線 ${conn.ID} 失敗:`, error);
}
}
// 等待連線完全關閉
await new Promise(resolve => setTimeout(resolve, 2000));
// 檢查剩餘連線
const remainingConnections = await db.query(`
SELECT COUNT(*) as count
FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE USER = 'AI_Platform' AND DB = 'db_AI_Platform'
`);
const remainingCount = remainingConnections[0]?.count || 0;
return NextResponse.json({
success: true,
message: '強制終止連線完成',
data: {
totalFound: connections.length,
killed: killedConnections.length,
remaining: remainingCount,
killedConnections: killedConnections
}
});
} catch (error) {
console.error('強制終止連線失敗:', error);
return NextResponse.json({
success: false,
message: '強制終止連線失敗',
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}