Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

47 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 预览站沙箱守卫中间件
*
* 预览环境中的写入操作在沙箱中执行,不影响真实系统。
* 版权:国作登字-2026-A-00037559
*/
'use strict';
// 沙箱数据库 ID通过环境变量配置Notion 中的独立数据库)
var SANDBOX_DB_IDS = {
ticketBook: process.env.SANDBOX_TICKET_DB_ID || '',
syslogInbox: process.env.SANDBOX_SYSLOG_DB_ID || '',
maintenanceLog: process.env.SANDBOX_MAINTENANCE_DB_ID || ''
};
/**
* 沙箱守卫中间件
*
* 如果开发者在预览环境中执行写入操作:
* - Notion 写入 → 重定向到沙箱数据库
* - GitHub 操作 → 重定向到 preview 分支
* - 所有操作标记 [SANDBOX]
*/
function sandboxGuard(req, res, next) {
if (req.user && req.user.environment === 'preview') {
req.sandbox = true;
req.sandboxDbIds = SANDBOX_DB_IDS;
// 预览环境中禁止正式站部署
if (req.path.includes('/deploy/production')) {
return res.status(403).json({
error: true,
code: 'SANDBOX_BLOCKED',
message: '预览环境不允许正式站部署',
reply: '🏖️ 你目前在预览环境。正式站部署需要升级到 Level 2执行者权限。\n\n继续在预览站练习吧你做得很好'
});
}
}
next();
}
module.exports = {
sandboxGuard: sandboxGuard,
SANDBOX_DB_IDS: SANDBOX_DB_IDS
};