update
This commit is contained in:
@@ -5,6 +5,7 @@ const DEFAULT_FOCUS_SEQUENCE = ["quickCommandsSearch", "commandHistorySearch", "
|
||||
const FOCUS_SEQUENCE_KEY = 'focusSwitcherSequence'; // 焦点切换顺序设置键
|
||||
const NAV_BAR_VISIBLE_KEY = 'navBarVisible'; // 导航栏可见性设置键
|
||||
const LAYOUT_TREE_KEY = 'layoutTree'; // 布局树设置键
|
||||
const AUTO_COPY_ON_SELECT_KEY = 'autoCopyOnSelect'; // 终端选中自动复制设置键
|
||||
|
||||
export const settingsService = {
|
||||
/**
|
||||
@@ -204,5 +205,40 @@ export const settingsService = {
|
||||
console.error(`[Service] Error calling settingsRepository.setSetting for key ${LAYOUT_TREE_KEY}:`, error);
|
||||
throw new Error('Failed to save layout tree setting.');
|
||||
}
|
||||
}, // *** 确保这里有逗号 ***
|
||||
|
||||
/**
|
||||
* 获取终端选中自动复制设置
|
||||
* @returns 返回是否启用该功能 (boolean),如果未设置则默认为 false
|
||||
*/
|
||||
async getAutoCopyOnSelect(): Promise<boolean> {
|
||||
console.log(`[Service] Attempting to get setting for key: ${AUTO_COPY_ON_SELECT_KEY}`);
|
||||
try {
|
||||
const enabledStr = await settingsRepository.getSetting(AUTO_COPY_ON_SELECT_KEY);
|
||||
console.log(`[Service] Raw value from repository for ${AUTO_COPY_ON_SELECT_KEY}:`, enabledStr);
|
||||
// 如果设置存在且值为 'true',则返回 true,否则都返回 false (包括未设置或值为 'false' 的情况)
|
||||
return enabledStr === 'true';
|
||||
} catch (error) {
|
||||
console.error(`[Service] Error getting auto copy on select setting (key: ${AUTO_COPY_ON_SELECT_KEY}):`, error);
|
||||
// 出错时返回默认值 false
|
||||
return false;
|
||||
}
|
||||
}, // *** 确保这里有逗号 ***
|
||||
|
||||
/**
|
||||
* 设置终端选中自动复制
|
||||
* @param enabled 是否启用 (boolean)
|
||||
*/
|
||||
async setAutoCopyOnSelect(enabled: boolean): Promise<void> {
|
||||
console.log(`[Service] setAutoCopyOnSelect called with: ${enabled}`);
|
||||
try {
|
||||
const enabledStr = String(enabled); // 将布尔值转换为 'true' 或 'false'
|
||||
console.log(`[Service] Attempting to save setting. Key: ${AUTO_COPY_ON_SELECT_KEY}, Value: ${enabledStr}`);
|
||||
await settingsRepository.setSetting(AUTO_COPY_ON_SELECT_KEY, enabledStr);
|
||||
console.log(`[Service] Successfully saved setting for key: ${AUTO_COPY_ON_SELECT_KEY}`);
|
||||
} catch (error) {
|
||||
console.error(`[Service] Error calling settingsRepository.setSetting for key ${AUTO_COPY_ON_SELECT_KEY}:`, error);
|
||||
throw new Error('Failed to save auto copy on select setting.');
|
||||
}
|
||||
} // *** 最后的方法后面不需要逗号 ***
|
||||
};
|
||||
|
||||
@@ -32,7 +32,8 @@ export const settingsController = {
|
||||
|
||||
const allowedSettingsKeys = [
|
||||
'language', 'ipWhitelist', 'maxLoginAttempts', 'loginBanDuration',
|
||||
'showPopupFileEditor', 'shareFileEditorTabs', 'ipWhitelistEnabled'
|
||||
'showPopupFileEditor', 'shareFileEditorTabs', 'ipWhitelistEnabled',
|
||||
'autoCopyOnSelect' // +++ 添加新设置键 +++
|
||||
];
|
||||
const filteredSettings: Record<string, string> = {};
|
||||
for (const key in settingsToUpdate) {
|
||||
@@ -245,5 +246,49 @@ export const settingsController = {
|
||||
console.error(`从 IP 黑名单删除 ${req.params.ip} 时出错:`, error);
|
||||
res.status(500).json({ message: '从 IP 黑名单删除失败', error: error.message });
|
||||
}
|
||||
}
|
||||
}, // *** 确保这里有逗号 ***
|
||||
|
||||
/**
|
||||
* 获取终端选中自动复制设置
|
||||
*/
|
||||
async getAutoCopyOnSelect(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
console.log('[Controller] Received request to get auto copy on select setting.');
|
||||
const isEnabled = await settingsService.getAutoCopyOnSelect();
|
||||
console.log(`[Controller] Sending auto copy on select setting to client: ${isEnabled}`);
|
||||
res.json({ enabled: isEnabled });
|
||||
} catch (error: any) {
|
||||
console.error('[Controller] 获取终端选中自动复制设置时出错:', error);
|
||||
res.status(500).json({ message: '获取终端选中自动复制设置失败', error: error.message });
|
||||
}
|
||||
}, // *** 确保这里有逗号 ***
|
||||
|
||||
/**
|
||||
* 设置终端选中自动复制
|
||||
*/
|
||||
async setAutoCopyOnSelect(req: Request, res: Response): Promise<void> {
|
||||
console.log('[Controller] Received request to set auto copy on select setting.');
|
||||
try {
|
||||
const { enabled } = req.body;
|
||||
console.log('[Controller] Request body enabled:', enabled);
|
||||
|
||||
if (typeof enabled !== 'boolean') {
|
||||
console.warn('[Controller] Invalid enabled format received:', enabled);
|
||||
res.status(400).json({ message: '无效的请求体,"enabled" 必须是一个布尔值' });
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[Controller] Calling settingsService.setAutoCopyOnSelect...');
|
||||
await settingsService.setAutoCopyOnSelect(enabled);
|
||||
console.log('[Controller] settingsService.setAutoCopyOnSelect completed successfully.');
|
||||
|
||||
// auditLogService.logAction('AUTO_COPY_ON_SELECT_UPDATED', { enabled }); // 可选:添加审计日志
|
||||
|
||||
console.log('[Controller] Sending success response.');
|
||||
res.status(200).json({ message: '终端选中自动复制设置已成功更新' });
|
||||
} catch (error: any) {
|
||||
console.error('[Controller] 设置终端选中自动复制时出错:', error);
|
||||
res.status(500).json({ message: '设置终端选中自动复制失败', error: error.message });
|
||||
}
|
||||
} // *** 最后的方法后面不需要逗号 ***
|
||||
};
|
||||
|
||||
@@ -37,4 +37,10 @@ router.get('/ip-blacklist', settingsController.getIpBlacklist);
|
||||
router.delete('/ip-blacklist/:ip', settingsController.deleteIpFromBlacklist);
|
||||
|
||||
|
||||
// +++ 新增:终端选中自动复制路由 +++
|
||||
// GET /api/v1/settings/auto-copy-on-select - 获取设置
|
||||
router.get('/auto-copy-on-select', settingsController.getAutoCopyOnSelect);
|
||||
// PUT /api/v1/settings/auto-copy-on-select - 更新设置
|
||||
router.put('/auto-copy-on-select', settingsController.setAutoCopyOnSelect);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user