dsh-plugin-zotero 0.3.0 → 0.4.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.
Files changed (214) hide show
  1. package/README.md +31 -20
  2. package/client/client.js +25683 -787
  3. package/client/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  4. package/client/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  5. package/client/pdfjs/cmaps/78-H.bcmap +0 -0
  6. package/client/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  7. package/client/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  8. package/client/pdfjs/cmaps/78-V.bcmap +0 -0
  9. package/client/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  10. package/client/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  11. package/client/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  12. package/client/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  13. package/client/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  14. package/client/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  15. package/client/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  16. package/client/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  17. package/client/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  18. package/client/pdfjs/cmaps/Add-H.bcmap +0 -0
  19. package/client/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  20. package/client/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  21. package/client/pdfjs/cmaps/Add-V.bcmap +0 -0
  22. package/client/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  23. package/client/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  24. package/client/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  25. package/client/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  26. package/client/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  27. package/client/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  28. package/client/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  29. package/client/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  30. package/client/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  31. package/client/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  32. package/client/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  33. package/client/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  34. package/client/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  35. package/client/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  36. package/client/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  37. package/client/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  38. package/client/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  39. package/client/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  40. package/client/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  41. package/client/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  42. package/client/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  43. package/client/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  44. package/client/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  45. package/client/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  46. package/client/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  47. package/client/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  48. package/client/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  49. package/client/pdfjs/cmaps/B5-H.bcmap +0 -0
  50. package/client/pdfjs/cmaps/B5-V.bcmap +0 -0
  51. package/client/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  52. package/client/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  53. package/client/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  54. package/client/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  55. package/client/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  56. package/client/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  57. package/client/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  58. package/client/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  59. package/client/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  60. package/client/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  61. package/client/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  62. package/client/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  63. package/client/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  64. package/client/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  65. package/client/pdfjs/cmaps/EUC-H.bcmap +0 -0
  66. package/client/pdfjs/cmaps/EUC-V.bcmap +0 -0
  67. package/client/pdfjs/cmaps/Ext-H.bcmap +0 -0
  68. package/client/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  69. package/client/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  70. package/client/pdfjs/cmaps/Ext-V.bcmap +0 -0
  71. package/client/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  72. package/client/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  73. package/client/pdfjs/cmaps/GB-H.bcmap +4 -0
  74. package/client/pdfjs/cmaps/GB-V.bcmap +0 -0
  75. package/client/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  76. package/client/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  77. package/client/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  78. package/client/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  79. package/client/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  80. package/client/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  81. package/client/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  82. package/client/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  83. package/client/pdfjs/cmaps/GBT-H.bcmap +0 -0
  84. package/client/pdfjs/cmaps/GBT-V.bcmap +0 -0
  85. package/client/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  86. package/client/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  87. package/client/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  88. package/client/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  89. package/client/pdfjs/cmaps/H.bcmap +0 -0
  90. package/client/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  91. package/client/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  92. package/client/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  93. package/client/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  94. package/client/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  95. package/client/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  96. package/client/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  97. package/client/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  98. package/client/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  99. package/client/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  100. package/client/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  101. package/client/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  102. package/client/pdfjs/cmaps/Hankaku.bcmap +0 -0
  103. package/client/pdfjs/cmaps/Hiragana.bcmap +0 -0
  104. package/client/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  105. package/client/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  106. package/client/pdfjs/cmaps/KSC-H.bcmap +0 -0
  107. package/client/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  108. package/client/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  109. package/client/pdfjs/cmaps/KSC-V.bcmap +0 -0
  110. package/client/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  111. package/client/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  112. package/client/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  113. package/client/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  114. package/client/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  115. package/client/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  116. package/client/pdfjs/cmaps/Katakana.bcmap +0 -0
  117. package/client/pdfjs/cmaps/LICENSE +36 -0
  118. package/client/pdfjs/cmaps/NWP-H.bcmap +0 -0
  119. package/client/pdfjs/cmaps/NWP-V.bcmap +0 -0
  120. package/client/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  121. package/client/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  122. package/client/pdfjs/cmaps/Roman.bcmap +0 -0
  123. package/client/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  124. package/client/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  125. package/client/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  126. package/client/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  127. package/client/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  128. package/client/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  129. package/client/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  130. package/client/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  131. package/client/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  132. package/client/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  133. package/client/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  134. package/client/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  135. package/client/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  136. package/client/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  137. package/client/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  138. package/client/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  139. package/client/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  140. package/client/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  141. package/client/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  142. package/client/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  143. package/client/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  144. package/client/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  145. package/client/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  146. package/client/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  147. package/client/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  148. package/client/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  149. package/client/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  150. package/client/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  151. package/client/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  152. package/client/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  153. package/client/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  154. package/client/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  155. package/client/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  156. package/client/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  157. package/client/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  158. package/client/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  159. package/client/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  160. package/client/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  161. package/client/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  162. package/client/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  163. package/client/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  164. package/client/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  165. package/client/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  166. package/client/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  167. package/client/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  168. package/client/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  169. package/client/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  170. package/client/pdfjs/cmaps/V.bcmap +0 -0
  171. package/client/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  172. package/client/pdfjs/pdf.worker.min.mjs +29 -0
  173. package/client/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  174. package/client/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  175. package/client/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  176. package/client/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  177. package/client/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  178. package/client/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  179. package/client/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  180. package/client/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  181. package/client/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  182. package/client/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  183. package/client/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  184. package/client/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  185. package/client/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  186. package/client/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  187. package/client/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  188. package/client/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  189. package/client/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  190. package/client/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  191. package/client/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  192. package/client/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  193. package/client/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  194. package/client/pdfjs/wasm/LICENSE_QCMS +21 -0
  195. package/client/pdfjs/wasm/jbig2.wasm +0 -0
  196. package/client/pdfjs/wasm/jbig2_nowasm_fallback.js +15 -0
  197. package/client/pdfjs/wasm/openjpeg.wasm +0 -0
  198. package/client/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
  199. package/client/pdfjs/wasm/qcms_bg.wasm +0 -0
  200. package/client/pdfjs/wasm/quickjs-eval.js +16 -0
  201. package/client/pdfjs/wasm/quickjs-eval.wasm +0 -0
  202. package/lib/host/router.d.ts +1 -0
  203. package/lib/host/router.js +163 -5
  204. package/lib/host/static.d.ts +9 -0
  205. package/lib/host/static.js +100 -0
  206. package/lib/index.js +7 -1
  207. package/lib/zotero/annotations.d.ts +6 -1
  208. package/lib/zotero/annotations.js +6 -1
  209. package/lib/zotero/client.d.ts +12 -2
  210. package/lib/zotero/client.js +113 -5
  211. package/lib/zotero/config.d.ts +4 -0
  212. package/lib/zotero/config.js +4 -0
  213. package/lib/zotero/types.d.ts +22 -2
  214. package/package.json +3 -2
