- 创建 security_manager.py 安全模块
- SecurityManager: 安全管理主类
- 审计日志系统 - 记录所有数据操作
- 端到端加密 - AES-256-GCM 加密项目数据
- 数据脱敏 - 支持手机号、邮箱、身份证等敏感信息脱敏
- 数据访问策略 - 基于用户、角色、IP、时间的访问控制
- 访问审批流程 - 敏感数据访问需要审批
- 更新 schema.sql 添加安全相关数据库表
- audit_logs: 审计日志表
- encryption_configs: 加密配置表
- masking_rules: 脱敏规则表
- data_access_policies: 数据访问策略表
- access_requests: 访问请求表
- 更新 main.py 添加安全相关 API 端点
- GET /api/v1/audit-logs - 查询审计日志
- GET /api/v1/audit-logs/stats - 审计统计
- POST /api/v1/projects/{id}/encryption/enable - 启用加密
- POST /api/v1/projects/{id}/encryption/disable - 禁用加密
- POST /api/v1/projects/{id}/encryption/verify - 验证密码
- GET /api/v1/projects/{id}/encryption - 获取加密配置
- POST /api/v1/projects/{id}/masking-rules - 创建脱敏规则
- GET /api/v1/projects/{id}/masking-rules - 获取脱敏规则
- PUT /api/v1/masking-rules/{id} - 更新脱敏规则
- DELETE /api/v1/masking-rules/{id} - 删除脱敏规则
- POST /api/v1/projects/{id}/masking/apply - 应用脱敏
- POST /api/v1/projects/{id}/access-policies - 创建访问策略
- GET /api/v1/projects/{id}/access-policies - 获取访问策略
- POST /api/v1/access-policies/{id}/check - 检查访问权限
- POST /api/v1/access-requests - 创建访问请求
- POST /api/v1/access-requests/{id}/approve - 批准访问
- POST /api/v1/access-requests/{id}/reject - 拒绝访问
- 更新 requirements.txt 添加 cryptography 依赖
- 更新 STATUS.md 和 README.md 记录完成状态
154 lines
4.6 KiB
JavaScript
154 lines
4.6 KiB
JavaScript
// InsightFlow Chrome Extension - Popup Script
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
// 获取当前标签页信息
|
|
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
|
|
// 更新页面信息
|
|
document.getElementById('pageTitle').textContent = tab.title || '未知标题';
|
|
document.getElementById('pageUrl').textContent = tab.url || '';
|
|
|
|
// 获取页面统计
|
|
updateStats();
|
|
|
|
// 加载最近的剪辑
|
|
loadRecentClips();
|
|
|
|
// 绑定按钮事件
|
|
document.getElementById('clipPageBtn').addEventListener('click', clipPage);
|
|
document.getElementById('clipSelectionBtn').addEventListener('click', clipSelection);
|
|
document.getElementById('openOptions').addEventListener('click', openOptions);
|
|
});
|
|
|
|
// 更新统计信息
|
|
async function updateStats() {
|
|
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
|
|
// 获取字数统计
|
|
try {
|
|
const response = await chrome.tabs.sendMessage(tab.id, { action: 'extractContent' });
|
|
if (response.success) {
|
|
document.getElementById('wordCount').textContent = response.data.wordCount || 0;
|
|
}
|
|
} catch (error) {
|
|
console.log('Content script not available');
|
|
}
|
|
|
|
// 获取待同步数量
|
|
const result = await chrome.storage.local.get(['clips']);
|
|
const clips = result.clips || [];
|
|
const pendingCount = clips.filter(c => !c.synced).length;
|
|
document.getElementById('pendingCount').textContent = pendingCount;
|
|
}
|
|
|
|
// 保存整个页面
|
|
async function clipPage() {
|
|
setLoading(true);
|
|
|
|
try {
|
|
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
|
|
// 发送消息给 background script
|
|
const response = await chrome.runtime.sendMessage({ action: 'clipPage' });
|
|
|
|
if (response.success) {
|
|
showStatus('页面已保存!', 'success');
|
|
loadRecentClips();
|
|
updateStats();
|
|
} else {
|
|
showStatus(response.error || '保存失败', 'error');
|
|
}
|
|
} catch (error) {
|
|
showStatus('保存失败: ' + error.message, 'error');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
// 保存选中内容
|
|
async function clipSelection() {
|
|
setLoading(true);
|
|
|
|
try {
|
|
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
|
|
|
const response = await chrome.runtime.sendMessage({ action: 'clipSelection' });
|
|
|
|
if (response.success) {
|
|
showStatus('选中内容已保存!', 'success');
|
|
loadRecentClips();
|
|
updateStats();
|
|
} else {
|
|
showStatus(response.error || '保存失败', 'error');
|
|
}
|
|
} catch (error) {
|
|
showStatus('保存失败: ' + error.message, 'error');
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}
|
|
|
|
// 加载最近的剪辑
|
|
async function loadRecentClips() {
|
|
const result = await chrome.storage.local.get(['clips']);
|
|
const clips = result.clips || [];
|
|
|
|
const clipsList = document.getElementById('clipsList');
|
|
clipsList.innerHTML = '';
|
|
|
|
// 只显示最近5条
|
|
const recentClips = clips.slice(0, 5);
|
|
|
|
for (const clip of recentClips) {
|
|
const clipEl = document.createElement('div');
|
|
clipEl.className = 'clip-item';
|
|
|
|
const title = clip.title || '未命名';
|
|
const time = new Date(clip.extractedAt).toLocaleString('zh-CN');
|
|
const statusClass = clip.synced ? 'synced' : 'pending';
|
|
const statusText = clip.synced ? '已同步' : '待同步';
|
|
|
|
clipEl.innerHTML = `
|
|
<div class="clip-title">${escapeHtml(title)}</div>
|
|
<div class="clip-time">${time}</div>
|
|
<span class="clip-status ${statusClass}">${statusText}</span>
|
|
`;
|
|
|
|
clipsList.appendChild(clipEl);
|
|
}
|
|
}
|
|
|
|
// 打开设置页面
|
|
function openOptions(e) {
|
|
e.preventDefault();
|
|
chrome.runtime.openOptionsPage();
|
|
}
|
|
|
|
// 显示状态消息
|
|
function showStatus(message, type) {
|
|
const statusEl = document.getElementById('status');
|
|
statusEl.textContent = message;
|
|
statusEl.className = 'status ' + type;
|
|
|
|
setTimeout(() => {
|
|
statusEl.textContent = '';
|
|
statusEl.className = 'status';
|
|
}, 3000);
|
|
}
|
|
|
|
// 设置加载状态
|
|
function setLoading(loading) {
|
|
const loadingEl = document.getElementById('loading');
|
|
if (loading) {
|
|
loadingEl.classList.add('active');
|
|
} else {
|
|
loadingEl.classList.remove('active');
|
|
}
|
|
}
|
|
|
|
// HTML 转义
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
} |