This commit is contained in:
windingwind 2023-09-11 16:12:12 +08:00
parent 912b6a088f
commit b292d97272
7 changed files with 29 additions and 13 deletions

View File

@ -21,7 +21,12 @@ import YAML = require("yamljs");
import { Root as HRoot, RootContent } from "hast";
import { Root as MRoot } from "mdast";
import { Nodes } from "hast-util-to-text/lib";
import { fileExists, formatPath, randomString } from "../../utils/str";
import {
fileExists,
formatPath,
jointPath,
randomString,
} from "../../utils/str";
import { parseCitationHTML } from "../../utils/citation";
import {
copyEmbeddedImagesInHTML,
@ -75,7 +80,7 @@ async function note2md(
await processN2MRehypeImageNodes(
getN2MRehypeImageNodes(rehype),
noteItem.libraryID,
formatPath(PathUtils.join(dir, "attachments")),
jointPath(dir, "attachments"),
options.skipSavingImages,
false,
NodeMode.direct,

View File

@ -1,5 +1,5 @@
import { showHintWithLink } from "../../utils/hint";
import { formatPath } from "../../utils/str";
import { formatPath, jointPath } from "../../utils/str";
export async function saveMD(
filename: string,
@ -30,7 +30,7 @@ export async function saveMD(
export async function syncMDBatch(saveDir: string, noteIds: number[]) {
const noteItems = Zotero.Items.get(noteIds);
await Zotero.File.createDirectoryIfMissingAsync(saveDir);
const attachmentsDir = formatPath(PathUtils.join(saveDir, "attachments"));
const attachmentsDir = jointPath(saveDir, "attachments");
const hasImage = noteItems.some((noteItem) =>
noteItem.getNote().includes("<img"),
);

View File

@ -22,7 +22,7 @@ export {
function initSyncList() {
const rawKeys = getPref("syncNoteIds") as string;
if (!rawKeys.startsWith("[") || !rawKeys.endsWith("]")) {
const keys = rawKeys.split(",").map((id) => parseInt(id));
const keys = rawKeys.split(",").map((id) => String(id));
setPref("syncNoteIds", JSON.stringify(keys));
}
addon.data.sync.data = new ztoolkit.LargePref(
@ -30,6 +30,9 @@ function initSyncList() {
`${config.prefsPrefix}.syncDetail-`,
"parser",
);
// Due to the bug in v1.1.4-22, the sync data may be corrupted
const keys = addon.data.sync.data?.getKeys().map((key) => String(key));
setPref("syncNoteIds", JSON.stringify(keys));
}
function getSyncNoteIds(): number[] {

View File

@ -184,7 +184,7 @@ async function callSyncing(
progress: 100,
});
} catch (e) {
ztoolkit.log(e);
ztoolkit.log("[BetterNotes Syncing Error]", e);
showHint(`Sync Error: ${String(e)}`);
} finally {
progress?.startCloseTimer(5000);

View File

@ -1,6 +1,6 @@
import { showHint } from "../../utils/hint";
import { getString } from "../../utils/locale";
import { formatPath, slice } from "../../utils/str";
import { formatPath, jointPath, slice } from "../../utils/str";
export async function showSyncInfo(noteId: number) {
const status = addon.api.sync.getSyncStatus(noteId);
@ -54,9 +54,7 @@ export async function showSyncInfo(noteId: number) {
.addButton(getString("syncInfo.reveal"), "reveal", {
noClose: true,
callback: (ev) => {
Zotero.File.reveal(
formatPath(PathUtils.join(status.path, status.filename)),
);
Zotero.File.reveal(jointPath(status.path, status.filename));
},
})
.addButton(getString("syncInfo.manager"), "manager", {

View File

@ -1,6 +1,7 @@
import { config } from "../../../package.json";
import { getLinkedNotesRecursively, getNoteLink } from "../../utils/link";
import { getString } from "../../utils/locale";
import { jointPath } from "../../utils/str";
import { isWindowAlive } from "../../utils/window";
export async function showSyncManager() {
@ -49,7 +50,7 @@ export async function showSyncManager() {
),
showHeader: true,
multiSelect: true,
staticColumns: true,
staticColumns: false,
disableFontSizeScaling: true,
})
.setProp("getRowCount", () => addon.data.sync.manager.data.length)
@ -128,7 +129,7 @@ function updateData() {
noteId: noteId,
noteName: Zotero.Items.get(noteId).getNoteTitle(),
lastSync: new Date(syncStatus.lastsync).toLocaleString(),
filePath: PathUtils.join(syncStatus.path, syncStatus.filename),
filePath: jointPath(syncStatus.path, syncStatus.filename),
};
});
}

View File

@ -83,7 +83,16 @@ export async function fileExists(path: string): Promise<boolean> {
// IOUtils.exists() will throw error if path is not valid
return await IOUtils.exists(formatPath(path));
} catch (e) {
ztoolkit.log(e);
ztoolkit.log("[fileExists]", e);
return false;
}
}
export function jointPath(...paths: string[]) {
try {
return formatPath(PathUtils.join(...paths));
} catch (e) {
ztoolkit.log("[jointPath]", e);
return "";
}
}