Binary file
@@ -0,0 +1,16 @@
1
+ /* THIS FILE IS GENERATED - DO NOT EDIT */
2
+ async function QuickJS(moduleArg={}){var moduleRtn;var e=moduleArg,aa=import.meta.url,h="",m;try{h=(new URL(".",aa)).href}catch{}m=async a=>{a=await fetch(a,{credentials:"same-origin"});if(a.ok)return a.arrayBuffer();throw Error(a.status+" : "+a.url);};var q=console.error.bind(console),r,t=!1,u,v,w,x=!1;function y(){var a=z.buffer;A=new Int8Array(a);new Int16Array(a);B=new Uint8Array(a);new Uint16Array(a);C=new Int32Array(a);D=new Uint32Array(a);new Float32Array(a);new Float64Array(a);new BigInt64Array(a);new BigUint64Array(a)}
3
+ function E(a){e.onAbort?.(a);a=`Aborted(${a})`;q(a);t=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");w?.(a);throw a;}var F;async function ba(a){if(!r)try{var b=await m(a);return new Uint8Array(b)}catch{}if(a==F&&r)a=new Uint8Array(r);else throw"both async and sync fetching of the wasm failed";return a}async function ca(a,b){try{var c=await ba(a);return await WebAssembly.instantiate(c,b)}catch(d){q(`failed to asynchronously prepare wasm: ${d}`),E(d)}}
4
+ async function da(a){var b=F;if(!r)try{var c=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(c,a)}catch(d){q(`wasm streaming compile failed: ${d}`),q("falling back to ArrayBuffer instantiation")}return ca(b,a)}class G{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
5
+ var C,A,D,B,H=a=>{for(;a.length>0;)a.shift()(e)},I=[],J=[],ea=()=>{var a=e.preRun.shift();J.push(a)},K=!0,L=0,fa=[0,31,60,91,121,152,182,213,244,274,305,335],ha=[0,31,59,90,120,151,181,212,243,273,304,334],M={},N=a=>{if(!(a instanceof G||a=="unwind"))throw a;},O=a=>{u=a;K||L>0||(e.onExit?.(a),t=!0);throw new G(a);},ia=a=>{if(!t)try{a()}catch(b){N(b)}finally{if(!(K||L>0))try{u=a=u,O(a)}catch(b){N(b)}}},P=(a,b,c)=>{var d=B;if(c>0){c=b+c-1;for(var g=0;g<a.length;++g){var f=a.codePointAt(g);if(f<=127){if(b>=
6
+ c)break;d[b++]=f}else if(f<=2047){if(b+1>=c)break;d[b++]=192|f>>6;d[b++]=128|f&63}else if(f<=65535){if(b+2>=c)break;d[b++]=224|f>>12;d[b++]=128|f>>6&63;d[b++]=128|f&63}else{if(b+3>=c)break;d[b++]=240|f>>18;d[b++]=128|f>>12&63;d[b++]=128|f>>6&63;d[b++]=128|f&63;g++}}d[b]=0}},ja=new TextDecoder,Q=a=>{if(a){for(var b=a,c=B,d=b+void 0;c[b]&&!(b>=d);)++b;a=ja.decode(B.subarray(a,b))}else a="";return a},R=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);d<=127?b++:d<=2047?b+=2:d>=55296&&d<=57343?
7
+ (b+=4,++c):b+=3}return b},T=a=>{var b=R(a)+1,c=S(b);c&&P(a,c,b);return c};function U(){}var la=(a,b,c,d)=>{var g={string:k=>{var n=0;if(k!==null&&k!==void 0&&k!==0){n=R(k)+1;var X=V(n);P(k,X,n);n=X}return n},array:k=>{var n=V(k.length);A.set(k,n);return n}};a=e["_"+a];var f=[],p=0;if(d)for(var l=0;l<d.length;l++){var Y=g[c[l]];Y?(p===0&&(p=W()),f[l]=Y(d[l])):f[l]=d[l]}c=a(...f);return c=function(k){p!==0&&ka(p);return b==="string"?Q(k):b==="boolean"?!!k:k}(c)};
8
+ U=(a,b,c)=>{a=Q(a);b=b!==null?JSON.parse(Q(b)):[];try{let d=e.externalCall(a,b);return d?T(d):null}catch(d){return e.HEAPU8[c]=1,T(d.message)}};e.noExitRuntime&&(K=e.noExitRuntime);e.printErr&&(q=e.printErr);e.wasmBinary&&(r=e.wasmBinary);if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.shift()();e.ccall=la;e.cwrap=(a,b,c,d)=>{var g=!c||c.every(f=>f==="number"||f==="boolean");return b!=="string"&&g&&!d?e["_"+a]:(...f)=>la(a,b,c,f,d)};
9
+ e.stringToNewUTF8=T;
10
+ var S,ma,ka,V,W,z,na={e:()=>E(""),a:()=>{K=!1;L=0},b:function(a,b){a=a<-9007199254740992||a>9007199254740992?NaN:Number(a);a=new Date(a*1E3);C[b>>2]=a.getSeconds();C[b+4>>2]=a.getMinutes();C[b+8>>2]=a.getHours();C[b+12>>2]=a.getDate();C[b+16>>2]=a.getMonth();C[b+20>>2]=a.getFullYear()-1900;C[b+24>>2]=a.getDay();var c=a.getFullYear();C[b+28>>2]=(c%4!==0||c%100===0&&c%400!==0?ha:fa)[a.getMonth()]+a.getDate()-1|0;C[b+36>>2]=-(a.getTimezoneOffset()*60);c=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();
11
+ var d=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();C[b+32>>2]=(c!=d&&a.getTimezoneOffset()==Math.min(d,c))|0},i:(a,b)=>{M[a]&&(clearTimeout(M[a].id),delete M[a]);if(!b)return 0;var c=setTimeout(()=>{delete M[a];ia(()=>ma(a,performance.now()))},b);M[a]={id:c,A:b};return 0},c:(a,b,c,d)=>{var g=(new Date).getFullYear(),f=(new Date(g,0,1)).getTimezoneOffset();g=(new Date(g,6,1)).getTimezoneOffset();D[a>>2]=Math.max(f,g)*60;C[b>>2]=Number(f!=g);b=p=>{var l=Math.abs(p);return`UTC${p>=0?"-":"+"}${String(Math.floor(l/
12
+ 60)).padStart(2,"0")}${String(l%60).padStart(2,"0")}`};a=b(f);b=b(g);g<f?(P(a,c,17),P(b,d,17)):(P(a,d,17),P(b,c,17))},g:U,f:function(a,b){a=Q(a);try{var c=window.JSON.parse(a)}catch(d){c=a}b!==0?window.alert(a):window.console.log("DUMP",c)},d:()=>Date.now(),j:a=>{var b=B.length;a>>>=0;if(a>2147483648)return!1;for(var c=1;c<=4;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(2147483648,Math.ceil(Math.max(a,d)/65536)*65536)-z.buffer.byteLength+65535)/65536|0;try{z.grow(d);y();var g=1;
13
+ break a}catch(f){}g=void 0}if(g)return!0}return!1},m:function(a){a=Q(a);window.console.log(a)},h:function(a){a=Q(a);return Date.parse(a)},l:function(a,b,c,d){a=Q(a);b=Q(b);c=Q(c);c=`Quickjs -- ${a}: ${b}\n${c}`;d!==0?window.alert(c):window.console.error(c)},k:O},Z;
14
+ Z=await (async function(){function a(c){c=Z=c.exports;e._evalInSandbox=c.p;e._nukeSandbox=c.q;e._init=c.r;e._commFun=c.s;e._dumpMemoryUse=c.t;S=c.u;e._free=c.v;ma=c.w;ka=c.x;V=c.y;W=c.z;z=c.n;y();return Z}var b={a:na};if(e.instantiateWasm)return new Promise(c=>{e.instantiateWasm(b,(d,g)=>{c(a(d,g))})});F??=e.locateFile?e.locateFile?e.locateFile("quickjs-eval.wasm",h):h+"quickjs-eval.wasm":(new URL("quickjs-eval.wasm",import.meta.url)).href;return function(c){return a(c.instance)}(await da(b))}());
15
+ (function(){function a(){e.calledRun=!0;if(!t){x=!0;Z.o();v?.(e);e.onRuntimeInitialized?.();if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();I.push(b)}H(I)}}if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ea();H(J);e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1);a()},1)):a()})();x?moduleRtn=e:moduleRtn=new Promise((a,b)=>{v=a;w=b});
16
+ ;return moduleRtn}export default QuickJS;
@@ -23,5 +23,6 @@ export interface HandlerDeps {
23
23
  */
24
24
  syncTools?: () => Promise<zotero.McpToolInfo[]>;
25
25
  }
