feat(api): implement read-only mode for reviewers controlled by REVIEWER_READ_ONLY env

This commit is contained in:
yiling
2026-06-17 21:51:34 +08:00
parent 438ea79535
commit ead91455d8
2 changed files with 128 additions and 0 deletions
+17
View File
@@ -28,6 +28,23 @@ export const authMiddleware = createMiddleware<{
}
c.set('user', user)
if (process.env.REVIEWER_READ_ONLY === '1') {
const method = c.req.method.toUpperCase()
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
const member = await prisma.teamMember.findFirst({
where: {
userId: user.id,
role: { in: ['owner', 'editor'] },
},
})
if (!member) {
return c.json({ error: 'System is in read-only mode' }, 403)
}
}
}
await next()
} catch {
return c.json({ error: 'Authentication failed' }, 401)