Skip to content

Commit de79b93

Browse files
committed
fix: Wrong graph path when working with multi-graph.
1 parent 3dad10e commit de79b93

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "logseq-plugin-image-uploader",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"main": "dist/index.html",
55
"scripts": {
66
"dev": "vite",

Diff for: src/main.tsx

+51-43
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,69 @@ import "@logseq/libs";
22
import { checkUpdates } from "./CheckUpdatesUtils";
33
import { checkAndUploadBlock } from "./ImageUploadUtils";
44

5-
async function main() {
6-
setTimeout(() => {
7-
checkUpdates();
8-
}, 5000);
9-
5+
async function getGraphPath() {
106
const graphInfo = await logseq.App.getCurrentGraph();
117
const graphPath = graphInfo?.path;
128
if (!graphPath) {
139
const errorMsg = "Failed to get graph root path.";
14-
console.error('Error:', errorMsg);
10+
console.error("Error:", errorMsg);
1511
logseq.App.showMsg(errorMsg, "error");
16-
return
17-
} else {
18-
// Adding a context menu item to upload images in the block.
19-
logseq.Editor.registerBlockContextMenuItem("Upload image", async (e) => {
20-
const block = await logseq.Editor.getBlock(e.uuid);
21-
if (block && block.content) {
12+
return;
13+
}
14+
return graphPath;
15+
}
16+
17+
async function main() {
18+
setTimeout(() => {
19+
checkUpdates();
20+
}, 5000);
21+
22+
// Adding a context menu item to upload images in the block.
23+
logseq.Editor.registerBlockContextMenuItem("Upload image", async (e) => {
24+
const block = await logseq.Editor.getBlock(e.uuid);
25+
if (block && block.content) {
26+
const graphPath = await getGraphPath();
27+
if (graphPath) {
2228
checkAndUploadBlock(block, graphPath);
2329
}
24-
})
30+
}
31+
});
2532

26-
// Adding pasting event listener to upload images in the block.
27-
// Note: Paste event won't trigger when pastring an image, so we're using the keydown event instead.
28-
parent.document.addEventListener("keydown", async (e) => {
29-
let autoUploading = logseq.settings?.autoUploading ?? true;
30-
if (!autoUploading) {
31-
return
32-
}
33-
34-
if (e.ctrlKey || e.metaKey) {
35-
if (e.code === "KeyV") {
36-
let currentBlock = await logseq.Editor.getCurrentBlock();
37-
if (currentBlock) {
38-
let uuid = currentBlock.uuid;
39-
let checkLater = function () {
40-
setTimeout(async () => {
41-
let isEditing = await logseq.Editor.checkEditing();
42-
if (typeof isEditing === "string" && isEditing === uuid) {
43-
// logseq.App.showMsg("Still editing, check it later.", "warning");
44-
checkLater();
45-
} else {
46-
let block = await logseq.Editor.getBlock(uuid);
47-
if (block && block.content) {
48-
// logseq.App.showMsg(block.content);
33+
// Adding pasting event listener to upload images in the block.
34+
// Note: Paste event won't trigger when pastring an image, so we're using the keydown event instead.
35+
parent.document.addEventListener("keydown", async (e) => {
36+
let autoUploading = logseq.settings?.autoUploading ?? true;
37+
if (!autoUploading) {
38+
return;
39+
}
40+
41+
if (e.ctrlKey || e.metaKey) {
42+
if (e.code === "KeyV") {
43+
let currentBlock = await logseq.Editor.getCurrentBlock();
44+
if (currentBlock) {
45+
let uuid = currentBlock.uuid;
46+
let checkLater = function () {
47+
setTimeout(async () => {
48+
let isEditing = await logseq.Editor.checkEditing();
49+
if (typeof isEditing === "string" && isEditing === uuid) {
50+
// logseq.App.showMsg("Still editing, check it later.", "warning");
51+
checkLater();
52+
} else {
53+
let block = await logseq.Editor.getBlock(uuid);
54+
if (block && block.content) {
55+
const graphPath = await getGraphPath();
56+
if (graphPath) {
4957
checkAndUploadBlock(block, graphPath);
5058
}
5159
}
52-
}, 1000);
53-
}
54-
checkLater();
55-
}
60+
}
61+
}, 1000);
62+
};
63+
checkLater();
5664
}
5765
}
58-
});
59-
}
66+
}
67+
});
6068
}
6169

62-
logseq.ready(main).catch(console.error);
70+
logseq.ready(main).catch(console.error);

0 commit comments

Comments
 (0)