feat: add map-password API with DB model and admin endpoint

This commit is contained in:
2026-05-24 16:32:15 +08:00
parent 2c0d6ba2eb
commit cd9fb924d5
7 changed files with 1335 additions and 3 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -280,3 +280,31 @@ model DeviceBinding {
@@unique([userId, installId])
@@map("device_bindings")
}
// ============================================
// 地图密码批次表
// ============================================
model MapPassword {
id String @id @default(uuid())
createdAt DateTime @default(now()) @map("created_at")
maps MapPasswordItem[]
@@map("map_passwords")
}
// ============================================
// 地图密码明细表
// ============================================
model MapPasswordItem {
id String @id @default(uuid())
batchId String @map("batch_id")
mapName String @map("map_name") @db.VarChar(50)
password String @db.VarChar(20)
location String @db.Text
image String @db.VarChar(500)
batch MapPassword @relation(fields: [batchId], references: [id], onDelete: Cascade)
@@map("map_password_items")
}

View File

@@ -158,9 +158,30 @@ app.get('/api/software-version-ad', (req, res) => {
res.json({ success: true, data: { items: [] } });
});
// 游戏地图密码缓存
app.get('/api/game/map-password/cached', (req, res) => {
res.json({ success: true, data: [] });
// 游戏地图密码缓存(对齐 maqt.top 格式)
app.get('/api/game/map-password/cached', async (_req, res) => {
try {
// 从 DB 取最新一批地图密码
const latest = await prisma.mapPassword.findFirst({
orderBy: { createdAt: 'desc' },
include: { maps: { select: { mapName: true, password: true, location: true, image: true } } },
});
if (latest) {
const d = new Date(latest.createdAt);
res.json({
success: true,
data: {
maps: latest.maps,
updateTime: `${String(d.getDate()).padStart(2,'0')}${String(d.getMonth()+1).padStart(2,'0')}`,
},
});
} else {
// 默认空数据
res.json({ success: true, data: { maps: [], updateTime: '' } });
}
} catch {
res.json({ success: true, data: { maps: [], updateTime: '' } });
}
});
// 筛选分类
@@ -360,6 +381,37 @@ app.post('/api/admin/set-vip', async (req, res) => {
}
});
// 管理员更新地图密码
app.post('/api/admin/map-passwords', async (req, res) => {
const secret = process.env.ADMIN_SECRET;
if (!secret || req.headers['x-admin-secret'] !== secret) {
return res.status(403).json({ success: false, message: '禁止访问' });
}
try {
const { maps } = req.body;
if (!Array.isArray(maps) || maps.length === 0) {
return res.status(400).json({ success: false, message: '缺少 maps 数组' });
}
const batch = await prisma.mapPassword.create({
data: {
maps: {
create: maps.map((m: any) => ({
mapName: m.mapName,
password: m.password,
location: m.location || '',
image: m.image || '',
})),
},
},
include: { maps: true },
});
res.json({ success: true, data: batch });
} catch (e: any) {
console.error('Admin map-password error:', e);
res.status(500).json({ success: false, message: '更新失败: ' + e.message });
}
});
// ============================================
// 错误处理
// ============================================