Skip to content

Commit

Permalink
support specifying imagekit folder
Browse files Browse the repository at this point in the history
  • Loading branch information
addozhang committed Feb 19, 2024
1 parent 8baa6f7 commit 9887e31
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"authorUrl": "https://atbug.com",
"isDesktopOnly": true,
"minAppVersion": "0.11.0",
"version": "0.5.0"
"version": "0.5.1"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-image-upload-toolkit",
"version": "0.5.0",
"version": "0.5.1",
"description": "",
"author": "addozhang",
"main": "main.js",
Expand Down
2 changes: 1 addition & 1 deletion src/imageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const DEFAULT_SETTINGS: PublishSettings = {
endpoint: "",
imagekitID: "",
privateKey: "",
publicKey: ""

publicKey: "",
folder: "",
}
};
export default class ObsidianPublish extends Plugin {
Expand Down
9 changes: 9 additions & 0 deletions src/ui/publishSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
10 changes: 7 additions & 3 deletions src/uploader/imagekit/imagekitUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
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",
Expand All @@ -30,6 +33,7 @@ export default class ImagekitUploader implements ImageUploader {


export interface ImagekitSetting {
folder: string;
imagekitID: string;
publicKey: string;
privateKey: string;
Expand Down

0 comments on commit 9887e31

Please sign in to comment.