@haitang-hub/lingyu-island 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -21
- package/assets/icon.png +0 -0
- package/assets/logo-source.jpg +0 -0
- package/assets/tray-macTemplate.png +0 -0
- package/assets/tray-macTemplate@2x.png +0 -0
- package/assets/tray.png +0 -0
- package/assets/tray@2x.png +0 -0
- package/package.json +48 -7
- package/scripts/gen-logo.js +102 -0
- package/scripts/set-root.js +1 -1
- package/src/core/detector.js +4 -4
- package/src/core/fileproc.js +16 -16
- package/src/core/imports.js +1 -1
- package/src/core/masker.js +2 -2
- package/src/main/importer.js +4 -4
- package/src/main/ipc.js +4 -4
- package/src/main/island.js +41 -9
- package/src/main/main.js +2 -2
- package/src/main/store.js +32 -1
- package/src/main/tray.js +1 -1
- package/src/renderer/mock.js +6 -6
- package/src/renderer/panel.css +1 -1
- package/src/renderer/panel.html +14 -14
- package/src/renderer/panel.js +10 -10
- package/src/renderer/pill.css +3 -3
- package/src/renderer/pill.html +4 -4
- package/src/renderer/pill.js +7 -7
- package/test/e2e.js +24 -24
- package/test/real-files.test.js +17 -17
- package/test/run-tests.js +29 -29
- package//345/220/257/345/212/250/347/201/265/345/261/{277.bat → 277/345/262/233.bat} +2 -2
- package//345/220/257/345/212/250/347/201/265/345/261/{277.command → 277/345/262/233.command} +3 -3
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 灵屿岛
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
一款「灵动岛」风格的桌面文件屏蔽工具:把文件拖到屏幕顶部的胶囊上,自动识别内容并生成屏蔽副本或还原副本;屏蔽值内嵌还原编码,**只要编码未被改动(哪怕从文件里复制出来),随时可一键还原真实内容**。
|
|
4
4
|
|
|
5
|
-
>
|
|
5
|
+
> 隐私设计原则:**性别、年龄、出生日期等依法用于判断的信息不作为敏感信息,不会屏蔽**;身份证号属于个人身份标识,仍会屏蔽(屏蔽后保留首尾特征,可判断内容类型)。
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
|
|
11
11
|
| 功能 | 说明 |
|
|
12
12
|
| --- | --- |
|
|
13
|
-
| 拖入即处理 | 拖文件/文件夹到屏幕顶部胶囊,**按内容自动判断**:明文 → 生成 `文件名_
|
|
13
|
+
| 拖入即处理 | 拖文件/文件夹到屏幕顶部胶囊,**按内容自动判断**:明文 → 生成 `文件名_屏蔽.ext`,含〔编码〕的屏蔽文件 → 生成 `文件名_还原.ext`;**直接读取源文件,只在根目录写出结果,不生成原文件副本**,原位置的文件不会被改动(可在设置中改为处理后移入回收站);结果文件同名时可选保留两份或覆盖,完成后胶囊与面板都会给出结果提示 |
|
|
14
14
|
| 可还原的屏蔽 | 屏蔽形如 `138****5678〔a3f2b1〕`:保留首尾特征可判断内容,`〔〕`内编码是还原钥匙 |
|
|
15
|
-
| 随时还原 |
|
|
16
|
-
| 剪贴板恢复 |
|
|
15
|
+
| 随时还原 | 把屏蔽文件重新拖入即可自动生成 `文件名_还原.ext`;粘贴任意含编码的文本可实时还原 |
|
|
16
|
+
| 剪贴板恢复 | 复制了含编码的内容时,胶囊提示「识别到含屏蔽信息」,点右侧「还原文本」按钮才还原并写回剪贴板;仅对当前复制的那段文本生效,剪贴板换成别的内容后提示自动失效 |
|
|
17
17
|
| 编码防篡改 | 编码被改动时明确提示无法还原,绝不输出错误内容 |
|
|
18
18
|
| 快速查找 | 配置根目录后自动建索引、监听变更,秒搜根目录下所有文件;可按「全部/文档/表格/文本/代码/其他」筛选(按钮上的数字为该类别命中数),结果可打开或在文件夹中定位 |
|
|
19
19
|
| 全类型支持 | 文本类(txt/md/csv/json/代码等,UTF-8/GBK 自动识别)+ Office(docx/xlsx/pptx) |
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
- ✅ 中文姓名(**语境驱动**:角色标签「原告/被告/第三人/代理人/负责人/审判长…」、称呼、`,男|女` 结构、职业前缀「村医/村委/米婆…」、强敏感信息邻近)
|
|
25
25
|
- ✅ 姓名传播:同一文档内首次锚定后,后文只出现名字也会命中;同一批次(如整套卷宗)内跨文件传播
|
|
26
26
|
- ✅ 家庭住址(保守组合模式)、护照号、车牌号
|
|
27
|
-
- ❌
|
|
28
|
-
- ❌
|
|
29
|
-
- ❌ 误报控制:无语境的姓名(如"今天上午和张伟开会"
|
|
27
|
+
- ❌ **不屏蔽**:性别、年龄、出生日期、民族(依法判断需要的数据)
|
|
28
|
+
- ❌ **不按姓名屏蔽**:机构名与地名(「广东雷阳律师事务所」「雷州市北和镇…村民委员会」「广东省雷州市」),避免把 `雷州市` 误切成 `雷*市`
|
|
29
|
+
- ❌ 误报控制:无语境的姓名(如"今天上午和张伟开会")不会误屏蔽;姓名后必须是标点/连词/常见谓语,`安排于`、`关于主体`、`文字经` 这类普通词不再被当成名字
|
|
30
30
|
|
|
31
31
|
## 运行
|
|
32
32
|
|
|
@@ -36,8 +36,8 @@ npm start # 启动灵动岛
|
|
|
36
36
|
npm test # 核心引擎单元测试(22 项)
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
- **Windows**:双击 [
|
|
40
|
-
- **macOS**:首次执行 `chmod +x
|
|
39
|
+
- **Windows**:双击 [启动灵屿岛.bat](启动灵屿岛.bat)
|
|
40
|
+
- **macOS**:首次执行 `chmod +x 启动灵屿岛.command`,之后双击即可(或 `npm start`)
|
|
41
41
|
|
|
42
42
|
**启动脚本**直接调用 Electron 运行时,不经过 npm。首次使用前需 `npm install`(Electron 下载慢可设镜像:`ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ npm install`)。
|
|
43
43
|
|
|
@@ -53,25 +53,25 @@ npm test # 核心引擎单元测试(22 项)
|
|
|
53
53
|
| 根目录监听 | fs.watch 递归 | 同左(Node ≥19 支持;异常时自动降级为手动重建索引) |
|
|
54
54
|
| 开机自启 | 登录项直接生效 | 开发模式下可能需在「系统设置 → 登录项」确认 |
|
|
55
55
|
|
|
56
|
-
**真实文书测试**:`node test/real-files.test.js` —— 自动从样本目录同步文件到 `test/realtest` 做全量校验:原件 SHA-256
|
|
56
|
+
**真实文书测试**:`node test/real-files.test.js` —— 自动从样本目录同步文件到 `test/realtest` 做全量校验:原件 SHA-256 不变、屏蔽无泄露、还原逐字节一致、性别/年龄/出生日期保留(161 项检查)。样本目录默认为 `F:\Law\output\Chuanjianling`(Windows),macOS 用环境变量指定:`LINGYU_SAMPLES=/path/to/docs node test/real-files.test.js`。测试产物(`_屏蔽`/`_还原` 副本)保留在 `test/realtest` 供查看效果。
|
|
57
57
|
|
|
58
58
|
- 首次使用:点击胶囊展开面板 → 「设置」→ 选择**文件根目录**(用于快速查找)
|
|
59
|
-
- 日常使用:拖文件到胶囊 →
|
|
59
|
+
- 日常使用:拖文件到胶囊 → 自动识别并屏蔽/还原;点胶囊展开「概览」查看记录
|
|
60
60
|
- 托盘图标:显示/隐藏灵动岛、开机自启、退出
|
|
61
61
|
|
|
62
62
|
## 使用说明
|
|
63
63
|
|
|
64
|
-
1. **智能处理**:拖入文件 → 自动识别内容;明文生成 `文件名_
|
|
65
|
-
2.
|
|
66
|
-
3. **还原文本**:从文件里复制了被屏蔽的内容 →
|
|
64
|
+
1. **智能处理**:拖入文件 → 自动识别内容;明文生成 `文件名_屏蔽.ext`,含屏蔽编码的文件生成 `文件名_还原.ext`。根目录只留结果文件,不会复制一份原文件进去,胶囊与面板都会提示完成结果
|
|
65
|
+
2. **还原文件**:把已屏蔽文件(或任意含〔编码〕的文件)重新拖入即可,无需手动选择操作
|
|
66
|
+
3. **还原文本**:从文件里复制了被屏蔽的内容 → 胶囊提示「识别到含屏蔽信息」,点右侧「还原文本」按钮即可(点胶囊其他位置只展开面板);或在「文本恢复」页粘贴
|
|
67
67
|
4. **快速查找**:展开面板「快速查找」→ 输入文件名 → 点类别按钮筛选(按钮数字为该类别命中数,类别栏聚焦后可用 ←→ 切换)→ 回车打开 / Shift+回车 定位
|
|
68
|
-
5. **同名文件**:「设置 → 同名文件」选择策略,作用于生成的 `_
|
|
69
|
-
6. **命名归位**:还原产物(`A_还原.docx
|
|
68
|
+
5. **同名文件**:「设置 → 同名文件」选择策略,作用于生成的 `_屏蔽` / `_还原` 结果文件。「保留两份」(默认)在结果同名时自动加序号(如 `_屏蔽_02`),旧结果不动;「覆盖同名」直接更新那份结果(启用时有二次确认)
|
|
69
|
+
6. **命名归位**:还原产物(`A_还原.docx`)再次拖入屏蔽时,结果回到原名 `A_屏蔽.docx`(同名按上面的策略处理),不会出现 `A_还原_屏蔽.docx`
|
|
70
70
|
7. **设置**:检测项开关、剪贴板识别、自动收起(时长可自定义 5–3600 秒,也可选快捷预设,修改后立即生效;**关闭自动收起后,鼠标点击面板外任意位置即收起面板**)、开机自启、清空记录
|
|
71
71
|
|
|
72
72
|
## 隐私与安全
|
|
73
73
|
|
|
74
|
-
-
|
|
74
|
+
- 屏蔽映射库(编码 ↔ 原文)仅存本机 `%AppData%`,经 Windows DPAPI(safeStorage)**加密落盘**
|
|
75
75
|
- 工具完全不联网,无任何数据上传
|
|
76
76
|
- 清空记录不影响已生成的文件与映射库;映射库在「设置 → 数据」中可见加密状态
|
|
77
77
|
|
|
@@ -81,14 +81,14 @@ npm test # 核心引擎单元测试(22 项)
|
|
|
81
81
|
- docx/xlsx 中被排版拆分成多个文本片段(run)的敏感值可能漏检(漏检不破坏文档,宁可漏不可错)
|
|
82
82
|
- 中文姓名为语境驱动识别:没有任何语境锚点的单次出现(如正文里孤立的「麦穗」)仍可能漏检;反之,紧邻角色标签但其实是普通词的情况已用边界规则过滤
|
|
83
83
|
- 姓名识别依赖常见姓氏表(约 130 个单姓 + 30 个复姓),生僻姓氏可能漏检
|
|
84
|
-
-
|
|
84
|
+
- 误检可通过「还原」无损找回;漏检建议在屏蔽后人工复核正文中出现的人名
|
|
85
85
|
- 屏蔽值还原依赖映射库:请勿删除 `%AppData%` 下的映射库文件
|
|
86
86
|
|
|
87
87
|
## 项目结构
|
|
88
88
|
|
|
89
89
|
```
|
|
90
90
|
src/
|
|
91
|
-
core/ 检测器 /
|
|
91
|
+
core/ 检测器 / 屏蔽恢复引擎 / 文件管道(纯 JS,可独立测试)
|
|
92
92
|
main/ 主进程:双窗口、托盘、IPC、映射库加密存储、索引、剪贴板监听
|
|
93
93
|
renderer/ 胶囊 + 主面板 UI(原生 HTML/CSS/JS)
|
|
94
94
|
test/ 单元测试 + Electron E2E(含截图)
|
package/assets/icon.png
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/assets/tray.png
CHANGED
|
Binary file
|
package/assets/tray@2x.png
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haitang-hub/lingyu-island",
|
|
3
|
-
"productName": "
|
|
4
|
-
"version": "1.
|
|
5
|
-
"description": "
|
|
3
|
+
"productName": "灵屿岛",
|
|
4
|
+
"version": "1.2.0",
|
|
5
|
+
"description": "灵动岛式文件屏蔽与恢复工具:拖入文件即可屏蔽个人敏感信息,随时还原",
|
|
6
6
|
"main": "src/main/main.js",
|
|
7
7
|
"author": "Haitang-Hub",
|
|
8
8
|
"license": "MIT",
|
|
@@ -19,19 +19,60 @@
|
|
|
19
19
|
"test/real-files.test.js",
|
|
20
20
|
"test/run-tests.js",
|
|
21
21
|
"README.md",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"启动灵屿岛.bat",
|
|
23
|
+
"启动灵屿岛.command"
|
|
24
24
|
],
|
|
25
25
|
"scripts": {
|
|
26
26
|
"start": "electron .",
|
|
27
27
|
"test": "node test/run-tests.js",
|
|
28
|
-
"e2e": "cross-env-shell ISLAND_E2E=1 electron . || ISLAND_E2E=1 electron ."
|
|
28
|
+
"e2e": "cross-env-shell ISLAND_E2E=1 electron . || ISLAND_E2E=1 electron .",
|
|
29
|
+
"dist": "electron-builder --win"
|
|
30
|
+
},
|
|
31
|
+
"build": {
|
|
32
|
+
"appId": "com.lingyu.privacy-island",
|
|
33
|
+
"productName": "LingyuIsland",
|
|
34
|
+
"directories": {
|
|
35
|
+
"output": "release"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"src/**/*",
|
|
39
|
+
"assets/**/*",
|
|
40
|
+
"package.json",
|
|
41
|
+
"!test/**"
|
|
42
|
+
],
|
|
43
|
+
"win": {
|
|
44
|
+
"icon": "assets/icon.png",
|
|
45
|
+
"target": [
|
|
46
|
+
{
|
|
47
|
+
"target": "nsis",
|
|
48
|
+
"arch": [
|
|
49
|
+
"x64"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"target": "zip",
|
|
54
|
+
"arch": [
|
|
55
|
+
"x64"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"nsis": {
|
|
61
|
+
"oneClick": false,
|
|
62
|
+
"perMachine": false,
|
|
63
|
+
"allowToChangeInstallationDirectory": true,
|
|
64
|
+
"createDesktopShortcut": true,
|
|
65
|
+
"shortcutName": "灵屿岛",
|
|
66
|
+
"artifactName": "LingyuIsland-Setup-${version}.${ext}"
|
|
67
|
+
}
|
|
29
68
|
},
|
|
30
69
|
"dependencies": {
|
|
31
70
|
"adm-zip": "^0.5.16",
|
|
32
71
|
"iconv-lite": "^0.6.3"
|
|
33
72
|
},
|
|
34
73
|
"devDependencies": {
|
|
35
|
-
"electron": "^33.2.0"
|
|
74
|
+
"electron": "^33.2.0",
|
|
75
|
+
"electron-builder": "^26.18.0",
|
|
76
|
+
"jimp": "^1.6.1"
|
|
36
77
|
}
|
|
37
78
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* 从 assets/logo-source.jpg 生成全套图标:
|
|
4
|
+
* icon.png(256) / tray.png(16) / tray@2x.png(32)
|
|
5
|
+
* tray-macTemplate.png(16) / tray-macTemplate@2x.png(32)(黑色剪影+透明底)
|
|
6
|
+
* 用法:node scripts/gen-logo.js (依赖 jimp)
|
|
7
|
+
*
|
|
8
|
+
* 处理:从四边 flood-fill 抠除近白背景(含浅灰棋盘纹),保留内部白色眼睛;
|
|
9
|
+
* 边缘残留的白色锯齿再做邻接清除;裁剪 bbox 后缩放输出。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
|
|
15
|
+
let Jimp;
|
|
16
|
+
try { ({ Jimp } = require('jimp')); } catch { Jimp = require('jimp'); }
|
|
17
|
+
|
|
18
|
+
const SRC = path.join(__dirname, '..', 'assets', 'logo-source.jpg');
|
|
19
|
+
const OUT = path.join(__dirname, '..', 'assets');
|
|
20
|
+
|
|
21
|
+
const isLight = (r, g, b) => Math.min(r, g, b) > 215 && (Math.max(r, g, b) - Math.min(r, g, b)) < 22;
|
|
22
|
+
|
|
23
|
+
async function main() {
|
|
24
|
+
const img = await Jimp.read(SRC);
|
|
25
|
+
const { width: w, height: h, data } = img.bitmap;
|
|
26
|
+
console.log(`源图 ${w}x${h}`);
|
|
27
|
+
|
|
28
|
+
// —— flood fill:从边界出发清除近白背景 ——
|
|
29
|
+
const bg = new Uint8Array(w * h); // 1 = 背景
|
|
30
|
+
const stack = [];
|
|
31
|
+
const idx = (x, y) => y * w + x;
|
|
32
|
+
for (let x = 0; x < w; x++) { stack.push([x, 0], [x, h - 1]); }
|
|
33
|
+
for (let y = 0; y < h; y++) { stack.push([0, y], [w - 1, y]); }
|
|
34
|
+
while (stack.length) {
|
|
35
|
+
const [x, y] = stack.pop();
|
|
36
|
+
if (x < 0 || y < 0 || x >= w || y >= h) continue;
|
|
37
|
+
const i = idx(x, y);
|
|
38
|
+
if (bg[i]) continue;
|
|
39
|
+
const o = i * 4;
|
|
40
|
+
if (!isLight(data[o], data[o + 1], data[o + 2])) continue;
|
|
41
|
+
bg[i] = 1;
|
|
42
|
+
stack.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// —— 边缘残留白边清除:透明邻居 + 近白 → 透明(两轮) ——
|
|
46
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
47
|
+
const extra = [];
|
|
48
|
+
for (let y = 1; y < h - 1; y++) {
|
|
49
|
+
for (let x = 1; x < w - 1; x++) {
|
|
50
|
+
const i = idx(x, y);
|
|
51
|
+
if (bg[i]) continue;
|
|
52
|
+
const o = i * 4;
|
|
53
|
+
if (!isLight(data[o], data[o + 1], data[o + 2])) continue;
|
|
54
|
+
const nearTransparent = bg[idx(x + 1, y)] || bg[idx(x - 1, y)] || bg[idx(x, y + 1)] || bg[idx(x, y - 1)];
|
|
55
|
+
if (nearTransparent) extra.push(i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const i of extra) bg[i] = 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// —— 应用透明度 + 裁剪 bbox ——
|
|
62
|
+
for (let i = 0; i < w * h; i++) {
|
|
63
|
+
if (bg[i]) data[i * 4 + 3] = 0;
|
|
64
|
+
}
|
|
65
|
+
let minX = w, minY = h, maxX = -1, maxY = -1;
|
|
66
|
+
for (let y = 0; y < h; y++) {
|
|
67
|
+
for (let x = 0; x < w; x++) {
|
|
68
|
+
if (data[idx(x, y) * 4 + 3] > 0) {
|
|
69
|
+
if (x < minX) minX = x;
|
|
70
|
+
if (x > maxX) maxX = x;
|
|
71
|
+
if (y < minY) minY = y;
|
|
72
|
+
if (y > maxY) maxY = y;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (maxX < 0) throw new Error('背景抠除失败:没有剩余不透明像素(阈值过严)');
|
|
77
|
+
const cw = maxX - minX + 1, ch = maxY - minY + 1;
|
|
78
|
+
console.log(`主体 bbox ${cw}x${ch} @(${minX},${minY})`);
|
|
79
|
+
img.crop({ x: minX, y: minY, w: cw, h: ch });
|
|
80
|
+
|
|
81
|
+
// —— 输出各尺寸 ——
|
|
82
|
+
const outIcon = img.clone().resize({ w: 256, h: 256 });
|
|
83
|
+
await outIcon.write(path.join(OUT, 'icon.png'));
|
|
84
|
+
|
|
85
|
+
for (const [file, size] of [['tray.png', 16], ['tray@2x.png', 32]]) {
|
|
86
|
+
await img.clone().resize({ w: size, h: size }).write(path.join(OUT, file));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// mac 模板图:形状剪影填黑 + 透明底
|
|
90
|
+
for (const [file, size] of [['tray-macTemplate.png', 16], ['tray-macTemplate@2x.png', 32]]) {
|
|
91
|
+
const t = img.clone().resize({ w: size, h: size });
|
|
92
|
+
const td = t.bitmap.data;
|
|
93
|
+
for (let i = 0; i < td.length; i += 4) {
|
|
94
|
+
if (td[i + 3] > 0) { td[i] = 0; td[i + 1] = 0; td[i + 2] = 0; }
|
|
95
|
+
}
|
|
96
|
+
await t.write(path.join(OUT, file));
|
|
97
|
+
}
|
|
98
|
+
console.log('已输出 icon.png / tray.png / tray@2x.png / tray-macTemplate.png / tray-macTemplate@2x.png');
|
|
99
|
+
void fs;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
main().catch((e) => { console.error(e); process.exit(1); });
|
package/scripts/set-root.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const path = require('path');
|
|
9
9
|
|
|
10
|
-
const dir = path.join(process.env.APPDATA, '
|
|
10
|
+
const dir = path.join(process.env.APPDATA, '灵屿岛');
|
|
11
11
|
const p = path.join(dir, 'settings.json');
|
|
12
12
|
let s = {};
|
|
13
13
|
try { s = JSON.parse(fs.readFileSync(p, 'utf8')); } catch { /* 首次 */ }
|
package/src/core/detector.js
CHANGED
|
@@ -73,7 +73,7 @@ const NAME_BLACKLIST = new Set([
|
|
|
73
73
|
'招工', '招标', '招生', '招呼', '招聘', '措施',
|
|
74
74
|
]);
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// 称呼词:紧随姓名(高置信)或直接跟在姓氏后(本身已是屏蔽表述)
|
|
77
77
|
const TITLES = ['先生', '女士', '小姐', '同学', '老师', '医生', '大夫', '经理', '律师', '教授', '主任', '护士', '总裁', '老板', '师傅', '董事', '局长', '科长', '处长', '队长', '院长', '校长', '园长', '部长', '会计', '出纳'];
|
|
78
78
|
const TITLES_SET = new Set(TITLES);
|
|
79
79
|
|
|
@@ -277,7 +277,7 @@ function detectAddress(text) {
|
|
|
277
277
|
/* ---------------- 机构名(民商事主体) ---------------- */
|
|
278
278
|
|
|
279
279
|
/**
|
|
280
|
-
*
|
|
280
|
+
* 需要屏蔽的主体后缀:律所、事务所、公司、集团、合作社
|
|
281
281
|
* 注意:人民法院 / 人民检察院 / 公安局 / 人民政府 等国家机关**不在**此列 ——
|
|
282
282
|
* 文书来源机关是文书效力的一部分,脱掉反而不可用
|
|
283
283
|
*/
|
|
@@ -455,7 +455,7 @@ function detectNames(text, strongItems, knownNames) {
|
|
|
455
455
|
|
|
456
456
|
for (let i = 0; i < text.length - 1; i++) {
|
|
457
457
|
if (!SURNAMES_1.has(text[i]) && !SURNAMES_EXTRA.has(text[i])) continue;
|
|
458
|
-
//
|
|
458
|
+
// 「王女士」这类表述本身就是屏蔽写法,不再处理
|
|
459
459
|
if (TITLES_SET.has(text.substr(i + 1, 2))) continue;
|
|
460
460
|
// 优先 3 字,证据不足时回落 2 字(「周砚,广东…」不能被切成「周砚广」)
|
|
461
461
|
for (const len of [3, 2]) {
|
|
@@ -587,7 +587,7 @@ function detect(text, options = {}) {
|
|
|
587
587
|
if (toggles.org) items.push(...detectOrgs(text));
|
|
588
588
|
if (toggles.name) items.push(...detectNames(text, strong, options.knownNames));
|
|
589
589
|
|
|
590
|
-
//
|
|
590
|
+
// 排除依法不屏蔽的内容(仅当检测项“完全落在”排除区间内时丢弃)
|
|
591
591
|
const excl = exclusionRanges(text);
|
|
592
592
|
const filtered = items.filter((it) => !isContained(it, excl));
|
|
593
593
|
|
package/src/core/fileproc.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 文件屏蔽管道
|
|
4
4
|
* - 文本类:txt/md/csv/json/代码等,自动识别 UTF-8 / GBK,保留原编码写回
|
|
5
5
|
* - Office 类:docx/xlsx/pptx(zip 内 XML 仅替换文本节点,原文跨排版 run 时跳过,绝不破坏结构)
|
|
6
|
-
* -
|
|
6
|
+
* - 原文件永不被覆盖:屏蔽结果写为 「xxx_屏蔽.ext」,还原结果写为 「xxx_还原.ext」
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
const fs = require('fs');
|
|
@@ -17,7 +17,7 @@ const MAX_SIZE = 20 * 1024 * 1024; // 20MB
|
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* 系统垃圾文件(Office「~$」所有者锁文件、LibreOffice「.~lock」锁文件、缩略图/桌面配置等)
|
|
20
|
-
* ——
|
|
20
|
+
* —— 不索引、不导入、不屏蔽
|
|
21
21
|
*/
|
|
22
22
|
function isJunkFile(name) {
|
|
23
23
|
return (
|
|
@@ -85,10 +85,10 @@ function encodeText(text, encoding, bom) {
|
|
|
85
85
|
|
|
86
86
|
/* ---------------- 命名 ---------------- */
|
|
87
87
|
|
|
88
|
-
// 结果后缀:_
|
|
89
|
-
const RESULT_SUFFIX_RE = /_(
|
|
88
|
+
// 结果后缀:_屏蔽(新)/ _脱敏(v1.1 及更早的旧产物,向后兼容)/ _还原,可带序号(_02、_03…),仅剥离位于结尾的
|
|
89
|
+
const RESULT_SUFFIX_RE = /_(屏蔽|脱敏|还原)(?:_\d{1,3})*$/;
|
|
90
90
|
|
|
91
|
-
/** 去掉结尾的 _脱敏 / _还原(含可能存在的序号),得到原始基名 */
|
|
91
|
+
/** 去掉结尾的 _屏蔽 / _脱敏 / _还原(含可能存在的序号),得到原始基名 */
|
|
92
92
|
function stripResultSuffix(base) {
|
|
93
93
|
let out = String(base || '');
|
|
94
94
|
let prev;
|
|
@@ -100,18 +100,18 @@ function stripResultSuffix(base) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* 而不是「06_民事起诉状_还原_
|
|
103
|
+
* 屏蔽结果路径:xxx_屏蔽.ext
|
|
104
|
+
* 还原产物再次屏蔽时按原名归类 —— 「06_民事起诉状_还原.docx」→「06_民事起诉状_屏蔽.docx」,
|
|
105
|
+
* 而不是「06_民事起诉状_还原_屏蔽.docx」
|
|
106
106
|
*/
|
|
107
107
|
function maskedPathOf(p) {
|
|
108
108
|
const dir = path.dirname(p);
|
|
109
109
|
const ext = path.extname(p);
|
|
110
110
|
const base = stripResultSuffix(path.basename(p, ext));
|
|
111
|
-
return path.join(dir, `${base}_
|
|
111
|
+
return path.join(dir, `${base}_屏蔽${ext}`);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
/** 还原结果路径:xxx_还原.ext
|
|
114
|
+
/** 还原结果路径:xxx_还原.ext(屏蔽产物 → 还原产物,名字回到原名) */
|
|
115
115
|
function restoredPathOf(p) {
|
|
116
116
|
const dir = path.dirname(p);
|
|
117
117
|
const ext = path.extname(p);
|
|
@@ -217,7 +217,7 @@ function readFileText(filePath) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
/**
|
|
220
|
-
*
|
|
220
|
+
* 按内容判断处理方式:含〔编码〕的是屏蔽产物 → 还原;其余视为明文 → 屏蔽。
|
|
221
221
|
* 无法读取内容时返回 'mask',交由 maskFile 给出「格式不支持」等明确提示。
|
|
222
222
|
*/
|
|
223
223
|
function detectFileIntent(filePath) {
|
|
@@ -228,8 +228,8 @@ function detectFileIntent(filePath) {
|
|
|
228
228
|
/* ---------------- 单文件处理 ---------------- */
|
|
229
229
|
|
|
230
230
|
/**
|
|
231
|
-
*
|
|
232
|
-
* @param {string} [outPath] 指定结果路径(不传则写为同目录的「xxx_
|
|
231
|
+
* 屏蔽一个文件
|
|
232
|
+
* @param {string} [outPath] 指定结果路径(不传则写为同目录的「xxx_屏蔽.ext」)
|
|
233
233
|
* @returns {{ok:boolean, path:string, maskedPath?:string, count?:number,
|
|
234
234
|
* counts?:Record, skipped?:string, reason?:string}}
|
|
235
235
|
*/
|
|
@@ -243,7 +243,7 @@ function maskFile(filePath, vault, toggles, outPath, knownNames) {
|
|
|
243
243
|
const buf = fs.readFileSync(filePath);
|
|
244
244
|
const dec = decodeBuffer(buf);
|
|
245
245
|
if (!dec) return { ok: false, path: filePath, skipped: 'binary' };
|
|
246
|
-
if (countCodes(dec.text) > 0 && path.basename(filePath)
|
|
246
|
+
if (countCodes(dec.text) > 0 && /_(屏蔽|脱敏)/.test(path.basename(filePath))) {
|
|
247
247
|
return { ok: false, path: filePath, skipped: 'already-masked' };
|
|
248
248
|
}
|
|
249
249
|
const known = mergeKnown(collectKnownNames([dec.text], toggles), knownNames);
|
|
@@ -257,7 +257,7 @@ function maskFile(filePath, vault, toggles, outPath, knownNames) {
|
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
/**
|
|
260
|
-
*
|
|
260
|
+
* 还原一个屏蔽文件(也支持任意含〔编码〕的文本文件)
|
|
261
261
|
* @param {string} [outPath] 指定结果路径(不传则写为同目录的「xxx_还原.ext」)
|
|
262
262
|
* @returns {{ok:boolean, path:string, restoredPath?:string, resolved?:number, missing?:string[]}}
|
|
263
263
|
*/
|
package/src/core/imports.js
CHANGED
package/src/core/masker.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 屏蔽 / 恢复引擎(纯 JS,依赖 node 内置 crypto)
|
|
4
4
|
*
|
|
5
5
|
* 核心设计:屏蔽值形如 138****5678〔ab12cd〕
|
|
6
6
|
* - 前后保留部分原文,让用户“能判断出是什么内容”
|
|
@@ -138,7 +138,7 @@ function buildMasked(type, value, code) {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/* ------------------------------------------------------------------ */
|
|
141
|
-
/*
|
|
141
|
+
/* 文本屏蔽 / 文本恢复 */
|
|
142
142
|
/* ------------------------------------------------------------------ */
|
|
143
143
|
|
|
144
144
|
/**
|
package/src/main/importer.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
3
|
* 智能处理流程(不生成工作副本)
|
|
4
|
-
* 1.
|
|
5
|
-
* 2. 只在根目录写出结果文件:「文件名_
|
|
4
|
+
* 1. 直接读取拖入/选择的文件内容,按内容判断屏蔽或还原
|
|
5
|
+
* 2. 只在根目录写出结果文件:「文件名_屏蔽.ext」或「文件名_还原.ext」
|
|
6
6
|
* —— 不再复制一份明文工作副本到根目录,根目录里只保留处理结果
|
|
7
7
|
* 3. 「同名文件」设置作用于结果文件:保留两份(自动加序号)或覆盖同名
|
|
8
8
|
* 4. 拖入的原位置文件永不改动;设置「移入回收站」时,处理完成后把根目录外的
|
|
@@ -95,8 +95,8 @@ async function importAndMask(inputPaths, ctx, sender) {
|
|
|
95
95
|
const intent = detectFileIntent(src);
|
|
96
96
|
const { out, base, action } = resolveOutputPath(rootNorm, src, intent, conflictPolicy);
|
|
97
97
|
|
|
98
|
-
// 结果路径恰好等于源文件(如根目录里名为 xxx_
|
|
99
|
-
//
|
|
98
|
+
// 结果路径恰好等于源文件(如根目录里名为 xxx_屏蔽 却无编码的文件):
|
|
99
|
+
// 既不覆盖源文件,也不重复屏蔽
|
|
100
100
|
if (path.resolve(out) === path.resolve(src) || path.resolve(base) === path.resolve(src)) {
|
|
101
101
|
r = { ok: false, path: src, action: intent, skipped: 'already-masked' };
|
|
102
102
|
} else {
|
package/src/main/ipc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
* IPC
|
|
3
|
+
* IPC 处理器:屏蔽 / 恢复 / 查找 / 设置 / 系统操作
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { dialog, shell, clipboard, BrowserWindow, ipcMain, app: electronApp } = require('electron');
|
|
@@ -72,7 +72,7 @@ function register(ctx) {
|
|
|
72
72
|
island.dialogOpen = true;
|
|
73
73
|
try {
|
|
74
74
|
const r = await dialog.showOpenDialog(BrowserWindow.fromWebContents(e.sender), {
|
|
75
|
-
title: '
|
|
75
|
+
title: '选择要屏蔽的文件',
|
|
76
76
|
properties: ['openFile', 'multiSelections'],
|
|
77
77
|
});
|
|
78
78
|
if (r.canceled) return [];
|
|
@@ -80,7 +80,7 @@ function register(ctx) {
|
|
|
80
80
|
} finally { island.dialogOpen = false; }
|
|
81
81
|
});
|
|
82
82
|
|
|
83
|
-
/* ----------------
|
|
83
|
+
/* ---------------- 屏蔽 / 恢复 ---------------- */
|
|
84
84
|
|
|
85
85
|
ipc_handle('mask:files', (e, inputPaths) => {
|
|
86
86
|
const paths = Array.isArray(inputPaths) ? inputPaths : [];
|
|
@@ -113,7 +113,7 @@ function register(ctx) {
|
|
|
113
113
|
/* ---------------- 剪贴板恢复 ---------------- */
|
|
114
114
|
|
|
115
115
|
ipc_handle('clip:restore', () => {
|
|
116
|
-
//
|
|
116
|
+
// 只针对「检测到屏蔽信息时的那一次复制内容」生效,不读取点击瞬间剪贴板里的其他内容
|
|
117
117
|
const pending = clipboardWatcher.getPendingText();
|
|
118
118
|
if (!pending) return { ok: false, resolved: 0, stale: true };
|
|
119
119
|
let current = '';
|
package/src/main/island.js
CHANGED
|
@@ -28,6 +28,7 @@ class Island {
|
|
|
28
28
|
|
|
29
29
|
create() {
|
|
30
30
|
const { workArea } = screen.getPrimaryDisplay();
|
|
31
|
+
const appIcon = path.join(__dirname, '..', '..', 'assets', 'icon.png');
|
|
31
32
|
|
|
32
33
|
this.pill = new BrowserWindow({
|
|
33
34
|
width: PILL_W, height: PILL_H,
|
|
@@ -36,6 +37,7 @@ class Island {
|
|
|
36
37
|
frame: false, transparent: true, resizable: false,
|
|
37
38
|
alwaysOnTop: true, skipTaskbar: true, focusable: false,
|
|
38
39
|
hasShadow: false, show: false,
|
|
40
|
+
icon: appIcon,
|
|
39
41
|
backgroundColor: '#00000000',
|
|
40
42
|
webPreferences: {
|
|
41
43
|
preload: path.join(__dirname, '..', 'preload.js'),
|
|
@@ -52,6 +54,7 @@ class Island {
|
|
|
52
54
|
frame: false, transparent: true, resizable: false,
|
|
53
55
|
alwaysOnTop: true, skipTaskbar: true,
|
|
54
56
|
hasShadow: false, show: false,
|
|
57
|
+
icon: appIcon,
|
|
55
58
|
backgroundColor: '#00000000',
|
|
56
59
|
webPreferences: {
|
|
57
60
|
preload: path.join(__dirname, '..', 'preload.js'),
|
|
@@ -99,13 +102,17 @@ class Island {
|
|
|
99
102
|
layout() {
|
|
100
103
|
const { workArea } = screen.getPrimaryDisplay();
|
|
101
104
|
if (this.pill && !this.pill.isDestroyed()) {
|
|
102
|
-
|
|
105
|
+
const px = Math.round(workArea.x + (workArea.width - PILL_W) / 2);
|
|
106
|
+
const py = this._pillY();
|
|
107
|
+
const b = this.pill.getBounds();
|
|
108
|
+
// 位置没变就不要动窗口:透明窗口 setPosition 会触发一次重绘,肉眼可见地「闪」
|
|
109
|
+
if (b.x !== px || b.y !== py) this.pill.setPosition(px, py);
|
|
103
110
|
}
|
|
104
111
|
if (this.panel && !this.panel.isDestroyed()) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
112
|
+
const px = Math.round(workArea.x + (workArea.width - PANEL_W) / 2);
|
|
113
|
+
const py = Math.min(workArea.y + 6 + PILL_H + 4, workArea.y + workArea.height - PANEL_H);
|
|
114
|
+
const b = this.panel.getBounds();
|
|
115
|
+
if (b.x !== px || b.y !== py) this.panel.setPosition(px, py);
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
118
|
|
|
@@ -114,11 +121,33 @@ class Island {
|
|
|
114
121
|
this.layout();
|
|
115
122
|
if (tab) this.panel.webContents.send('panel:show-tab', tab);
|
|
116
123
|
// 面板始终为「点击外部即收起」模式:必须激活窗口,blur 才会触发
|
|
124
|
+
const wasVisible = this.panel.isVisible();
|
|
125
|
+
if (!wasVisible) {
|
|
126
|
+
// 先以 0 透明度拉起,避开透明窗口显示瞬间的首帧闪动,再做淡入过渡
|
|
127
|
+
try { this.panel.setOpacity(0); } catch { /* ignore */ }
|
|
128
|
+
}
|
|
117
129
|
this.panel.show();
|
|
118
130
|
this.panel.focus();
|
|
131
|
+
if (!wasVisible) this._fadeIn();
|
|
119
132
|
this._notifyPanel(true); // 面板打开期间胶囊暂停空闲收起计时
|
|
120
133
|
}
|
|
121
134
|
|
|
135
|
+
_fadeIn() {
|
|
136
|
+
this._stopFade();
|
|
137
|
+
const w = this.panel;
|
|
138
|
+
let o = 0;
|
|
139
|
+
this._fadeTimer = setInterval(() => {
|
|
140
|
+
if (w.isDestroyed()) return this._stopFade();
|
|
141
|
+
o = Math.min(1, o + 0.25);
|
|
142
|
+
try { w.setOpacity(o); } catch { /* ignore */ }
|
|
143
|
+
if (o >= 1) this._stopFade();
|
|
144
|
+
}, 35); // 约 140ms 淡入
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
_stopFade() {
|
|
148
|
+
if (this._fadeTimer) { clearInterval(this._fadeTimer); this._fadeTimer = null; }
|
|
149
|
+
}
|
|
150
|
+
|
|
122
151
|
/** 胶囊在面板之外,点击它也应视为「点击外部」而收起 */
|
|
123
152
|
onPillClick(tab) {
|
|
124
153
|
if (this.panel && this.panel.isVisible()) this.hidePanel();
|
|
@@ -126,10 +155,13 @@ class Island {
|
|
|
126
155
|
}
|
|
127
156
|
|
|
128
157
|
hidePanel() {
|
|
129
|
-
if (this.panel
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
158
|
+
if (!this.panel || !this.panel.isVisible() || this.panel.isDestroyed()) return;
|
|
159
|
+
this._stopFade();
|
|
160
|
+
// 关闭保持立即隐藏(不淡出):与「点击面板外即收起」的即时语义一致,
|
|
161
|
+
// 也避免淡出窗口期间 isVisible() 仍为 true 造成交互判断歧义
|
|
162
|
+
try { this.panel.setOpacity(1); } catch { /* ignore */ }
|
|
163
|
+
this.panel.hide();
|
|
164
|
+
this._notifyPanel(false); // 面板关闭后胶囊恢复空闲计时
|
|
133
165
|
}
|
|
134
166
|
|
|
135
167
|
togglePanel(tab) {
|
package/src/main/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 灵屿岛 —— 应用入口
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const { app, Menu } = require('electron');
|
|
@@ -25,7 +25,7 @@ if (!app.requestSingleInstanceLock()) {
|
|
|
25
25
|
app.quit();
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
app.setAppUserModelId('com.
|
|
28
|
+
app.setAppUserModelId('com.yu.dynamic-island');
|
|
29
29
|
|
|
30
30
|
// macOS:作为托盘工具,不占用 Dock 图标
|
|
31
31
|
if (process.platform === 'darwin' && app.dock) {
|