修复无法获得pdf的问题
This commit is contained in:
@@ -19,28 +19,38 @@ export function normalizeExecutablePath(input: string): string {
|
||||
|
||||
/** Join path segments using Zotero PathUtils (cross-platform). */
|
||||
export function joinPath(...parts: string[]): string {
|
||||
return PathUtils.join(...parts.filter(Boolean));
|
||||
const filtered = parts.filter(Boolean);
|
||||
if (!filtered.length) return "";
|
||||
try {
|
||||
return PathUtils.join(...filtered);
|
||||
} catch (e) {
|
||||
ztoolkit.log("[ChatPapers] PathUtils.join failed", filtered, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/** Normalize a filesystem path for the current OS. */
|
||||
/** Normalize user-provided storage directory paths (prefs). */
|
||||
export function normalizeStoragePath(input: string): string {
|
||||
const trimmed = (input || "").trim();
|
||||
if (!trimmed) return "";
|
||||
const joined = trimmed.replace(/[\\/]+/g, "/");
|
||||
if (/^[A-Za-z]:\//.test(joined)) {
|
||||
const drive = joined.slice(0, 2);
|
||||
const rest = joined
|
||||
.slice(2)
|
||||
|
||||
const unified = trimmed.replace(/\\/g, "/").replace(/\/+/g, "/");
|
||||
|
||||
const winMatch = unified.match(/^([A-Za-z]:)(\/.*)?$/);
|
||||
if (winMatch) {
|
||||
const drive = winMatch[1];
|
||||
const rest = (winMatch[2] || "")
|
||||
.split("/")
|
||||
.filter((part) => part && part !== ".")
|
||||
.join("\\");
|
||||
return `${drive}\\${rest}`.replace(/\\+$/, "");
|
||||
return rest ? `${drive}\\${rest}` : drive;
|
||||
}
|
||||
return joined
|
||||
.split("/")
|
||||
.filter((part) => part && part !== ".")
|
||||
.join("/")
|
||||
.replace(/\/+$/, "");
|
||||
|
||||
const absolute = unified.startsWith("/");
|
||||
const parts = unified.split("/").filter((part) => part && part !== ".");
|
||||
let result = parts.join("/");
|
||||
if (absolute) result = `/${result}`;
|
||||
return result.replace(/\/+$/, "") || (absolute ? "/" : "");
|
||||
}
|
||||
|
||||
/** Safe single path segment for file or directory names (cross-platform). */
|
||||
|
||||
Reference in New Issue
Block a user