@mysterycode-liwen/dsh-credential-vault 1.4.0 → 1.4.2
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 +18 -5
- package/client.js +157 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ dsh plugin --profile desktop why @mysterycode-liwen/dsh-credential-vault
|
|
|
72
72
|
- **密码生成器**:在账号密码字段旁点「⚙ 生成」,用加密安全随机数(Web Crypto)生成强密码,可设置长度与字符类型、避开易混淆字符,并实时显示强度;可直接填入表单或复制。(仅账号密码类提供,API Key / 其他类不显示)
|
|
73
73
|
- **健康审计**:点「🛡 健康审计」扫描全部凭据,列出弱密码 / 空密钥、重复使用、已过期 / 即将到期等问题并按严重程度排序,点击条目可直接跳转编辑。
|
|
74
74
|
- 登录网址 / Base URL 字段旁提供「访问」按钮,默认用 DeepSeek Harness 内置浏览器打开。
|
|
75
|
-
- 导入 / 导出:可把全部凭据导出为 **JSON 备份 / CSV(Excel、WPS 可直接打开)/ Markdown
|
|
75
|
+
- 导入 / 导出:可把全部凭据导出为 **JSON 备份 / CSV(Excel、WPS 可直接打开)/ Markdown 卡片**三种格式,或从这三种格式的文件恢复;导入时自动识别格式,并可选「合并(跳过重复 ID)」或「替换全部」。JSON 保留全部字段;CSV 用中文表头、常用列在前;Markdown 每条凭据一张中文卡片,方便阅读。三种格式均可无损导回。
|
|
76
76
|
- 设置页:访问密码开关、设置 / 修改密码、密保问题重置、闲置自动锁定(可开关、可选时长)、插件版本与检查更新。
|
|
77
77
|
|
|
78
78
|
## Agent 工具 / Agent tool
|
|
@@ -111,9 +111,9 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
|
|
|
111
111
|
|
|
112
112
|
**导出该选哪种格式?Excel 打开 CSV 会乱码吗?**
|
|
113
113
|
- **JSON**:字段最完整,换机器 / 完整备份首选。
|
|
114
|
-
- **CSV**:带 UTF-8 BOM,Excel / WPS
|
|
115
|
-
- **Markdown
|
|
116
|
-
|
|
114
|
+
- **CSV**:带 UTF-8 BOM,Excel / WPS 双击即可正确显示中文;中文表头、常用列在前,ID / 时间戳等放在最后,适合表格查看与批量编辑。
|
|
115
|
+
- **Markdown**:每条凭据一张卡片、中文标签两列表,空字段自动省略,方便阅读、贴到文档或做版本管理;完整数据以 HTML 注释内嵌,导入时无损还原。
|
|
116
|
+
导入时会自动识别这三种格式(也兼容旧版英文表头的 CSV 与宽表格 Markdown),无需手动选择。
|
|
117
117
|
|
|
118
118
|
**支持多设备同步吗?**
|
|
119
119
|
不支持,也不打算支持——本插件的定位就是「不上云的本机保险箱」。
|
|
@@ -123,6 +123,19 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
|
|
|
123
123
|
|
|
124
124
|
## 更新日志 / Changelog
|
|
125
125
|
|
|
126
|
+
### 1.4.2 — 2026-11-22
|
|
127
|
+
|
|
128
|
+
- **字段过滤**:导入 / 加载 / 导出时统一按凭据类型清理字段,API Key 记录若残留账号类的「用户名 / 密码 / 网址」会被自动剔除,不再出现在卡片或导出文件中。
|
|
129
|
+
- 清理在 `normalize()` 里统一完成:从 localStorage 加载、三种格式导入、导出渲染都走同一入口;合法字段(ID / 类型 / 时间戳)保留,无损导回不变。
|
|
130
|
+
- 新增回归测试:验证脏 API Key 记录经 JSON / CSV / Markdown 导入后脏字段被清除、真字段保留。
|
|
131
|
+
|
|
132
|
+
### 1.4.1 — 2026-11-22
|
|
133
|
+
|
|
134
|
+
- **可读性改进**:Markdown 导出由超宽表格改为每条凭据一张卡片、中文标签两列表、空字段省略、类型显示为「账号 / API Key / 其他」,一目了然。
|
|
135
|
+
- CSV 导出改为中文表头、常用列在前,类型中文化,时间戳转为易读的 ISO 格式。
|
|
136
|
+
- 两种格式在保持可读的同时仍可无损导回(Markdown 以 HTML 注释内嵌完整数据);导入兼容旧版英文表头 CSV 与宽表格 Markdown。
|
|
137
|
+
- 自动识别逻辑同步更新,新增「无注释的手改卡片」回退解析。
|
|
138
|
+
|
|
126
139
|
### 1.4.0 — 2026-11-22
|
|
127
140
|
|
|
128
141
|
- 导入 / 导出支持三种格式:**JSON 备份**(完整字段)、**CSV**(UTF-8 BOM,Excel / WPS 双击即开)、**Markdown 表格**(可读、易复制与版本管理)。
|
|
@@ -148,7 +161,7 @@ Host 侧工具在 Harness 启动时注册。重启 Harness,或在插件管理
|
|
|
148
161
|
npm run check # 发布前自检:client.js 的模块 id 与 cordis.patch.yml 的 name 必须等于包名
|
|
149
162
|
npm pack --dry-run # 核对实际打包的文件清单
|
|
150
163
|
npm publish # publishConfig.access = public;会先自动跑一次 npm run check,不一致则中止
|
|
151
|
-
git tag v1.4.
|
|
164
|
+
git tag v1.4.2 && git push --tags
|
|
152
165
|
```
|
|
153
166
|
|
|
154
167
|
`client.js` 里 `window.__ModuleLoader__.load({ id })` 的 `id` **必须等于 `package.json` 的 `name`**:DSH 按包名去浏览器模块表里查找,不一致时浏览器端不会挂载,表现为侧边栏入口与设置页整块消失(Host 端仍然正常)。改包名或改 scope 时,三处要同步:`package.json` 的 `name`、`client.js` 的 `id`、`cordis.patch.yml` 的 `name`。
|
package/client.js
CHANGED
|
@@ -15,7 +15,7 @@ window.__ModuleLoader__.load({
|
|
|
15
15
|
// whatever port the Web GUI is on.
|
|
16
16
|
var API = 'dsh-credential-vault/';
|
|
17
17
|
/** Plugin version shown in Settings; keep in sync with package.json on release. */
|
|
18
|
-
var VERSION = '1.4.
|
|
18
|
+
var VERSION = '1.4.2';
|
|
19
19
|
|
|
20
20
|
// Compare two semver-ish strings: -1 (left older), 0 (equal), 1 (left newer).
|
|
21
21
|
// Used to decide "update available" against THIS client's version, so the
|
|
@@ -115,8 +115,8 @@ window.__ModuleLoader__.load({
|
|
|
115
115
|
importInvalid: 'Invalid backup file', importEmpty: 'No credentials in this file',
|
|
116
116
|
importDetected: 'Detected format', fmtJson: 'JSON', fmtCsv: 'CSV', fmtMd: 'Markdown',
|
|
117
117
|
exportFormat: 'Export format', exportJson: 'JSON backup', exportJsonHint: 'Full fidelity — restores every field exactly (recommended).',
|
|
118
|
-
exportCsv: 'CSV for Excel / WPS', exportCsvHint: '
|
|
119
|
-
exportMd: 'Markdown', exportMdHint: '
|
|
118
|
+
exportCsv: 'CSV for Excel / WPS', exportCsvHint: 'Chinese headers, readable order, UTF-8 with BOM.',
|
|
119
|
+
exportMd: 'Markdown cards', exportMdHint: 'One card per entry with Chinese labels — clean and readable.',
|
|
120
120
|
genButton: 'Generate password', genField: 'Generate a password for this field',
|
|
121
121
|
genTitle: 'Password generator', genHint: 'Generates a strong random password using your browser’s cryptographic random source. Nothing is stored or sent anywhere.',
|
|
122
122
|
genLength: 'Length', genUpper: 'Uppercase (A–Z)', genLower: 'Lowercase (a–z)', genDigits: 'Digits (0–9)',
|
|
@@ -218,8 +218,8 @@ window.__ModuleLoader__.load({
|
|
|
218
218
|
importInvalid: '备份文件无效', importEmpty: '文件中没有凭据',
|
|
219
219
|
importDetected: '识别到的格式', fmtJson: 'JSON', fmtCsv: 'CSV', fmtMd: 'Markdown',
|
|
220
220
|
exportFormat: '导出格式', exportJson: 'JSON 备份', exportJsonHint: '完整保真,可精确恢复全部字段(推荐)。',
|
|
221
|
-
exportCsv: 'CSV(Excel / WPS)', exportCsvHint: '
|
|
222
|
-
exportMd: 'Markdown
|
|
221
|
+
exportCsv: 'CSV(Excel / WPS)', exportCsvHint: '中文表头、常用列在前,UTF-8 BOM 编码。',
|
|
222
|
+
exportMd: 'Markdown 卡片', exportMdHint: '每条凭据一张卡片、中文标签,一目了然。',
|
|
223
223
|
genButton: '生成密码', genField: '为此字段生成密码',
|
|
224
224
|
genTitle: '密码生成器', genHint: '使用浏览器的加密随机源生成高强度随机密码,不会存储或上传任何数据。',
|
|
225
225
|
genLength: '长度', genUpper: '大写字母 (A–Z)', genLower: '小写字母 (a–z)', genDigits: '数字 (0–9)',
|
|
@@ -467,7 +467,7 @@ window.__ModuleLoader__.load({
|
|
|
467
467
|
if (n.provider == null && n.username) n.provider = n.username;
|
|
468
468
|
if (n.endpoint == null && n.url) n.endpoint = n.url;
|
|
469
469
|
}
|
|
470
|
-
return n;
|
|
470
|
+
return sanitize(n);
|
|
471
471
|
}
|
|
472
472
|
function loadEntries() {
|
|
473
473
|
try {
|
|
@@ -654,6 +654,40 @@ window.__ModuleLoader__.load({
|
|
|
654
654
|
}
|
|
655
655
|
var EXPORT_COLS = ['id', 'title', 'category', 'username', 'password', 'url', 'provider', 'apiKey', 'endpoint', 'expiry', 'content', 'notes', 'createdAt', 'updatedAt'];
|
|
656
656
|
|
|
657
|
+
// ---- Human-readable labels ------------------------------------------------
|
|
658
|
+
// CSV/Markdown use Chinese labels for people; every label maps back to its
|
|
659
|
+
// exact field name so an exported file still round-trips without data loss.
|
|
660
|
+
var FIELD_LABELS = {
|
|
661
|
+
id: 'ID', title: '标题', category: '类型', username: '用户名', password: '密码',
|
|
662
|
+
url: '网址', provider: '服务商', apiKey: 'API Key', endpoint: '接口地址',
|
|
663
|
+
expiry: '有效期', content: '内容', notes: '备注', createdAt: '创建时间', updatedAt: '更新时间'
|
|
664
|
+
};
|
|
665
|
+
var LABEL_FIELDS = {};
|
|
666
|
+
Object.keys(FIELD_LABELS).forEach(function (k) { LABEL_FIELDS[FIELD_LABELS[k]] = k; });
|
|
667
|
+
var CATEGORY_LABELS = { account: '账号', apikey: 'API Key', other: '其他' };
|
|
668
|
+
var LABEL_CATEGORIES = {};
|
|
669
|
+
Object.keys(CATEGORY_LABELS).forEach(function (k) { LABEL_CATEGORIES[CATEGORY_LABELS[k]] = k; });
|
|
670
|
+
// Only export fields that belong to the entry's type. A record may carry
|
|
671
|
+
// stale fields from a past type change (e.g. an API Key with leftover
|
|
672
|
+
// username/password/url); those must not leak into readable exports.
|
|
673
|
+
var VISIBLE_FIELDS = {
|
|
674
|
+
account: ['title', 'username', 'password', 'url', 'notes'],
|
|
675
|
+
apikey: ['title', 'provider', 'apiKey', 'endpoint', 'expiry', 'notes'],
|
|
676
|
+
other: ['title', 'content', 'notes']
|
|
677
|
+
};
|
|
678
|
+
function fieldsFor(cat) { return VISIBLE_FIELDS[cat] || VISIBLE_FIELDS.account; }
|
|
679
|
+
// Strip fields that do not belong to the entry's type. Applied inside
|
|
680
|
+
// normalize(), so stale fields (e.g. an API Key carrying username/password/
|
|
681
|
+
// url from a past type change) are removed everywhere data enters the app:
|
|
682
|
+
// loading from localStorage, importing, and exporting. Technical columns
|
|
683
|
+
// (id / category / timestamps) stay for identity and ordering.
|
|
684
|
+
function sanitize(e) {
|
|
685
|
+
var keep = fieldsFor(e.category).concat(['id', 'category', 'createdAt', 'updatedAt']);
|
|
686
|
+
var out = {};
|
|
687
|
+
keep.forEach(function (k) { if (e[k] !== undefined) out[k] = e[k]; });
|
|
688
|
+
return out;
|
|
689
|
+
}
|
|
690
|
+
|
|
657
691
|
// CSV helpers (RFC 4180): quote fields containing comma / quote / newline,
|
|
658
692
|
// double embedded quotes. The file carries a UTF-8 BOM so Excel/WPS show
|
|
659
693
|
// Chinese characters correctly when opened by double-click.
|
|
@@ -661,11 +695,28 @@ window.__ModuleLoader__.load({
|
|
|
661
695
|
var s = v == null ? '' : String(v);
|
|
662
696
|
return /[",\r\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
|
663
697
|
}
|
|
698
|
+
function csvDate(v) {
|
|
699
|
+
if (v == null || v === '') return '';
|
|
700
|
+
var d = new Date(Number(v));
|
|
701
|
+
return isNaN(d.getTime()) ? String(v) : d.toISOString();
|
|
702
|
+
}
|
|
703
|
+
// CSV shows the fields people actually read first; technical columns
|
|
704
|
+
// (ID / timestamps) go last. Import maps by header label, so order is safe.
|
|
705
|
+
var CSV_COLS = ['title', 'category', 'username', 'password', 'url', 'provider',
|
|
706
|
+
'apiKey', 'endpoint', 'expiry', 'content', 'notes', 'id', 'createdAt', 'updatedAt'];
|
|
664
707
|
function buildCsv(arr) {
|
|
665
|
-
var lines = [
|
|
708
|
+
var lines = [CSV_COLS.map(function (c) { return csvEscape(FIELD_LABELS[c] || c); }).join(',')];
|
|
666
709
|
arr.forEach(function (e) {
|
|
667
710
|
var n = normalize(e);
|
|
668
|
-
|
|
711
|
+
var visible = fieldsFor(n.category);
|
|
712
|
+
lines.push(CSV_COLS.map(function (c) {
|
|
713
|
+
// Technical columns stay for lossless import; business columns that
|
|
714
|
+
// do not belong to this type are left blank.
|
|
715
|
+
if (visible.indexOf(c) < 0 && c !== 'id' && c !== 'category' && c !== 'createdAt' && c !== 'updatedAt') return '';
|
|
716
|
+
var v = (c === 'createdAt' || c === 'updatedAt') ? csvDate(n[c]) : n[c];
|
|
717
|
+
if (c === 'category') v = CATEGORY_LABELS[v] || v;
|
|
718
|
+
return csvEscape(v);
|
|
719
|
+
}).join(','));
|
|
669
720
|
});
|
|
670
721
|
return '\uFEFF' + lines.join('\r\n');
|
|
671
722
|
}
|
|
@@ -693,7 +744,9 @@ window.__ModuleLoader__.load({
|
|
|
693
744
|
function parseCsv(text) {
|
|
694
745
|
var rows = csvParse(text);
|
|
695
746
|
if (rows.length < 2) throw new Error('shape');
|
|
696
|
-
var
|
|
747
|
+
var rawHeader = rows[0].map(function (x) { return String(x).trim(); });
|
|
748
|
+
// Accept both the new Chinese header and the legacy English one.
|
|
749
|
+
var header = rawHeader.map(function (h) { return LABEL_FIELDS[h] || h; });
|
|
697
750
|
if (header.indexOf('title') === -1) throw new Error('shape');
|
|
698
751
|
var out = [];
|
|
699
752
|
for (var r = 1; r < rows.length; r++) {
|
|
@@ -701,16 +754,22 @@ window.__ModuleLoader__.load({
|
|
|
701
754
|
if (cells.length === 1 && !String(cells[0]).trim()) continue;
|
|
702
755
|
var e = {};
|
|
703
756
|
header.forEach(function (h, i2) { if (h) e[h] = cells[i2] != null ? cells[i2] : ''; });
|
|
757
|
+
if (e.category) e.category = LABEL_CATEGORIES[e.category] || e.category;
|
|
704
758
|
['createdAt', 'updatedAt'].forEach(function (k) {
|
|
705
|
-
|
|
759
|
+
var v = e[k];
|
|
760
|
+
if (v != null && v !== '') {
|
|
761
|
+
if (/^\d+$/.test(String(v))) e[k] = Number(v);
|
|
762
|
+
else { var ms = Date.parse(v); if (!isNaN(ms)) e[k] = ms; }
|
|
763
|
+
}
|
|
706
764
|
});
|
|
707
765
|
out.push(normalize(e));
|
|
708
766
|
}
|
|
709
767
|
return out;
|
|
710
768
|
}
|
|
711
769
|
|
|
712
|
-
// Markdown
|
|
713
|
-
//
|
|
770
|
+
// Markdown card helpers. Each credential is a small card with a Chinese
|
|
771
|
+
// two-column table; an embedded HTML comment keeps the full original data
|
|
772
|
+
// so import stays lossless even though the visible part is human-friendly.
|
|
714
773
|
function mdEscape(v) {
|
|
715
774
|
return String(v == null ? '' : v)
|
|
716
775
|
.replace(/\\/g, '\\\\').replace(/\|/g, '\\|')
|
|
@@ -719,6 +778,7 @@ window.__ModuleLoader__.load({
|
|
|
719
778
|
function mdDecode(s) {
|
|
720
779
|
var out = '', i = 0;
|
|
721
780
|
while (i < s.length) {
|
|
781
|
+
if (s.substr(i, 4) === '<br>') { out += '\n'; i += 4; continue; }
|
|
722
782
|
if (s.charAt(i) === '\\' && i + 1 < s.length) {
|
|
723
783
|
var c = s.charAt(i + 1);
|
|
724
784
|
if (c === 'n') { out += '\n'; i += 2; continue; }
|
|
@@ -740,45 +800,103 @@ window.__ModuleLoader__.load({
|
|
|
740
800
|
if (s.charAt(i) === '|') { cells.push(cur); cur = ''; i++; continue; }
|
|
741
801
|
cur += s.charAt(i); i++;
|
|
742
802
|
}
|
|
743
|
-
// The trailing '|' was stripped above, so the final cell is still in cur.
|
|
744
803
|
cells.push(cur);
|
|
745
|
-
// buildMarkdown pads each cell with one space on either side of '|';
|
|
746
|
-
// strip exactly one such padding space, preserving any intentional ones.
|
|
747
804
|
return cells.map(function (x) { return mdDecode(x.replace(/^ /, '').replace(/ $/, '')); });
|
|
748
805
|
}
|
|
806
|
+
// Cell text for the visible card table: escape pipes/backslashes, and show
|
|
807
|
+
// real newlines as <br> so multi-line notes stay readable in a table.
|
|
808
|
+
function mdCell(v) {
|
|
809
|
+
return String(v == null ? '' : v)
|
|
810
|
+
.replace(/\\/g, '\\\\').replace(/\|/g, '\\|')
|
|
811
|
+
.replace(/\r/g, '').replace(/\n/g, '<br>');
|
|
812
|
+
}
|
|
749
813
|
function buildMarkdown(arr) {
|
|
750
|
-
var lines = ['#
|
|
751
|
-
'
|
|
752
|
-
'
|
|
753
|
-
arr.forEach(function (e) {
|
|
814
|
+
var lines = ['# 凭据保险箱 / Credential Vault', '',
|
|
815
|
+
'导出时间:' + new Date().toISOString() + ' · 共 ' + arr.length + ' 条', '',
|
|
816
|
+
'> 每条凭据下方的 HTML 注释保存了完整原始数据(含 ID、时间戳等),导入时优先读取以保证无损还原。请勿删除这些注释。', ''];
|
|
817
|
+
arr.forEach(function (e, i) {
|
|
754
818
|
var n = normalize(e);
|
|
755
|
-
lines.push('
|
|
819
|
+
lines.push('## ' + (i + 1) + '. ' + mdCell(n.title || '(无标题)'));
|
|
820
|
+
lines.push('');
|
|
821
|
+
// Encode < and > so the JSON can never terminate the HTML comment early.
|
|
822
|
+
var data = JSON.stringify(n).replace(/</g, '\\u003c').replace(/>/g, '\\u003e');
|
|
823
|
+
lines.push('<!-- cv:' + data + ' -->');
|
|
824
|
+
lines.push('');
|
|
825
|
+
lines.push('| 字段 | 内容 |');
|
|
826
|
+
lines.push('| --- | --- |');
|
|
827
|
+
lines.push('| 类型 | ' + mdCell(CATEGORY_LABELS[n.category] || n.category || '账号') + ' |');
|
|
828
|
+
fieldsFor(n.category).forEach(function (c) {
|
|
829
|
+
if (c === 'title') return;
|
|
830
|
+
var v = n[c];
|
|
831
|
+
if (v == null || v === '') return;
|
|
832
|
+
lines.push('| ' + (FIELD_LABELS[c] || c) + ' | ' + mdCell(v) + ' |');
|
|
833
|
+
});
|
|
834
|
+
lines.push('');
|
|
835
|
+
lines.push('---');
|
|
836
|
+
lines.push('');
|
|
756
837
|
});
|
|
757
838
|
return lines.join('\n');
|
|
758
839
|
}
|
|
759
840
|
function parseMarkdown(text) {
|
|
760
841
|
var lines = String(text || '').replace(/^\uFEFF/, '').split(/\r?\n/);
|
|
842
|
+
// Preferred path: the embedded <!-- cv:{...} --> comment is lossless.
|
|
843
|
+
var fromComment = [];
|
|
844
|
+
lines.forEach(function (line) {
|
|
845
|
+
var m = /<!--\s*cv:(\{[\s\S]*?\})\s*-->/.exec(line);
|
|
846
|
+
if (m) { try { fromComment.push(normalize(JSON.parse(m[1]))); } catch (e) {} }
|
|
847
|
+
});
|
|
848
|
+
if (fromComment.length) return fromComment;
|
|
849
|
+
|
|
850
|
+
// Legacy wide table from earlier exports: keep supporting old files.
|
|
761
851
|
var hIdx = -1;
|
|
762
852
|
for (var i = 0; i < lines.length - 1; i++) {
|
|
763
853
|
if (/^\s*\|/.test(lines[i]) && /title/.test(lines[i]) &&
|
|
764
854
|
/^\s*\|/.test(lines[i + 1]) && /-/.test(lines[i + 1])) { hIdx = i; break; }
|
|
765
855
|
}
|
|
766
|
-
if (hIdx
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
856
|
+
if (hIdx >= 0) {
|
|
857
|
+
var header = mdSplitRow(lines[hIdx]).map(function (h) { return LABEL_FIELDS[h] || h; });
|
|
858
|
+
if (header.indexOf('title') !== -1) {
|
|
859
|
+
var out = [];
|
|
860
|
+
for (var r = hIdx + 2; r < lines.length; r++) {
|
|
861
|
+
var line = lines[r];
|
|
862
|
+
if (!/^\s*\|/.test(line)) continue;
|
|
863
|
+
var cells = mdSplitRow(line);
|
|
864
|
+
var e = {};
|
|
865
|
+
header.forEach(function (h, i2) { if (h) e[h] = cells[i2] != null ? cells[i2] : ''; });
|
|
866
|
+
['createdAt', 'updatedAt'].forEach(function (k) {
|
|
867
|
+
if (e[k] != null && e[k] !== '' && /^\d+$/.test(String(e[k]))) e[k] = Number(e[k]);
|
|
868
|
+
});
|
|
869
|
+
out.push(normalize(e));
|
|
870
|
+
}
|
|
871
|
+
return out;
|
|
872
|
+
}
|
|
780
873
|
}
|
|
781
|
-
|
|
874
|
+
|
|
875
|
+
// Fallback: hand-edited cards whose comment was removed — read 字段/内容 tables.
|
|
876
|
+
var cards = [], curCard = null, inTable = false;
|
|
877
|
+
lines.forEach(function (line) {
|
|
878
|
+
var h = /^##\s+(?:\d+\.\s*)?(.*)$/.exec(line);
|
|
879
|
+
if (h) {
|
|
880
|
+
curCard = { title: h[1].trim() === '(无标题)' ? '' : h[1].trim(), fields: {} };
|
|
881
|
+
cards.push(curCard); inTable = false; return;
|
|
882
|
+
}
|
|
883
|
+
if (!curCard) return;
|
|
884
|
+
if (/^\|\s*字段\s*\|\s*内容\s*\|?\s*$/.test(line)) { inTable = true; return; }
|
|
885
|
+
if (inTable && /^\s*\|/.test(line)) {
|
|
886
|
+
var cells = mdSplitRow(line);
|
|
887
|
+
if (cells.length >= 2 && !/^-+$/.test(cells[0].replace(/\s/g, ''))) {
|
|
888
|
+
var key = LABEL_FIELDS[cells[0].trim()] || cells[0].trim();
|
|
889
|
+
curCard.fields[key] = cells.slice(1).join(' ');
|
|
890
|
+
}
|
|
891
|
+
} else if (!line.trim()) { inTable = false; }
|
|
892
|
+
});
|
|
893
|
+
return cards.map(function (c, i) {
|
|
894
|
+
var e = { id: 'import-' + Date.now() + '-' + i, title: c.title };
|
|
895
|
+
Object.keys(c.fields).forEach(function (k) {
|
|
896
|
+
e[k] = k === 'category' ? (LABEL_CATEGORIES[c.fields[k]] || c.fields[k]) : c.fields[k];
|
|
897
|
+
});
|
|
898
|
+
return normalize(e);
|
|
899
|
+
});
|
|
782
900
|
}
|
|
783
901
|
|
|
784
902
|
// Auto-detect the format and return { entries, fmt } or throw a known error.
|
|
@@ -787,12 +905,15 @@ window.__ModuleLoader__.load({
|
|
|
787
905
|
var t = s.trim();
|
|
788
906
|
if (!t) throw new Error('empty');
|
|
789
907
|
if (t.charAt(0) === '{' || t.charAt(0) === '[') return { entries: parseBackup(t), fmt: 'json' };
|
|
908
|
+
if (/<!--\s*cv:/.test(s) || /\|\s*字段\s*\|/.test(s)) return { entries: parseMarkdown(t), fmt: 'md' };
|
|
790
909
|
var lines = t.split(/\r?\n/);
|
|
791
910
|
for (var li = 0; li < lines.length; li++) {
|
|
792
911
|
if (/^\s*\|/.test(lines[li]) && /title/.test(lines[li])) return { entries: parseMarkdown(t), fmt: 'md' };
|
|
793
912
|
}
|
|
794
913
|
var first = lines[0] || '';
|
|
795
|
-
if (first.indexOf(',') !== -1 &&
|
|
914
|
+
if (first.indexOf(',') !== -1 &&
|
|
915
|
+
(/\bid\b/.test(first) || /ID/.test(first)) &&
|
|
916
|
+
(/title/.test(first) || /标题/.test(first))) return { entries: parseCsv(t), fmt: 'csv' };
|
|
796
917
|
throw new Error('parse');
|
|
797
918
|
}
|
|
798
919
|
function exportBackup(arr) {
|
package/package.json
CHANGED