@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.
- package/lib/index.js +17 -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
|
-
|
|
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