dsh-plugin-zotero 0.9.2 → 0.9.3
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/client/client.js +97 -24
- package/lib/host/router.js +48 -13
- package/lib/zotero/client.d.ts +2 -0
- package/lib/zotero/client.js +11 -3
- package/package.json +1 -1
package/client/client.js
CHANGED
|
@@ -1129,7 +1129,6 @@ function fetchAttachmentInfo(key, signal) {
|
|
|
1129
1129
|
function snapshotUrl(key) {
|
|
1130
1130
|
return `/dsh-zotero/snapshot/${encodeURIComponent(key)}/`;
|
|
1131
1131
|
}
|
|
1132
|
-
/** 用系统 Zotero 打开条目或附件页。 */
|
|
1133
1132
|
async function openInZotero(input) {
|
|
1134
1133
|
await post("open-in-zotero", input);
|
|
1135
1134
|
}
|
|
@@ -2238,6 +2237,15 @@ const KNOWN_SCOPES = [
|
|
|
2238
2237
|
"trash",
|
|
2239
2238
|
"recent"
|
|
2240
2239
|
];
|
|
2240
|
+
const VIRTUAL_COUNT_SCOPES = [
|
|
2241
|
+
"publications",
|
|
2242
|
+
"unfiled",
|
|
2243
|
+
"trash"
|
|
2244
|
+
];
|
|
2245
|
+
/** scope 是否是树里要显示数量的特殊目录。 */
|
|
2246
|
+
function isVirtualCountScope(scope) {
|
|
2247
|
+
return scope === "publications" || scope === "unfiled" || scope === "trash";
|
|
2248
|
+
}
|
|
2241
2249
|
/** 文库根节点的 id(只存在于客户端,不对应任何 Zotero 分类)。 */
|
|
2242
2250
|
const TREE_ROOT_ID = "__library__";
|
|
2243
2251
|
/**
|
|
@@ -2331,6 +2339,7 @@ function initialState() {
|
|
|
2331
2339
|
expanded: /* @__PURE__ */ new Set([TREE_ROOT_ID, ...saved.expanded]),
|
|
2332
2340
|
treeQuery: "",
|
|
2333
2341
|
recentCount: 0,
|
|
2342
|
+
virtualCounts: {},
|
|
2334
2343
|
selectedCollection: saved.selected === null ? null : {
|
|
2335
2344
|
key: saved.selected.key,
|
|
2336
2345
|
name: saved.selected.name,
|
|
@@ -2355,12 +2364,14 @@ function initialState() {
|
|
|
2355
2364
|
toast: null
|
|
2356
2365
|
};
|
|
2357
2366
|
}
|
|
2358
|
-
function errorMessage$
|
|
2367
|
+
function errorMessage$5(error) {
|
|
2359
2368
|
return error instanceof Error ? error.message : String(error);
|
|
2360
2369
|
}
|
|
2361
2370
|
let state = initialState();
|
|
2362
2371
|
const listeners$1 = /* @__PURE__ */ new Set();
|
|
2363
2372
|
let treeInflight = null;
|
|
2373
|
+
/** 特殊目录计数的请求序号:刷新后迟到的旧结果不能覆盖新数量。 */
|
|
2374
|
+
let virtualCountsSeq = 0;
|
|
2364
2375
|
let tagsInflight = null;
|
|
2365
2376
|
let searchTimer = null;
|
|
2366
2377
|
let toastTimer = null;
|
|
@@ -2419,6 +2430,25 @@ function selectionQuery() {
|
|
|
2419
2430
|
return { collectionKey: collection.key };
|
|
2420
2431
|
}
|
|
2421
2432
|
/**
|
|
2433
|
+
* 后台补「我的出版物 / 未分类条目 / 回收站」的数量。
|
|
2434
|
+
*
|
|
2435
|
+
* 复用条目列表接口,只取一条读总数;不阻塞分类树渲染。单项失败保留上一次
|
|
2436
|
+
* 成功的值(如果还没有则继续不显示),刷新时靠序号丢掉迟到的旧结果。
|
|
2437
|
+
*/
|
|
2438
|
+
function loadVirtualCounts() {
|
|
2439
|
+
const seq = ++virtualCountsSeq;
|
|
2440
|
+
for (const scope of VIRTUAL_COUNT_SCOPES) fetchItems({
|
|
2441
|
+
scope,
|
|
2442
|
+
limit: 1
|
|
2443
|
+
}).then((data) => {
|
|
2444
|
+
if (seq !== virtualCountsSeq) return;
|
|
2445
|
+
patch({ virtualCounts: {
|
|
2446
|
+
...state.virtualCounts,
|
|
2447
|
+
[scope]: data.total
|
|
2448
|
+
} });
|
|
2449
|
+
}).catch(() => {});
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2422
2452
|
* 拉取状态与分类树。
|
|
2423
2453
|
*
|
|
2424
2454
|
* 成功后按 key 保留原选择(真实分类被删则回到文库根),再重拉条目列表;
|
|
@@ -2454,11 +2484,12 @@ function loadTree(force = false) {
|
|
|
2454
2484
|
expanded,
|
|
2455
2485
|
selectedCollection: selected
|
|
2456
2486
|
});
|
|
2487
|
+
loadVirtualCounts();
|
|
2457
2488
|
saveTreeState();
|
|
2458
2489
|
reloadItems({ reset: true });
|
|
2459
2490
|
loadTagUsage();
|
|
2460
2491
|
} catch (error) {
|
|
2461
|
-
patch({ treeError: errorMessage$
|
|
2492
|
+
patch({ treeError: errorMessage$5(error) });
|
|
2462
2493
|
} finally {
|
|
2463
2494
|
patch({ treeLoading: false });
|
|
2464
2495
|
treeInflight = null;
|
|
@@ -2534,7 +2565,7 @@ function loadTags(force = false) {
|
|
|
2534
2565
|
tagsError: null
|
|
2535
2566
|
});
|
|
2536
2567
|
} catch (error) {
|
|
2537
|
-
patch({ tagsError: errorMessage$
|
|
2568
|
+
patch({ tagsError: errorMessage$5(error) });
|
|
2538
2569
|
} finally {
|
|
2539
2570
|
patch({ tagsLoading: false });
|
|
2540
2571
|
tagsInflight = null;
|
|
@@ -2594,9 +2625,12 @@ function reloadItems(options) {
|
|
|
2594
2625
|
patch({ itemsLoading: true });
|
|
2595
2626
|
const recent = isRecentSelection(state.selectedCollection);
|
|
2596
2627
|
const tags = recent ? [] : [...state.selectedTags];
|
|
2628
|
+
const query = state.query.trim();
|
|
2629
|
+
const selectedScope = state.selectedCollection?.scope;
|
|
2630
|
+
const countScope = !append && query === "" && tags.length === 0 && isVirtualCountScope(selectedScope) ? selectedScope : null;
|
|
2597
2631
|
fetchItems({
|
|
2598
2632
|
...selectionQuery(),
|
|
2599
|
-
q:
|
|
2633
|
+
q: query,
|
|
2600
2634
|
tags: tags.length === 0 ? void 0 : tags,
|
|
2601
2635
|
tagMode: tags.length === 0 ? void 0 : state.tagMode,
|
|
2602
2636
|
sort: recent || state.sort === "none" ? void 0 : "title",
|
|
@@ -2605,14 +2639,17 @@ function reloadItems(options) {
|
|
|
2605
2639
|
offset
|
|
2606
2640
|
}, controller.signal).then((data) => {
|
|
2607
2641
|
if (current !== itemsSeq) return;
|
|
2642
|
+
const virtualCounts = { ...state.virtualCounts };
|
|
2643
|
+
if (countScope !== null) virtualCounts[countScope] = data.total;
|
|
2608
2644
|
patch({
|
|
2609
2645
|
items: append ? [...state.items, ...data.items] : data.items,
|
|
2610
2646
|
itemsTotal: data.total,
|
|
2611
|
-
itemsError: null
|
|
2647
|
+
itemsError: null,
|
|
2648
|
+
virtualCounts
|
|
2612
2649
|
});
|
|
2613
2650
|
}).catch((error) => {
|
|
2614
2651
|
if (current !== itemsSeq || controller.signal.aborted) return;
|
|
2615
|
-
patch({ itemsError: errorMessage$
|
|
2652
|
+
patch({ itemsError: errorMessage$5(error) });
|
|
2616
2653
|
}).finally(() => {
|
|
2617
2654
|
if (current !== itemsSeq) return;
|
|
2618
2655
|
patch({ itemsLoading: false });
|
|
@@ -4241,7 +4278,7 @@ const EMPTY_DRAFT = {
|
|
|
4241
4278
|
pageLabel: "",
|
|
4242
4279
|
tags: ""
|
|
4243
4280
|
};
|
|
4244
|
-
function errorMessage$
|
|
4281
|
+
function errorMessage$4(error) {
|
|
4245
4282
|
return error instanceof Error ? error.message : String(error);
|
|
4246
4283
|
}
|
|
4247
4284
|
/**
|
|
@@ -4404,7 +4441,7 @@ function AnnotationList({ t, annotations, hasFulltext, truncated, filter, canWri
|
|
|
4404
4441
|
onChanged();
|
|
4405
4442
|
return true;
|
|
4406
4443
|
} catch (error) {
|
|
4407
|
-
setNotice(tpl(t("annotation.writeFailed"), { message: errorMessage$
|
|
4444
|
+
setNotice(tpl(t("annotation.writeFailed"), { message: errorMessage$4(error) }));
|
|
4408
4445
|
return false;
|
|
4409
4446
|
} finally {
|
|
4410
4447
|
setBusy(false);
|
|
@@ -5798,7 +5835,7 @@ const highlightLabelStyle = {
|
|
|
5798
5835
|
*/
|
|
5799
5836
|
/** 输入停止多久后自动写回。太短会把每次停顿都变成一次 PATCH。 */
|
|
5800
5837
|
const SAVE_DELAY = 800;
|
|
5801
|
-
function errorMessage$
|
|
5838
|
+
function errorMessage$3(error) {
|
|
5802
5839
|
return error instanceof Error ? error.message : String(error);
|
|
5803
5840
|
}
|
|
5804
5841
|
function NoteList({ t, notes, itemKey, canWrite, selfNote, composing, onComposingChange, onInsert, onChanged }) {
|
|
@@ -5844,7 +5881,7 @@ function NoteComposer({ t, itemKey, onCancel, onCreated }) {
|
|
|
5844
5881
|
onCreated();
|
|
5845
5882
|
onCancel();
|
|
5846
5883
|
} catch (error) {
|
|
5847
|
-
setNotice(tpl(t("note.writeFailed"), { message: errorMessage$
|
|
5884
|
+
setNotice(tpl(t("note.writeFailed"), { message: errorMessage$3(error) }));
|
|
5848
5885
|
} finally {
|
|
5849
5886
|
setBusy(false);
|
|
5850
5887
|
}
|
|
@@ -5925,7 +5962,7 @@ function NoteItem({ t, note, canWrite, onInsert, onChanged, onOpenEditor }) {
|
|
|
5925
5962
|
if (fresh.version > version.current) version.current = fresh.version;
|
|
5926
5963
|
if (alive.current) setRaw(fresh.html);
|
|
5927
5964
|
} catch (error) {
|
|
5928
|
-
if (alive.current) setNotice(tpl(t("note.readFailed"), { message: errorMessage$
|
|
5965
|
+
if (alive.current) setNotice(tpl(t("note.readFailed"), { message: errorMessage$3(error) }));
|
|
5929
5966
|
} finally {
|
|
5930
5967
|
if (alive.current) setLoading(false);
|
|
5931
5968
|
}
|
|
@@ -5987,7 +6024,7 @@ function NoteItem({ t, note, canWrite, onInsert, onChanged, onOpenEditor }) {
|
|
|
5987
6024
|
} catch (error) {
|
|
5988
6025
|
if (alive.current) {
|
|
5989
6026
|
setStatus("idle");
|
|
5990
|
-
setNotice(tpl(t("note.writeFailed"), { message: errorMessage$
|
|
6027
|
+
setNotice(tpl(t("note.writeFailed"), { message: errorMessage$3(error) }));
|
|
5991
6028
|
}
|
|
5992
6029
|
} finally {
|
|
5993
6030
|
inflight.current = false;
|
|
@@ -6037,7 +6074,7 @@ function NoteItem({ t, note, canWrite, onInsert, onChanged, onOpenEditor }) {
|
|
|
6037
6074
|
showToast(t("note.deleted"));
|
|
6038
6075
|
onChanged();
|
|
6039
6076
|
} catch (error) {
|
|
6040
|
-
if (alive.current) setNotice(tpl(t("note.writeFailed"), { message: errorMessage$
|
|
6077
|
+
if (alive.current) setNotice(tpl(t("note.writeFailed"), { message: errorMessage$3(error) }));
|
|
6041
6078
|
} finally {
|
|
6042
6079
|
if (alive.current) setRemoving(false);
|
|
6043
6080
|
}
|
|
@@ -39108,7 +39145,7 @@ const OUTLINE_SOURCE_LABEL = {
|
|
|
39108
39145
|
text: "outline.source.text",
|
|
39109
39146
|
webpage: "outline.source.text"
|
|
39110
39147
|
};
|
|
39111
|
-
function errorMessage$
|
|
39148
|
+
function errorMessage$2(error) {
|
|
39112
39149
|
return error instanceof Error ? error.message : String(error);
|
|
39113
39150
|
}
|
|
39114
39151
|
function attachmentSource(attachment) {
|
|
@@ -39303,7 +39340,7 @@ function ItemDetail({ t, detail, onInsertItem, onInsertExcerpt, onInsertTranslat
|
|
|
39303
39340
|
kind: "attachment",
|
|
39304
39341
|
page
|
|
39305
39342
|
}).catch((error) => {
|
|
39306
|
-
showToast(tpl(t("viewer.openFailed"), { message: errorMessage$
|
|
39343
|
+
showToast(tpl(t("viewer.openFailed"), { message: errorMessage$2(error) }));
|
|
39307
39344
|
});
|
|
39308
39345
|
}
|
|
39309
39346
|
/**
|
|
@@ -39676,7 +39713,7 @@ function itemKeyFromAddress(address) {
|
|
|
39676
39713
|
function parseItemKey(info) {
|
|
39677
39714
|
return itemKeyFromAddress(info.tab.navigation?.address || info.tab.contentId || "");
|
|
39678
39715
|
}
|
|
39679
|
-
function errorMessage(error) {
|
|
39716
|
+
function errorMessage$1(error) {
|
|
39680
39717
|
return error instanceof Error ? error.message : String(error);
|
|
39681
39718
|
}
|
|
39682
39719
|
const hintStyle$4 = {
|
|
@@ -39711,7 +39748,7 @@ function ZoteroItemPane(props) {
|
|
|
39711
39748
|
setLoading(false);
|
|
39712
39749
|
}).catch((err) => {
|
|
39713
39750
|
if (current !== seq.current || signal.aborted) return;
|
|
39714
|
-
setError(errorMessage(err));
|
|
39751
|
+
setError(errorMessage$1(err));
|
|
39715
39752
|
setLoading(false);
|
|
39716
39753
|
});
|
|
39717
39754
|
}, [
|
|
@@ -39744,7 +39781,7 @@ function ZoteroItemPane(props) {
|
|
|
39744
39781
|
if (source === "manual") showToast(t("detail.refreshed"));
|
|
39745
39782
|
} catch (err) {
|
|
39746
39783
|
if (current !== seq.current || signal.aborted) return;
|
|
39747
|
-
showToast(tpl(t(source === "manual" ? "detail.refreshFailedManual" : "detail.refreshFailed"), { message: errorMessage(err) }));
|
|
39784
|
+
showToast(tpl(t(source === "manual" ? "detail.refreshFailedManual" : "detail.refreshFailed"), { message: errorMessage$1(err) }));
|
|
39748
39785
|
}
|
|
39749
39786
|
}, [
|
|
39750
39787
|
itemKey,
|
|
@@ -39805,7 +39842,8 @@ function ZoteroItemPane(props) {
|
|
|
39805
39842
|
*
|
|
39806
39843
|
* - 行首三角箭头只管开合,且只在有子分类的行出现;点行体选中该范围。
|
|
39807
39844
|
* - 缩进按层级一次性算出(`depth * INDENT`),不再逐层叠加 margin。
|
|
39808
|
-
* -
|
|
39845
|
+
* - 真实分类与特殊目录(我的出版物 / 未分类条目 / 回收站)右侧显示条目数;
|
|
39846
|
+
* 右键真实分类 → 「添加整目录引用」。
|
|
39809
39847
|
* - 「我的文库」根节点是可选中的全库范围;其下挂三个虚拟分类
|
|
39810
39848
|
* (我的出版物 / 未分类条目 / 回收站),与 Zotero 左侧栏一致。
|
|
39811
39849
|
* - 顶部筛选框只筛目录名(同 Zotero 左栏):命中分类保留、非命中的祖先作为
|
|
@@ -40071,8 +40109,11 @@ function virtualCollection(node, t) {
|
|
|
40071
40109
|
function VirtualRows({ ctx, node, depth }) {
|
|
40072
40110
|
const collection = virtualCollection(node, ctx.t);
|
|
40073
40111
|
const selected = ctx.selectedCollectionKey === collection.key;
|
|
40074
|
-
/**
|
|
40075
|
-
|
|
40112
|
+
/**
|
|
40113
|
+
* 最近阅读读插件自己的进度记录;其余三个特殊目录读后台补的 total。
|
|
40114
|
+
* 数量异步返回,没取到时保持不显示,不让数字把树撑变形。
|
|
40115
|
+
*/
|
|
40116
|
+
const count = node.scope === "recent" ? ctx.recentCount : isVirtualCountScope(node.scope) ? ctx.virtualCounts[node.scope] : void 0;
|
|
40076
40117
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
40077
40118
|
onClick: () => ctx.select(collection),
|
|
40078
40119
|
style: {
|
|
@@ -40099,7 +40140,7 @@ function VirtualRows({ ctx, node, depth }) {
|
|
|
40099
40140
|
});
|
|
40100
40141
|
}
|
|
40101
40142
|
function CollectionTree(props) {
|
|
40102
|
-
const { t, libraryName, collections, treeQuery, selectedCollectionKey, recentCount, onSelectCollection, onInsertCollection } = props;
|
|
40143
|
+
const { t, libraryName, collections, treeQuery, selectedCollectionKey, recentCount, virtualCounts, onSelectCollection, onInsertCollection } = props;
|
|
40103
40144
|
/** 展开集合在 store 里(默认展开根节点),重挂面板后原样恢复。 */
|
|
40104
40145
|
const { expanded } = usePaneState();
|
|
40105
40146
|
const filter = treeQuery.trim().toLowerCase();
|
|
@@ -40114,6 +40155,7 @@ function CollectionTree(props) {
|
|
|
40114
40155
|
filter,
|
|
40115
40156
|
selectedCollectionKey,
|
|
40116
40157
|
recentCount,
|
|
40158
|
+
virtualCounts,
|
|
40117
40159
|
toggle: toggleTreeNode,
|
|
40118
40160
|
select: onSelectCollection,
|
|
40119
40161
|
onInsertCollection
|
|
@@ -40426,6 +40468,7 @@ const itemMetaAttachStyle = {
|
|
|
40426
40468
|
alignItems: "center",
|
|
40427
40469
|
gap: 2,
|
|
40428
40470
|
flex: "0 0 auto",
|
|
40471
|
+
marginLeft: "auto",
|
|
40429
40472
|
opacity: .85
|
|
40430
40473
|
};
|
|
40431
40474
|
const itemMetaTextStyle = {
|
|
@@ -41297,8 +41340,11 @@ function StatusDot({ ok, label }) {
|
|
|
41297
41340
|
} }), label]
|
|
41298
41341
|
});
|
|
41299
41342
|
}
|
|
41343
|
+
function errorMessage(error) {
|
|
41344
|
+
return error instanceof Error ? error.message : String(error);
|
|
41345
|
+
}
|
|
41300
41346
|
function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
|
|
41301
|
-
const { health, libraryName, collections, treeError, treeLoading, selectedCollection, query, items, itemsTotal, itemsLoading, itemsError, tags, tagsLoading, tagsError, treeQuery, recentCount, tagQuery, selectedTags, tagMode, tagUsage, tagUsageLoading, sort, selectedItemKeys } = usePaneState();
|
|
41347
|
+
const { health, libraryName, collections, treeError, treeLoading, selectedCollection, query, items, itemsTotal, itemsLoading, itemsError, tags, tagsLoading, tagsError, treeQuery, recentCount, virtualCounts, tagQuery, selectedTags, tagMode, tagUsage, tagUsageLoading, sort, selectedItemKeys } = usePaneState();
|
|
41302
41348
|
(0, react.useEffect)(() => {
|
|
41303
41349
|
loadTree();
|
|
41304
41350
|
}, []);
|
|
@@ -41308,6 +41354,20 @@ function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
|
|
|
41308
41354
|
*/
|
|
41309
41355
|
const recent = isRecentSelection(selectedCollection);
|
|
41310
41356
|
const insertion = useInsertion(t, sessions, sessionId, inputActions);
|
|
41357
|
+
/**
|
|
41358
|
+
* 跳回 Zotero 主窗口:真实分类带 key 跳到该分类(目录树 + 列表),
|
|
41359
|
+
* 文库根与「最近阅读」等虚拟分类没有 select URL,只唤起主窗口。
|
|
41360
|
+
*/
|
|
41361
|
+
function openCurrentInZotero() {
|
|
41362
|
+
const collection = selectedCollection;
|
|
41363
|
+
const key = collection !== null && collection.key !== "__library__" && collection.scope === void 0 ? collection.key : null;
|
|
41364
|
+
openInZotero(key === null ? { kind: "library" } : {
|
|
41365
|
+
kind: "collection",
|
|
41366
|
+
key
|
|
41367
|
+
}).catch((error) => {
|
|
41368
|
+
showToast(tpl(t("viewer.openFailed"), { message: errorMessage(error) }));
|
|
41369
|
+
});
|
|
41370
|
+
}
|
|
41311
41371
|
const [treeWidth, setTreeWidth] = (0, react.useState)(readTreeWidth);
|
|
41312
41372
|
const [splitHover, setSplitHover] = (0, react.useState)(false);
|
|
41313
41373
|
const bodyRef = (0, react.useRef)(null);
|
|
@@ -41374,6 +41434,18 @@ function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
|
|
|
41374
41434
|
size: "sm",
|
|
41375
41435
|
onClick: () => void loadTree(true),
|
|
41376
41436
|
children: t("action.refresh")
|
|
41437
|
+
}),
|
|
41438
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Button, {
|
|
41439
|
+
variant: "ghost",
|
|
41440
|
+
size: "sm",
|
|
41441
|
+
onClick: openCurrentInZotero,
|
|
41442
|
+
title: t("viewer.openInZotero"),
|
|
41443
|
+
style: {
|
|
41444
|
+
display: "inline-flex",
|
|
41445
|
+
alignItems: "center",
|
|
41446
|
+
gap: 5
|
|
41447
|
+
},
|
|
41448
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(OpenInZoteroIcon, { size: 12 }), t("viewer.openInZoteroShort")]
|
|
41377
41449
|
})
|
|
41378
41450
|
]
|
|
41379
41451
|
}),
|
|
@@ -41428,6 +41500,7 @@ function ZoteroPane({ t, inputActions, sessions, sessionId, onOpenItem }) {
|
|
|
41428
41500
|
treeQuery,
|
|
41429
41501
|
selectedCollectionKey: selectedCollection?.key ?? null,
|
|
41430
41502
|
recentCount,
|
|
41503
|
+
virtualCounts,
|
|
41431
41504
|
onSelectCollection: selectCollection,
|
|
41432
41505
|
onInsertCollection: insertion.insertCollection
|
|
41433
41506
|
})
|
package/lib/host/router.js
CHANGED
|
@@ -365,16 +365,8 @@ async function handleAttachmentInfo(res, params) {
|
|
|
365
365
|
};
|
|
366
366
|
ok(res, data);
|
|
367
367
|
}
|
|
368
|
-
/**
|
|
369
|
-
function
|
|
370
|
-
const command = process.platform === 'darwin'
|
|
371
|
-
? 'open'
|
|
372
|
-
: process.platform === 'win32'
|
|
373
|
-
? 'rundll32'
|
|
374
|
-
: 'xdg-open';
|
|
375
|
-
const args = process.platform === 'win32'
|
|
376
|
-
? ['url.dll,FileProtocolHandler', url]
|
|
377
|
-
: [url];
|
|
368
|
+
/** 分离进程启动外部命令;参数数组传递,不经过 shell。 */
|
|
369
|
+
function spawnDetached(command, args) {
|
|
378
370
|
return new Promise((resolvePromise, reject) => {
|
|
379
371
|
const child = spawn(command, args, { detached: true, stdio: 'ignore' });
|
|
380
372
|
child.once('spawn', () => {
|
|
@@ -386,6 +378,29 @@ function openExternal(url) {
|
|
|
386
378
|
});
|
|
387
379
|
});
|
|
388
380
|
}
|
|
381
|
+
/** 用系统默认处理器打开 `zotero://` URL。 */
|
|
382
|
+
function openExternal(url) {
|
|
383
|
+
const command = process.platform === 'darwin'
|
|
384
|
+
? 'open'
|
|
385
|
+
: process.platform === 'win32'
|
|
386
|
+
? 'rundll32'
|
|
387
|
+
: 'xdg-open';
|
|
388
|
+
const args = process.platform === 'win32'
|
|
389
|
+
? ['url.dll,FileProtocolHandler', url]
|
|
390
|
+
: [url];
|
|
391
|
+
return spawnDetached(command, args);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* 启动 / 激活 Zotero 主窗口:没有可定位的分类 key 时用(文库根、虚拟分类)。
|
|
395
|
+
* `zotero://select/library` 不是合法的 select URL,只能交给系统唤起应用。
|
|
396
|
+
*/
|
|
397
|
+
function activateZotero() {
|
|
398
|
+
if (process.platform === 'darwin')
|
|
399
|
+
return spawnDetached('open', ['-a', 'Zotero']);
|
|
400
|
+
if (process.platform === 'win32')
|
|
401
|
+
return spawnDetached('cmd.exe', ['/c', 'start', '', 'zotero']);
|
|
402
|
+
return spawnDetached('zotero', []);
|
|
403
|
+
}
|
|
389
404
|
/** 读取小请求体;超过上限直接拒绝,避免被大 body 拖住。 */
|
|
390
405
|
async function readBody(req, limit) {
|
|
391
406
|
const chunks = [];
|
|
@@ -402,9 +417,29 @@ async function readBody(req, limit) {
|
|
|
402
417
|
async function handleOpenInZotero(req, res) {
|
|
403
418
|
const record = await readJsonBody(req, 4096);
|
|
404
419
|
const key = typeof record.key === 'string' ? record.key : '';
|
|
405
|
-
const kind = record.kind === 'item'
|
|
406
|
-
|
|
407
|
-
|
|
420
|
+
const kind = record.kind === 'item'
|
|
421
|
+
|| record.kind === 'attachment'
|
|
422
|
+
|| record.kind === 'collection'
|
|
423
|
+
|| record.kind === 'library'
|
|
424
|
+
? record.kind
|
|
425
|
+
: null;
|
|
426
|
+
if (kind === null) {
|
|
427
|
+
fail(res, 400, 'bad_request', 'kind 不合法');
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (kind === 'library') {
|
|
431
|
+
await activateZotero();
|
|
432
|
+
ok(res, { opened: true });
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
if (!KEY_PATTERN.test(key)) {
|
|
436
|
+
fail(res, 400, 'bad_request', 'key 格式不合法');
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (kind === 'collection') {
|
|
440
|
+
// Zotero 主窗口选中该分类,右侧即为该分类的文献列表。
|
|
441
|
+
await openExternal(`zotero://select/library/collections/${key}`);
|
|
442
|
+
ok(res, { opened: true });
|
|
408
443
|
return;
|
|
409
444
|
}
|
|
410
445
|
let url = `zotero://select/library/items/${key}`;
|
package/lib/zotero/client.d.ts
CHANGED
|
@@ -188,6 +188,8 @@ export interface ListTagUsageOptions {
|
|
|
188
188
|
* 传多个 `collectionKeys` 时分目录扫描,并按条目 key 去重——同一篇条目可能
|
|
189
189
|
* 同时挂在父分类与子分类里,不能重复计数。超过 `USAGE_SCAN_MAX` 条的大范围
|
|
190
190
|
* 按前若干页截断,超大目录可能漏掉靠后的标签(本地 API 没有按分类列标签的端点)。
|
|
191
|
+
*
|
|
192
|
+
* 回收站走 `/items/trash/top`:不带 `/top` 会把子附件也扫进来,与列表口径不一致。
|
|
191
193
|
*/
|
|
192
194
|
export declare function listTagUsage(options: ListTagUsageOptions): Promise<ZoteroTags>;
|
|
193
195
|
export interface ListItemsOptions {
|
package/lib/zotero/client.js
CHANGED
|
@@ -512,6 +512,8 @@ const USAGE_SCAN_MAX = 3000;
|
|
|
512
512
|
* 传多个 `collectionKeys` 时分目录扫描,并按条目 key 去重——同一篇条目可能
|
|
513
513
|
* 同时挂在父分类与子分类里,不能重复计数。超过 `USAGE_SCAN_MAX` 条的大范围
|
|
514
514
|
* 按前若干页截断,超大目录可能漏掉靠后的标签(本地 API 没有按分类列标签的端点)。
|
|
515
|
+
*
|
|
516
|
+
* 回收站走 `/items/trash/top`:不带 `/top` 会把子附件也扫进来,与列表口径不一致。
|
|
515
517
|
*/
|
|
516
518
|
export async function listTagUsage(options) {
|
|
517
519
|
// 「最近阅读」没有可按分类扫描的端点,也没有必要:面板在选它时不请求标签用量。
|
|
@@ -523,7 +525,7 @@ export async function listTagUsage(options) {
|
|
|
523
525
|
const bases = options.scope === 'publications'
|
|
524
526
|
? [`${libraryBase()}/publications/items`]
|
|
525
527
|
: options.scope === 'trash'
|
|
526
|
-
? [`${libraryBase()}/items/trash`]
|
|
528
|
+
? [`${libraryBase()}/items/trash/top`]
|
|
527
529
|
: (options.collectionKeys ?? []).length > 0
|
|
528
530
|
? options.collectionKeys.map((key) => `${libraryBase()}/collections/${encode(key)}/items/top`)
|
|
529
531
|
: [`${libraryBase()}/items/top`];
|
|
@@ -631,12 +633,18 @@ function appendItemSort(params, options) {
|
|
|
631
633
|
params.set('sort', options.sort);
|
|
632
634
|
params.set('direction', options.direction === 'desc' ? 'desc' : 'asc');
|
|
633
635
|
}
|
|
634
|
-
/**
|
|
636
|
+
/**
|
|
637
|
+
* 范围内的顶层条目端点基址(条目列表与标签用量共用同一套范围规则)。
|
|
638
|
+
*
|
|
639
|
+
* 回收站必须用 `/items/trash/top`:Zotero 本地 API 的 `/items/trash` 会把
|
|
640
|
+
* 子附件一并列出,`Total-Results` 因此比客户端回收站的顶层条目数多(实测
|
|
641
|
+
* 126 = 94 顶层 + 32 子附件),列表里也会多出一批子附件行。
|
|
642
|
+
*/
|
|
635
643
|
function itemListBase(options) {
|
|
636
644
|
return options.scope === 'publications'
|
|
637
645
|
? `${libraryBase()}/publications/items`
|
|
638
646
|
: options.scope === 'trash'
|
|
639
|
-
? `${libraryBase()}/items/trash`
|
|
647
|
+
? `${libraryBase()}/items/trash/top`
|
|
640
648
|
: options.collectionKey
|
|
641
649
|
? `${libraryBase()}/collections/${encode(options.collectionKey)}/items/top`
|
|
642
650
|
: `${libraryBase()}/items/top`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-zotero",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "Map your Zotero library into DSH: let AI operate Zotero for you and help you read papers. Browse collections and tags in the sidebar, read PDFs with highlights in place, and cite excerpts, annotations, notes or whole items into the chat. The model works from the source text for reviews, comparisons and data extraction, and can also search and organize the library, import papers and attach translations back to items; first use needs the Zotero MCP plugin and the local API enabled.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh",
|