From 9887e31f01b404bf20f604887a5832fb0abaaf2b Mon Sep 17 00:00:00 2001 From: "Addo.Zhang" Date: Mon, 19 Feb 2024 12:34:55 +0800 Subject: [PATCH] support specifying imagekit folder --- manifest.json | 2 +- package.json | 2 +- src/imageStore.ts | 2 +- src/publish.ts | 4 ++-- src/ui/publishSettingTab.ts | 9 +++++++++ src/uploader/imagekit/imagekitUploader.ts | 10 +++++++--- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/manifest.json b/manifest.json index d0a741b..fc40a44 100644 --- a/manifest.json +++ b/manifest.json @@ -6,5 +6,5 @@ "authorUrl": "https://atbug.com", "isDesktopOnly": true, "minAppVersion": "0.11.0", - "version": "0.5.0" + "version": "0.5.1" } diff --git a/package.json b/package.json index 5253b26..2f9e4eb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-image-upload-toolkit", - "version": "0.5.0", + "version": "0.5.1", "description": "", "author": "addozhang", "main": "main.js", diff --git a/src/imageStore.ts b/src/imageStore.ts index 34d2f41..05ed4b9 100644 --- a/src/imageStore.ts +++ b/src/imageStore.ts @@ -17,7 +17,7 @@ export default class ImageStore { static readonly ImageKit = new ImageStore( "Imagekit", - "Imagekit upload" + "Imagekit" ); private constructor(readonly id: string, readonly description: string) { diff --git a/src/publish.ts b/src/publish.ts index 783d1f2..2ea6234 100644 --- a/src/publish.ts +++ b/src/publish.ts @@ -43,8 +43,8 @@ const DEFAULT_SETTINGS: PublishSettings = { endpoint: "", imagekitID: "", privateKey: "", - publicKey: "" - + publicKey: "", + folder: "", } }; export default class ObsidianPublish extends Plugin { diff --git a/src/ui/publishSettingTab.ts b/src/ui/publishSettingTab.ts index bcb63a3..04b5e6a 100644 --- a/src/ui/publishSettingTab.ts +++ b/src/ui/publishSettingTab.ts @@ -196,6 +196,15 @@ export default class PublishSettingTab extends PluginSettingTab { this.plugin.settings.imagekitSetting.endpoint = `https://ik.imagekit.io/${value}/` })) + new Setting(parentEL) + .setName("Folder name") + .setDesc("Please enter the directory name, otherwise leave it blank") + .addText(text => + text + .setPlaceholder("Enter the folder name") + .setValue(this.plugin.settings.imagekitSetting.folder) + .onChange(value => this.plugin.settings.imagekitSetting.folder = value)) + new Setting(parentEL) .setName("Public Key") .addText(text => diff --git a/src/uploader/imagekit/imagekitUploader.ts b/src/uploader/imagekit/imagekitUploader.ts index f046407..55e26ac 100644 --- a/src/uploader/imagekit/imagekitUploader.ts +++ b/src/uploader/imagekit/imagekitUploader.ts @@ -3,18 +3,21 @@ import Imagekit from "imagekit"; export default class ImagekitUploader implements ImageUploader { private readonly imagekit!: Imagekit; + private readonly setting!: ImagekitSetting; constructor(setting: ImagekitSetting) { this.imagekit = new Imagekit({ - publicKey : setting.publicKey, - privateKey : setting.privateKey, + publicKey: setting.publicKey, + privateKey: setting.privateKey, urlEndpoint: setting.endpoint, - }) + }); + this.setting = setting; } async upload(image: File, fullPath: string): Promise { const result = await this.imagekit.upload({ file : Buffer.from((await image.arrayBuffer())).toString('base64'), //required fileName : image.name, //required + folder: this.setting.folder || '/', extensions: [ { name: "google-auto-tagging", @@ -30,6 +33,7 @@ export default class ImagekitUploader implements ImageUploader { export interface ImagekitSetting { + folder: string; imagekitID: string; publicKey: string; privateKey: string;