@a9i5k4/dsh-literature 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/lib/index.js +17 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2072,13 +2072,23 @@ async function importDir(dir, { autoResolve = true } = {}) {
2072
2072
  skipped.push({ file: name2, reason: "duplicate" });
2073
2073
  continue;
2074
2074
  }
2075
+ let pdf = null;
2076
+ try {
2077
+ const content = await readFile3(abs);
2078
+ if (content.subarray(0, 5).equals(PDF_MAGIC2)) {
2079
+ pdf = await savePdfBuffer(provisional.key, content);
2080
+ }
2081
+ } catch (e) {
2082
+ warn(`copy pdf failed for ${name2}:`, e.message);
2083
+ }
2075
2084
  item = await putItem({
2076
2085
  ...provisional,
2077
2086
  kind: hit.kind,
2078
2087
  rawValue: hit.value,
2079
2088
  display: hit.value,
2080
2089
  title: provisional.title || hit.value,
2081
- state: "discovered",
2090
+ state: pdf ? "fetched" : "discovered",
2091
+ pdf,
2082
2092
  sourceFile: abs,
2083
2093
  createdAt: Date.now()
2084
2094
  });
@@ -2929,7 +2939,12 @@ async function handleEvents(req, res) {
2929
2939
  }
2930
2940
  }
2931
2941
  async function servePdf(req, res, key) {
2932
- const path = safePdfPath(key);
2942
+ let decoded = key;
2943
+ try {
2944
+ decoded = decodeURIComponent(key);
2945
+ } catch {
2946
+ }
2947
+ const path = safePdfPath(decoded);
2933
2948
  if (!path) {
2934
2949
  writeJson(res, 400, { error: "invalid key" });
2935
2950
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a9i5k4/dsh-literature",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "DSH Literature 文献侧窗:在 DeepSeek Harness 侧边栏识别 DOI/arXiv/标题、抓取元数据与全文、写入本地文献库或导出目录,并提供内置 PDF 阅读器(缩放/翻页/目录/搜索/高亮/笔记)。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",