Skip to content

Commit 1c2965c

Browse files
committed
feat: Add hints - only support manually imported mode due to CORS restriction.
1 parent 2b90f34 commit 1c2965c

File tree

4 files changed

+819
-5
lines changed

4 files changed

+819
-5
lines changed

Diff for: README.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Navigate to the plugins dashboard: `t` `p`
1212
- Click the Load unpacked plugin button, then select the sample directory to load it
1313

14+
> Note: You can't use the plugin downloaded from marketplace due to CORS restriction. Please load it manually.
15+
1416
## How to use it?
1517

1618
Currently, we only support [PicGo](https://github.com/Molunerfinn/PicGo), so please open PicGo manually.

Diff for: package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "logseq-plugin-image-uploader",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"main": "dist/index.html",
55
"scripts": {
66
"dev": "vite",
@@ -9,11 +9,13 @@
99
"dependencies": {
1010
"@logseq/libs": "^0.0.1-alpha.33",
1111
"react": "^17.0.2",
12-
"react-dom": "^17.0.2"
12+
"react-dom": "^17.0.2",
13+
"semver": "^7.3.5"
1314
},
1415
"devDependencies": {
1516
"@types/react": "^17.0.33",
1617
"@types/react-dom": "^17.0.10",
18+
"@types/semver": "^7.3.9",
1719
"@vitejs/plugin-react": "1.1.3",
1820
"typescript": "4.5.4",
1921
"vite": "2.7.10"

Diff for: src/main.tsx

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import "@logseq/libs";
22
import { BlockEntity, PageEntity } from '@logseq/libs/dist/LSPlugin';
3+
import { gt } from "semver"
4+
5+
const currentVersion = "0.0.3";
36

47
async function uploadImage(url: string): Promise<string> {
5-
return url = await fetch("http://localhost:36677/upload", {
8+
return await fetch("http://localhost:36677/upload", {
69
method: "POST",
7-
mode: "no-cors",
810
body: JSON.stringify({ list: [url]})
911
})
1012
.then(res => res.json())
@@ -17,7 +19,7 @@ async function uploadImage(url: string): Promise<string> {
1719
})
1820
.catch ((error) => {
1921
console.error('Error:', error);
20-
logseq.App.showMsg("Please start PicGo or check its' status!", "error");
22+
logseq.App.showMsg("Please check if PicGo is running. And this plugin can only be run in manually loaded mode due to CORS restriction, please download it from GitHub release page.", "error");
2123
})
2224
}
2325

@@ -79,7 +81,20 @@ async function recordUploadedImageFile(filePath: string) {
7981
}
8082
}
8183

84+
async function checkUpdates() {
85+
const res = await fetch("https://api.github.com/repos/logseq/logseq-plugin-image-uploader/releases/latest")
86+
.then(res => res.json())
87+
.then(resJSON => {
88+
const latestVersion = resJSON["tag_name"].replace("v", "");
89+
if (gt(latestVersion, currentVersion)) {
90+
logseq.App.showMsg(`New version ${latestVersion} is available.`, "info");
91+
}
92+
})
93+
}
94+
8295
async function main() {
96+
checkUpdates();
97+
8398
const graphInfo = await logseq.App.getCurrentGraph();
8499
const graphPath = graphInfo?.path;
85100
if (!graphPath) {

0 commit comments

Comments
 (0)