26
+ export declare function isTrusted(req: IncomingMessage): boolean;
26
27
  /** 构造挂在 `webServer` 上的前缀路由处理器。 */
27
28
  export declare function createHandler(deps?: HandlerDeps): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
@@ -5,6 +5,8 @@
5
5
  * 信任栅栏:拒绝 `sec-fetch-site: cross-site`,且 Host 头必须是回环地址
6
6
  * (防御 DNS rebinding)。只读端点,无需会话 cookie。
7
7
  */
8
+ import { spawn } from 'node:child_process';
9
+ import { createReadStream } from 'node:fs';
8
10
  import * as zotero from '../zotero/client.js';
9
11
  import { ZoteroError } from '../zotero/client.js';
10
12
  import { DEFAULT_LIMIT, getSettings, ROUTE_PREFIX } from '../zotero/config.js';
@@ -16,7 +18,7 @@ function isLoopbackHost(hostHeader) {
16
18
  const host = hostHeader.replace(/:\d+$/u, '').toLowerCase();
17
19
  return host === 'localhost' || host === '127.0.0.1' || host === '[::1]' || host === '::1';
18
20
  }
19
- function isTrusted(req) {
21
+ export function isTrusted(req) {
20
22
  const site = req.headers['sec-fetch-site'];
21
23
  if (typeof site === 'string' && site.toLowerCase() === 'cross-site')
22
24
  return false;
@@ -156,13 +158,157 @@ async function handleCollectionBib(res, params) {
156
158
  const data = await zotero.getCollectionBib(key, style);
157
159
  ok(res, data);
158
160
  }
161
+ /** Zotero key:8 位,字母表排除了易混淆的 0 / 1 / O。 */
162
+ const KEY_PATTERN = /^[23456789ABCDEFGHIJKLMNPQRSTUVWXYZ]{8}$/u;
163
+ /** 允许直接流式读取的附件类型;后续加 Word 等格式只需在此追加。 */
164
+ const SERVABLE_TYPES = new Set(['application/pdf']);
165
+ /** 只支持单段 Range;`null` 表示无 Range,`'invalid'` 表示应回 416。 */
166
+ function parseRange(header, size) {
167
+ if (header === undefined || header.trim() === '')
168
+ return null;
169
+ const match = /^bytes=(\d*)-(\d*)$/u.exec(header.trim());
170
+ if (match === null)
171
+ return 'invalid';
172
+ const rawStart = match[1] ?? '';
173
+ const rawEnd = match[2] ?? '';
174
+ if (rawStart === '' && rawEnd === '')
175
+ return 'invalid';
176
+ let start;
177
+ let end;
178
+ if (rawStart === '') {
179
+ const suffix = Number.parseInt(rawEnd, 10);
180
+ if (!Number.isFinite(suffix) || suffix <= 0)
181
+ return 'invalid';
182
+ start = Math.max(0, size - suffix);
183
+ end = size - 1;
184
+ }
185
+ else {
186
+ start = Number.parseInt(rawStart, 10);
187
+ end = rawEnd === '' ? size - 1 : Number.parseInt(rawEnd, 10);
188
+ }
189
+ if (!Number.isFinite(start) || !Number.isFinite(end) || start >= size || start > end)
190
+ return 'invalid';
191
+ return { start, end: Math.min(end, size - 1) };
192
+ }
193
+ /** RFC 5987 的 `filename*` 编码。 */
194
+ function encodeFilename(filename) {
195
+ return encodeURIComponent(filename).replace(/['()*]/gu, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
196
+ }
197
+ async function handleFile(req, res, params) {
198
+ const key = params.get('key') ?? '';
199
+ if (!KEY_PATTERN.test(key)) {
200
+ fail(res, 400, 'bad_request', '附件 key 格式不合法');
201
+ return;
202
+ }
203
+ const file = await zotero.getAttachmentFile(key);
204
+ const contentType = file.contentType.split(';')[0].trim().toLowerCase();
205
+ if (!SERVABLE_TYPES.has(contentType)) {
206
+ fail(res, 415, 'bad_request', `暂不支持预览 ${file.contentType || '该附件类型'}`);
207
+ return;
208
+ }
209
+ const range = parseRange(req.headers.range, file.size);
210
+ if (range === 'invalid') {
211
+ res.writeHead(416, {
212
+ 'content-range': `bytes */${file.size}`,
213
+ 'cache-control': 'no-store',
214
+ });
215
+ res.end();
216
+ return;
217
+ }
218
+ const headers = {
219
+ 'content-type': contentType,
220
+ 'content-disposition': `inline; filename*=UTF-8''${encodeFilename(file.filename)}`,
221
+ 'accept-ranges': 'bytes',
222
+ 'cache-control': 'no-store',
223
+ 'x-content-type-options': 'nosniff',
224
+ };
225
+ let stream;
226
+ if (range === null) {
227
+ headers['content-length'] = file.size;
228
+ res.writeHead(200, headers);
229
+ stream = createReadStream(file.path);
230
+ }
231
+ else {
232
+ headers['content-range'] = `bytes ${range.start}-${range.end}/${file.size}`;
233
+ headers['content-length'] = range.end - range.start + 1;
234
+ res.writeHead(206, headers);
235
+ stream = createReadStream(file.path, { start: range.start, end: range.end });
236
+ }
237
+ stream.on('error', () => res.destroy());
238
+ stream.pipe(res);
239
+ }
240
+ /** 用系统默认处理器打开 `zotero://` URL;参数数组传递,不经过 shell。 */
241
+ function openExternal(url) {
242
+ const command = process.platform === 'darwin'
243
+ ? 'open'
244
+ : process.platform === 'win32'
245
+ ? 'rundll32'
246
+ : 'xdg-open';
247
+ const args = process.platform === 'win32'
248
+ ? ['url.dll,FileProtocolHandler', url]
249
+ : [url];
250
+ return new Promise((resolvePromise, reject) => {
251
+ const child = spawn(command, args, { detached: true, stdio: 'ignore' });
252
+ child.once('spawn', () => {
253
+ child.unref();
254
+ resolvePromise();
255
+ });
256
+ child.once('error', (error) => {
257
+ reject(new ZoteroError('internal_error', `无法打开 Zotero:${error.message}`));
258
+ });
259
+ });
260
+ }
261
+ /** 读取小请求体;超过上限直接拒绝,避免被大 body 拖住。 */
262
+ async function readBody(req, limit) {
263
+ const chunks = [];
264
+ let size = 0;
265
+ for await (const chunk of req) {
266
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
267
+ size += buffer.length;
268
+ if (size > limit)
269
+ throw new ZoteroError('bad_request', '请求体过大');
270
+ chunks.push(buffer);
271
+ }
272
+ return Buffer.concat(chunks).toString('utf8');
273
+ }
274
+ async function handleOpenInZotero(req, res) {
275
+ let input;
276
+ try {
277
+ input = JSON.parse(await readBody(req, 4096));
278
+ }
279
+ catch (error) {
280
+ if (error instanceof ZoteroError)
281
+ throw error;
282
+ fail(res, 400, 'bad_request', '请求体不是合法 JSON');
283
+ return;
284
+ }
285
+ const record = (typeof input === 'object' && input !== null ? input : {});
286
+ const key = typeof record.key === 'string' ? record.key : '';
287
+ const kind = record.kind === 'item' || record.kind === 'attachment' ? record.kind : null;
288
+ if (!KEY_PATTERN.test(key) || kind === null) {
289
+ fail(res, 400, 'bad_request', 'key 或 kind 不合法');
290
+ return;
291
+ }
292
+ let url = `zotero://select/library/items/${key}`;
293
+ if (kind === 'attachment') {
294
+ if (record.page !== undefined
295
+ && (typeof record.page !== 'number'
296
+ || !Number.isInteger(record.page)
297
+ || record.page < 1
298
+ || record.page > 10000)) {
299
+ fail(res, 400, 'bad_request', 'page 必须是 1–10000 的整数');
300
+ return;
301
+ }
302
+ url = `zotero://open-pdf/library/items/${key}`;
303
+ if (record.page !== undefined)
304
+ url += `?page=${record.page}`;
305
+ }
306
+ await openExternal(url);
307
+ ok(res, { opened: true });
308
+ }
159
309
  /** 构造挂在 `webServer` 上的前缀路由处理器。 */
160
310
  export function createHandler(deps = {}) {
161
311
  return async (req, res) => {
162
- if (req.method !== 'GET') {
163
- fail(res, 405, 'bad_request', `仅支持 GET,收到 ${req.method ?? '未知'}`);
164
- return;
165
- }
166
312
  if (!isTrusted(req)) {
167
313
  fail(res, 403, 'bad_request', '拒绝非回环来源的请求');
168
314
  return;
@@ -173,6 +319,12 @@ export function createHandler(deps = {}) {
173
319
  return;
174
320
  }
175
321
  const action = url.pathname.slice(ROUTE_PREFIX.length);
322
+ const method = req.method ?? 'GET';
323
+ const allowedMethod = action === 'open-in-zotero' ? 'POST' : 'GET';
324
+ if (method !== allowedMethod) {
325
+ fail(res, 405, 'bad_request', `该端点仅支持 ${allowedMethod},收到 ${method}`);
326
+ return;
327
+ }
176
328
  try {
177
329
  switch (action) {
178
330
  case 'health':
@@ -196,6 +348,12 @@ export function createHandler(deps = {}) {
196
348
  case 'collection-bib':
197
349
  await handleCollectionBib(res, url.searchParams);
198
350
  return;
351
+ case 'file':
352
+ await handleFile(req, res, url.searchParams);
353
+ return;
354
+ case 'open-in-zotero':
355
+ await handleOpenInZotero(req, res);
356
+ return;
199
357
  case 'mcp-tools':
200
358
  await handleMcpTools(res, deps);
201
359
  return;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * PDF.js 静态资产:`GET /dsh-zotero/static/*`。
3
+ *
4
+ * 只服务 `client/pdfjs/` 下的白名单内容(Worker、cmaps、标准字体、wasm),
5
+ * 不做通用静态服务器。路径在 `path.resolve` 后必须仍落在资产根内,
6
+ * 因此 `..`、绝对路径、跨平台分隔符都穿不出去。
7
+ */
8
+ import type { IncomingMessage, ServerResponse } from 'node:http';
9
+ export declare function createStaticHandler(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * PDF.js 静态资产:`GET /dsh-zotero/static/*`。
3
+ *
4
+ * 只服务 `client/pdfjs/` 下的白名单内容(Worker、cmaps、标准字体、wasm),
5
+ * 不做通用静态服务器。路径在 `path.resolve` 后必须仍落在资产根内,
6
+ * 因此 `..`、绝对路径、跨平台分隔符都穿不出去。
7
+ */
8
+ import { createReadStream } from 'node:fs';
9
+ import { stat } from 'node:fs/promises';
10
+ import { extname, resolve, sep } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { STATIC_ROUTE_PREFIX } from '../zotero/config.js';
13
+ import { isTrusted } from './router.js';
14
+ /** `lib/host/static.js` → 包根 `client/pdfjs/`。 */
15
+ const ASSET_ROOT = fileURLToPath(new URL('../../client/pdfjs/', import.meta.url));
16
+ /** 白名单:根下单个 Worker 文件 + 三个资产目录。 */
17
+ const ALLOWED_DIRECTORIES = ['cmaps/', 'standard_fonts/', 'wasm/'];
18
+ const ALLOWED_FILES = new Set(['pdf.worker.min.mjs', 'pdf.worker.mjs']);
19
+ const MIME = {
20
+ '.mjs': 'text/javascript; charset=utf-8',
21
+ '.js': 'text/javascript; charset=utf-8',
22
+ '.wasm': 'application/wasm',
23
+ '.bcmap': 'application/octet-stream',
24
+ '.pfb': 'application/x-font-type1',
25
+ '.ttf': 'font/ttf',
26
+ '.otf': 'font/otf',
27
+ '.woff': 'font/woff',
28
+ '.woff2': 'font/woff2',
29
+ '.ttc': 'font/collection',
30
+ '.icc': 'application/vnd.iccprofile',
31
+ };
32
+ function fail(res, status, message) {
33
+ res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' });
34
+ res.end(message);
35
+ }
36
+ /** 校验并还原相对路径;非法返回 null。 */
37
+ function relativePath(pathname) {
38
+ if (!pathname.startsWith(STATIC_ROUTE_PREFIX))
39
+ return null;
40
+ let relative;
41
+ try {
42
+ relative = decodeURIComponent(pathname.slice(STATIC_ROUTE_PREFIX.length));
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ if (relative === '' || relative.includes('\\') || relative.includes('\0'))
48
+ return null;
49
+ const segments = relative.split('/');
50
+ if (segments.some((segment) => segment === '' || segment === '.' || segment === '..'))
51
+ return null;
52
+ if (!ALLOWED_FILES.has(relative) && !ALLOWED_DIRECTORIES.some((prefix) => relative.startsWith(prefix))) {
53
+ return null;
54
+ }
55
+ return relative;
56
+ }
57
+ export function createStaticHandler() {
58
+ return async (req, res) => {
59
+ if (req.method !== 'GET') {
60
+ fail(res, 405, '仅支持 GET');
61
+ return;
62
+ }
63
+ if (!isTrusted(req)) {
64
+ fail(res, 403, '拒绝非回环来源的请求');
65
+ return;
66
+ }
67
+ const url = new URL(req.url ?? '/', `http://${req.headers.host ?? '127.0.0.1'}`);
68
+ const relative = relativePath(url.pathname);
69
+ if (relative === null) {
70
+ fail(res, 404, '未知静态资源');
71
+ return;
72
+ }
73
+ const full = resolve(ASSET_ROOT, relative);
74
+ if (!full.startsWith(ASSET_ROOT.endsWith(sep) ? ASSET_ROOT : ASSET_ROOT + sep)) {
75
+ fail(res, 404, '未知静态资源');
76
+ return;
77
+ }
78
+ let stats;
79
+ try {
80
+ stats = await stat(full);
81
+ }
82
+ catch {
83
+ fail(res, 404, '静态资源不存在');
84
+ return;
85
+ }
86
+ if (!stats.isFile()) {
87
+ fail(res, 404, '静态资源不存在');
88
+ return;
89
+ }
90
+ res.writeHead(200, {
91
+ 'content-type': MIME[extname(full).toLowerCase()] ?? 'application/octet-stream',
92
+ 'content-length': stats.size,
93
+ 'cache-control': 'public, max-age=86400',
94
+ 'x-content-type-options': 'nosniff',
95
+ });
96
+ const stream = createReadStream(full);
97
+ stream.on('error', () => res.destroy());
98
+ stream.pipe(res);
99
+ };
100
+ }
package/lib/index.js CHANGED
@@ -16,8 +16,9 @@
16
16
  import Schema from '@deepseek-ai/schemastery';
17
17
  import { McpToolBridge } from './host/mcp-bridge.js';
18
18
  import { createHandler } from './host/router.js';
19
+ import { createStaticHandler } from './host/static.js';
19
20
  import { listMcpTools } from './zotero/client.js';
20
- import { DEFAULT_LIMIT, FULLTEXT_MAX_BYTES, MCP_PROBE_TIMEOUT_MS, MCP_URL, REQUEST_TIMEOUT_MS, ROUTE_MATCH, setSettingsReader, ZOTERO_BASE, } from './zotero/config.js';
21
+ import { DEFAULT_LIMIT, FULLTEXT_MAX_BYTES, MCP_PROBE_TIMEOUT_MS, MCP_URL, REQUEST_TIMEOUT_MS, ROUTE_MATCH, setSettingsReader, STATIC_ROUTE_MATCH, ZOTERO_BASE, } from './zotero/config.js';
21
22
  export const name = 'dsh-plugin-zotero';
22
23
  /**
23
24
  * 插件配置 schema(逐字段 volatile)。
@@ -72,5 +73,10 @@ export function apply(ctx, config) {
72
73
  syncTools: async () => (bridge ? bridge.sync() : listMcpTools()),
73
74
  });
74
75
  hostCtx.effect(() => webServer.register({ kind: 'prefix', path: ROUTE_MATCH, handler }), 'dsh-plugin-zotero: http routes');
76
+ hostCtx.effect(() => webServer.register({
77
+ kind: 'prefix',
78
+ path: STATIC_ROUTE_MATCH,
79
+ handler: createStaticHandler(),
80
+ }), 'dsh-plugin-zotero: static assets');
75
81
  });
76
82
  }
@@ -6,7 +6,7 @@
6
6
  * 通过 map 把折叠下标还原成原文下标。
7
7
  */
8
8
  import type { ZoteroFulltext } from './types.js';
9
- /** Host 侧归一化后的标注(已过滤为非高亮/划线之外的条目)。 */
9
+ /** Host 侧归一化后的标注。 */
10
10
  export interface RawAnnotation {
11
11
  key: string;
12
12
  attachmentKey: string;
@@ -17,6 +17,11 @@ export interface RawAnnotation {
17
17
  pageLabel: string;
18
18
  /** 零填充的 `annotationSortIndex`,可按字典序比较。 */
19
19
  sortIndex: string;
20
+ /** PDF 页位置;缺失或墨迹标注为 null。 */
21
+ position: {
22
+ pageIndex: number;
23
+ rects: [number, number, number, number][];
24
+ } | null;
20
25
  }
21
26
  /**
22
27
  * 为每条标注计算它在 `fulltext.content` 里的区间。
@@ -5,6 +5,8 @@
5
5
  * 这里做「去空白 + 全角 ASCII 转半角」的 1:1 折叠,再在折叠串上查找,
6
6
  * 通过 map 把折叠下标还原成原文下标。
7
7
  */
8
+ /** 可以锚定到全文纯文本的标注类型(其余类型只用于 PDF 坐标叠加)。 */
9
+ const TEXT_TYPES = new Set(['highlight', 'underline']);
8
10
  /** 空白与软连字符:PDF 抽取会插入,匹配时忽略。 */
9
11
  const IGNORED = /[\s\u00ad]/u;
10
12
  /** 单条标注最多收集多少个候选位置(防止单字标注把内存打满)。 */
@@ -66,7 +68,10 @@ export function anchorAnnotations(annotations, fulltext) {
66
68
  const attachmentKey = fulltext?.attachmentKey ?? '';
67
69
  let prevEnd = 0;
68
70
  return annotations.map((annotation) => {
69
- if (folded === null || annotation.attachmentKey !== attachmentKey || annotation.text === '') {
71
+ if (folded === null
72
+ || !TEXT_TYPES.has(annotation.type)
73
+ || annotation.attachmentKey !== attachmentKey
74
+ || annotation.text === '') {
70
75
  return { ...annotation, range: null };
71
76
  }
72
77
  const query = fold(annotation.text).text;
@@ -13,7 +13,7 @@
13
13
  * - `?include=bib` 会让响应**丢掉 `data`**,因此条目详情与 bib 必须分两次请求。
14
14
  */
15
15
  import { type RawAnnotation } from './annotations.js';
16
- import type { ApiErrorCode, ZoteroCollection, ZoteroFulltext, ZoteroHealth, ZoteroItemDetail, ZoteroItemScope, ZoteroItemSummary, ZoteroTags } from './types.js';
16
+ import type { ApiErrorCode, ZoteroAttachmentFile, ZoteroCollection, ZoteroFulltext, ZoteroHealth, ZoteroItemDetail, ZoteroItemScope, ZoteroItemSummary, ZoteroTags } from './types.js';
17
17
  /** 归一化后的 Zotero 访问错误。 */
18
18
  export declare class ZoteroError extends Error {
19
19
  readonly code: ApiErrorCode;
@@ -60,6 +60,8 @@ interface RawItemData {
60
60
  annotationColor?: string;
61
61
  annotationPageLabel?: string;
62
62
  annotationSortIndex?: string;
63
+ /** JSON 字符串:`{pageIndex, rects}`;缺失或墨迹标注没有。 */
64
+ annotationPosition?: string;
63
65
  dateModified?: string;
64
66
  }
65
67
  interface RawEnclosure {
@@ -156,7 +158,7 @@ export declare function listItems(options: ListItemsOptions): Promise<{
156
158
  /** 子条目(附件 / 笔记)。 */
157
159
  export declare function getItemChildren(key: string): Promise<RawItem[]>;
158
160
  /**
159
- * 条目下所有 PDF 附件上的高亮与划线。
161
+ * 条目下所有 PDF 附件上的标注。
160
162
  *
161
163
  * 必须显式带 `itemType=annotation`:实测 `/children` 不带参数时不返回标注。
162
164
  * 失败降级为空数组——标注是详情的附加信息,不能拖垮整个条目。
@@ -164,6 +166,14 @@ export declare function getItemChildren(key: string): Promise<RawItem[]>;
164
166
  export declare function getItemAnnotations(key: string): Promise<RawAnnotation[]>;
165
167
  /** 附件全文;仅附件条目可用。 */
166
168
  export declare function getItemFulltext(attachmentKey: string): Promise<ZoteroFulltext | null>;
169
+ /**
170
+ * 解析附件在磁盘上的真实路径。
171
+ *
172
+ * 路径只来自 Zotero 条目 JSON 的 `links.enclosure.href`(`file://` URL),
173
+ * 客户端传来的任何路径都不接受。`lstat` 拒绝目录与非普通文件;
174
+ * 链接附件(`linkMode: linked_file`)同样走这里,不限制必须在 storage 下。
175
+ */
176
+ export declare function getAttachmentFile(key: string): Promise<ZoteroAttachmentFile>;
167
177
  /** 单条条目的 CSL HTML(`format=bib`);失败返回 null。 */
168
178
  export declare function getItemBib(key: string, style: string): Promise<string | null>;
169
179
  /** 条目详情:元数据 + 附件 + 笔记 + 标注 + 首个可读附件全文 + CSL。 */
@@ -12,7 +12,9 @@
12
12
  * 要拿整目录引用必须走 `/items?itemKey=a,b&format=bib`(每批 ≤ 50)。
13
13
  * - `?include=bib` 会让响应**丢掉 `data`**,因此条目详情与 bib 必须分两次请求。
14
14
  */
15
+ import { lstat } from 'node:fs/promises';
15
16
  import { connect } from 'node:net';
17
+ import { fileURLToPath } from 'node:url';
16
18
  import { anchorAnnotations } from './annotations.js';
17
19
  import { getSettings, libraryBase, MCP_CALL_TIMEOUT_MS, zoteroProbeUrl, } from './config.js';
18
20
  /** 归一化后的 Zotero 访问错误。 */
@@ -86,6 +88,7 @@ function toAttachment(raw) {
86
88
  return {
87
89
  key: raw.key,
88
90
  title: attachmentTitle(raw),
91
+ filename: raw.data?.filename ?? '',
89
92
  contentType: raw.data?.contentType ?? '',
90
93
  // 本地 API 只在 links.enclosure.length 上暴露大小;缺失时记 0。
91
94
  size: raw.links?.enclosure?.length ?? 0,
@@ -339,6 +342,35 @@ export async function listCollections() {
339
342
  };
340
343
  });
341
344
  }
345
+ /** 条目详情里解析分类路径用;60s 内复用,避免每开一条文献都多打一次 Zotero。 */
346
+ let collectionCache = null;
347
+ const COLLECTION_CACHE_MS = 60_000;
348
+ async function cachedCollections() {
349
+ if (collectionCache !== null && Date.now() - collectionCache.at < COLLECTION_CACHE_MS) {
350
+ return collectionCache.collections;
351
+ }
352
+ const collections = await listCollections();
353
+ collectionCache = { at: Date.now(), collections };
354
+ return collections;
355
+ }
356
+ /** 分类 key → 完整路径名(父分类在前,用 ` / ` 连接)。 */
357
+ function collectionPaths(collections, keys) {
358
+ const byKey = new Map(collections.map((collection) => [collection.key, collection]));
359
+ const paths = [];
360
+ for (const key of keys) {
361
+ const parts = [];
362
+ const seen = new Set();
363
+ let current = byKey.get(key);
364
+ while (current !== undefined && !seen.has(current.key)) {
365
+ seen.add(current.key);
366
+ parts.unshift(current.name);
367
+ current = current.parentKey === false ? undefined : byKey.get(current.parentKey);
368
+ }
369
+ if (parts.length > 0)
370
+ paths.push(parts.join(' / '));
371
+ }
372
+ return paths;
373
+ }
342
374
  // ---- 标签 -------------------------------------------------------------------
343
375
  /** 标签分页大小(本地 API 上限 1000)与总量上限。 */
344
376
  const TAG_PAGE_SIZE = 1000;
@@ -546,12 +578,42 @@ export async function getItemChildren(key) {
546
578
  const { body } = await requestJson(`${libraryBase()}/items/${encode(key)}/children`);
547
579
  return Array.isArray(body) ? body : [];
548
580
  }
549
- /** 展示的标注类型:高亮与划线(Zotero 支持两者互转)。 */
550
- const ANNOTATION_TYPES = new Set(['highlight', 'underline']);
581
+ /**
582
+ * 展示的标注类型。`ink` 没有 rects,只能进列表;其余类型都可在 PDF 上叠加。
583
+ */
584
+ const ANNOTATION_TYPES = new Set(['highlight', 'underline', 'note', 'text', 'image', 'ink']);
551
585
  /** 标注分页大小(本地 API 单页上限 100)与总量上限。 */
552
586
  const ANNOTATION_PAGE_SIZE = 100;
553
587
  const ANNOTATION_MAX = 1000;
554
- /** 原始标注 → 展示用标注;非高亮/划线返回 null。 */
588
+ function isRect(value) {
589
+ return Array.isArray(value)
590
+ && value.length === 4
591
+ && value.every((item) => typeof item === 'number' && Number.isFinite(item));
592
+ }
593
+ /** `annotationPosition` 是 JSON 字符串;结构不符按「无位置」处理。 */
594
+ function toPosition(value) {
595
+ if (typeof value !== 'string' || value === '')
596
+ return null;
597
+ let parsed;
598
+ try {
599
+ parsed = JSON.parse(value);
600
+ }
601
+ catch {
602
+ return null;
603
+ }
604
+ if (typeof parsed !== 'object' || parsed === null)
605
+ return null;
606
+ const { pageIndex, rects } = parsed;
607
+ if (typeof pageIndex !== 'number' || !Number.isInteger(pageIndex) || pageIndex < 0)
608
+ return null;
609
+ if (!Array.isArray(rects))
610
+ return null;
611
+ const valid = rects.filter(isRect);
612
+ if (valid.length === 0)
613
+ return null;
614
+ return { pageIndex, rects: valid };
615
+ }
616
+ /** 原始标注 → 展示用标注;未知类型返回 null。 */
555
617
  function toAnnotation(raw) {
556
618
  const data = raw.data ?? {};
557
619
  const type = data.annotationType ?? '';
@@ -567,10 +629,11 @@ function toAnnotation(raw) {
567
629
  color: data.annotationColor ?? '',
568
630
  pageLabel: data.annotationPageLabel ?? '',
569
631
  sortIndex: data.annotationSortIndex ?? '',
632
+ position: toPosition(data.annotationPosition),
570
633
  };
571
634
  }
572
635
  /**
573
- * 条目下所有 PDF 附件上的高亮与划线。
636
+ * 条目下所有 PDF 附件上的标注。
574
637
  *
575
638
  * 必须显式带 `itemType=annotation`:实测 `/children` 不带参数时不返回标注。
576
639
  * 失败降级为空数组——标注是详情的附加信息,不能拖垮整个条目。
@@ -622,6 +685,48 @@ export async function getItemFulltext(attachmentKey) {
622
685
  fallback: false,
623
686
  };
624
687
  }
688
+ /**
689
+ * 解析附件在磁盘上的真实路径。
690
+ *
691
+ * 路径只来自 Zotero 条目 JSON 的 `links.enclosure.href`(`file://` URL),
692
+ * 客户端传来的任何路径都不接受。`lstat` 拒绝目录与非普通文件;
693
+ * 链接附件(`linkMode: linked_file`)同样走这里,不限制必须在 storage 下。
694
+ */
695
+ export async function getAttachmentFile(key) {
696
+ const { body: raw } = await requestJson(`${libraryBase()}/items/${encode(key)}`);
697
+ const data = raw.data ?? {};
698
+ if (data.itemType !== 'attachment') {
699
+ throw new ZoteroError('bad_request', `条目 ${key} 不是附件`);
700
+ }
701
+ const href = raw.links?.enclosure?.href ?? '';
702
+ if (href === '') {
703
+ throw new ZoteroError('zotero_not_found', `附件 ${key} 没有可读取的本地文件`);
704
+ }
705
+ let path;
706
+ try {
707
+ path = fileURLToPath(href);
708
+ }
709
+ catch {
710
+ throw new ZoteroError('zotero_not_found', `附件 ${key} 的文件地址无法解析`);
711
+ }
712
+ let stats;
713
+ try {
714
+ stats = await lstat(path);
715
+ }
716
+ catch {
717
+ throw new ZoteroError('zotero_not_found', `附件文件不存在:${path}`);
718
+ }
719
+ if (!stats.isFile()) {
720
+ throw new ZoteroError('zotero_not_found', `附件路径不是普通文件:${path}`);
721
+ }
722
+ return {
723
+ key,
724
+ path,
725
+ size: stats.size,
726
+ contentType: data.contentType ?? '',
727
+ filename: data.filename ?? attachmentTitle(raw),
728
+ };
729
+ }
625
730
  /**
626
731
  * 依次尝试候选附件的全文,返回第一份可用的。
627
732
  *
@@ -654,9 +759,10 @@ export async function getItemDetail(key, style) {
654
759
  const itemType = data.itemType ?? '';
655
760
  const isAttachment = itemType === 'attachment';
656
761
  // 顶层条目可能是附件本身(直接导入的 PDF),此时把自己也算作附件。
657
- const [children, rawAnnotations] = await Promise.all([
762
+ const [children, rawAnnotations, collections] = await Promise.all([
658
763
  isAttachment ? Promise.resolve([]) : getItemChildren(key),
659
764
  itemType === 'note' ? Promise.resolve([]) : getItemAnnotations(key),
765
+ cachedCollections().catch(() => []),
660
766
  ]);
661
767
  const childAttachments = children.filter((c) => c.data?.itemType === 'attachment');
662
768
  const attachments = isAttachment ? [toAttachment(raw), ...childAttachments.map(toAttachment)] : childAttachments.map(toAttachment);
@@ -687,6 +793,7 @@ export async function getItemDetail(key, style) {
687
793
  comment: annotation.comment,
688
794
  color: annotation.color,
689
795
  pageLabel: annotation.pageLabel,
796
+ position: annotation.position,
690
797
  range: annotation.range,
691
798
  }));
692
799
  return {
@@ -701,6 +808,7 @@ export async function getItemDetail(key, style) {
701
808
  abstract: data.abstractNote ?? '',
702
809
  tags: (data.tags ?? []).map((tag) => tag.tag ?? '').filter((tag) => tag !== ''),
703
810
  collections: data.collections ?? [],
811
+ collectionNames: collectionPaths(collections, data.collections ?? []),
704
812
  attachments,
705
813
  notes,
706
814
  annotations,
@@ -31,6 +31,10 @@ export declare const ROUTE_PREFIX = "/dsh-zotero/api/";
31
31
  * 匹配,带尾斜杠会变成 `.../api//health`,永远匹配不上。
32
32
  */
33
33
  export declare const ROUTE_MATCH = "/dsh-zotero/api";
34
+ /** PDF.js 静态资产路由;与 API 路由分开注册。 */
35
+ export declare const STATIC_ROUTE_MATCH = "/dsh-zotero/static";
36
+ /** 静态资产路由的剥离基准(带尾斜杠)。 */
37
+ export declare const STATIC_ROUTE_PREFIX = "/dsh-zotero/static/";
34
38
  /** 可在 dsh「插件」页里编辑的字段;默认值即上面的常量。 */
35
39
  export interface ZoteroSettings {
36
40
  zoteroBaseUrl: string;