fix local markdown attachment regressions
This commit is contained in:
@@ -979,6 +979,11 @@ function startTreeShellRuntime() {
|
||||
});
|
||||
if (!response.ok) return false;
|
||||
const nextState = parseTreeShellStateFromHtml(await response.text());
|
||||
document.documentElement.setAttribute(
|
||||
"data-mnote-local-folder-watch-applied",
|
||||
options.appliedValue || "projection",
|
||||
);
|
||||
document.documentElement.removeAttribute("data-mnote-local-folder-watch-disabled");
|
||||
return applyTreeShellStateSnapshot(nextState, options);
|
||||
};
|
||||
|
||||
@@ -988,6 +993,16 @@ function startTreeShellRuntime() {
|
||||
}, 80);
|
||||
};
|
||||
|
||||
let localFolderEventRefreshPending = false;
|
||||
const scheduleLocalFolderEventRefresh = (options = {}) => {
|
||||
if (localFolderEventRefreshPending) return;
|
||||
localFolderEventRefreshPending = true;
|
||||
window.setTimeout(() => {
|
||||
localFolderEventRefreshPending = false;
|
||||
void refreshLocalFolderSnapshot(options);
|
||||
}, 120);
|
||||
};
|
||||
|
||||
const addTreeItemLocally = (item) => {
|
||||
if (!item?.nodeId || itemById.has(item.nodeId)) return false;
|
||||
normalizedItems.push(item);
|
||||
@@ -1096,41 +1111,49 @@ function startTreeShellRuntime() {
|
||||
};
|
||||
|
||||
if (sourceKind === "local_folder" && rootUri) {
|
||||
let localWatchRevision = initialLocalWatchRevision;
|
||||
let localWatchRefreshTimer = 0;
|
||||
const refreshFromLocalWatch = () => {
|
||||
if (localWatchRefreshTimer) return;
|
||||
localWatchRefreshTimer = window.setTimeout(() => {
|
||||
localWatchRefreshTimer = 0;
|
||||
void refreshLocalFolderSnapshot();
|
||||
}, 180);
|
||||
let localFolderWatchRevision = initialLocalWatchRevision;
|
||||
const applyLocalFolderRevision = (revision) => {
|
||||
const nextRevision = normalizeText(revision);
|
||||
if (!nextRevision || nextRevision === localFolderWatchRevision) return false;
|
||||
localFolderWatchRevision = nextRevision;
|
||||
document.documentElement.setAttribute("data-mnote-tree-live-revision", nextRevision);
|
||||
return true;
|
||||
};
|
||||
const pollLocalFolderRevision = async () => {
|
||||
if (busy || document.hidden) return;
|
||||
const url = new URL("/api/tree/local-folder-watch", window.location.origin);
|
||||
url.searchParams.set("rootUri", rootUri);
|
||||
const response = await fetch(url.toString(), { headers: { "accept": "application/json" } });
|
||||
if (!response.ok) return;
|
||||
const payload = await response.json();
|
||||
const nextRevision =
|
||||
payload &&
|
||||
payload.result &&
|
||||
typeof payload.result.revision === "string"
|
||||
? payload.result.revision
|
||||
: "";
|
||||
if (!nextRevision) return;
|
||||
if (!localWatchRevision) {
|
||||
localWatchRevision = nextRevision;
|
||||
return;
|
||||
}
|
||||
if (nextRevision !== localWatchRevision) {
|
||||
localWatchRevision = nextRevision;
|
||||
refreshFromLocalWatch();
|
||||
}
|
||||
};
|
||||
window.setInterval(() => {
|
||||
void pollLocalFolderRevision();
|
||||
}, 1200);
|
||||
window.addEventListener("tree:snapshot", function(event) {
|
||||
const detail = event && event.detail ? event.detail : {};
|
||||
const payload = detail.payload || detail;
|
||||
if (!payload || payload.sourceKind !== "local_folder") return;
|
||||
if (!applyLocalFolderRevision(payload.revision || detail.revision)) return;
|
||||
scheduleLocalFolderEventRefresh({ appliedValue: "snapshot" });
|
||||
});
|
||||
window.addEventListener("tree:resync", function(event) {
|
||||
const detail = event && event.detail ? event.detail : {};
|
||||
const payload = detail.payload || detail;
|
||||
if (!payload || payload.sourceKind !== "local_folder") return;
|
||||
if (!applyLocalFolderRevision(payload.revision || detail.revision)) return;
|
||||
scheduleLocalFolderEventRefresh({ appliedValue: "resync" });
|
||||
});
|
||||
window.addEventListener("tree:local-folder-watch-batch", function(event) {
|
||||
const detail = event && event.detail ? event.detail : {};
|
||||
const payload = detail.payload || detail;
|
||||
if (!payload || payload.sourceKind !== "local_folder") return;
|
||||
if (!applyLocalFolderRevision(payload.revision || detail.revision)) return;
|
||||
scheduleLocalFolderEventRefresh({ appliedValue: "watch_batch" });
|
||||
});
|
||||
window.addEventListener("tree:error", function(event) {
|
||||
const detail = event && event.detail ? event.detail : {};
|
||||
const payload = detail.payload || detail;
|
||||
if (!payload || payload.sourceKind !== "local_folder") return;
|
||||
document.documentElement.setAttribute(
|
||||
"data-mnote-tree-live-error",
|
||||
normalizeText(payload.code || payload.error || payload.message, "tree_live_error"),
|
||||
);
|
||||
});
|
||||
const transport = document.documentElement.getAttribute("data-mnote-tree-live-transport") || "";
|
||||
if (transport !== "local-folder-events") {
|
||||
document.documentElement.setAttribute("data-mnote-local-folder-watch-applied", "static");
|
||||
document.documentElement.setAttribute("data-mnote-local-folder-watch-disabled", "events-required");
|
||||
}
|
||||
}
|
||||
|
||||
const readErrorMessage = async (response) => {
|
||||
|
||||
Reference in New Issue
Block a user