Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
AlgusDark committed Nov 28, 2022
0 parents commit 2a3d8ec
Show file tree
Hide file tree
Showing 20 changed files with 1,251 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
tab_width = 2
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm node_modules
build
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"env": { "node": true },
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }],
"@typescript-eslint/ban-ts-comment": "off",
"no-prototype-builtins": "off",
"@typescript-eslint/no-empty-function": "off"
}
}
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# vscode
.vscode

# Intellij
*.iml
.idea

# npm
node_modules

# Don't include the compiled main.js file in the repo.
# They should be uploaded to GitHub releases instead.
main.js

# Exclude sourcemaps
*.map

# obsidian
data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tag-version-prefix=""
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Cloud uploader

This plugins is under development. Cloudinary is the only provider at the moment

## TODO / Ideas

- [ ] Multiple Providers
- Maybe activate several providers and have rules per provider, e.g use a specific provider per folder (maybe private notes on paid provider and public ones in free server).
- [ ] Offline first
- Save images localy and upload them.
- `Plugin#.app.vault.configDir` has the .obsidian folder
- `Plugin#.app.vault.writeBinary` for writing a binary file
- `Plugin#.app.vault.config.attachmentFolderPath` has the attachment folder path
- [More info](https://github.com/aleksey-rezvov/obsidian-local-images/blob/master/src/contentProcessor.ts)
- Parse offline images to be previewed if exists, download if not
- There should be a render-hook for all images 🤔
- [Maybe this?](https://github.com/bicarlsen/obsidian_image_caption/blob/main/src/view_observer.ts)
44 changes: 44 additions & 0 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";

const banner = `/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = process.argv[2] === "production";

esbuild
.build({
banner: {
js: banner,
},
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins,
],
format: "cjs",
watch: !prod,
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
})
.catch(() => process.exit(1));
10 changes: 10 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "cloud-uploader",
"name": "Cloud Uploader",
"version": "0.0.1",
"minAppVersion": "0.15.0",
"description": "Upload drop/paste images directly to the cloud",
"author": "Algus Dark",
"authorUrl": "https://algus.ninja",
"isDesktopOnly": true
}
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "obsidian-cloud-uploader",
"version": "0.0.1",
"description": "Upload drop/paste images directly to a cloud provider",
"scripts": {
"dev": "node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "Algus Dark",
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.14.47",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "4.7.4"
}
}
11 changes: 11 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class CustomClipboardEvent extends ClipboardEvent {
constructor(type: string, eventInitDict: ClipboardEventInit) {
super(type, eventInitDict);
}
}

export class CustomDragEvent extends DragEvent {
constructor(type: string, eventInitDict: DragEventInit) {
super(type, eventInitDict);
}
}
89 changes: 89 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Plugin } from "obsidian";

import { CustomClipboardEvent, CustomDragEvent } from "@app/events";
import { CloudUploaderSettings, DEFAULT_SETTINGS } from "@app/settings";
import { handleUploadEvent } from "@app/utils";
import { CloudinaryProvider } from "@app/providers/cloudinary";

import type { IProvider } from "@app/providers/manager";

declare module "obsidian" {
interface MarkdownSubView {
clipboardManager: {
handlePaste(e: ClipboardEvent): void;
handleDrop(e: DragEvent): void;
};
}
}

export default class CloudUploader extends Plugin {
settings: typeof DEFAULT_SETTINGS;
provider: IProvider;

async onload() {
await this.loadSettings();

this.registerEvent(
this.app.workspace.on("editor-paste", (event, editor, markdownView) => {
handleUploadEvent({
event,
editor,
provider: this.provider,
eventAllowDefault: (dataTransfer) => {
markdownView.currentMode.clipboardManager.handlePaste(
new CustomClipboardEvent(event.type, {
clipboardData: dataTransfer,
})
);
},
});
})
);

this.registerEvent(
this.app.workspace.on("editor-drop", (event, editor, markdownView) => {
handleUploadEvent({
event,
editor,
provider: this.provider,
eventAllowDefault: (dataTransfer) => {
markdownView.currentMode.clipboardManager.handleDrop(
new CustomDragEvent(event.type, {
clientX: event.clientX,
clientY: event.clientY,
dataTransfer,
})
);
},
});
})
);

this.addSettingTab(new CloudUploaderSettings(this.app, this));
}

private setProvider() {
switch (this.settings.provider) {
case "cloudinary":
this.provider = new CloudinaryProvider(this.settings.cloudinary);
}
}

private async loadSettings() {
this.settings = await Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);

this.setProvider();
}

async saveSettings() {
await this.saveData(this.settings);

this.setProvider();
}

onunload() {}
}
Loading

0 comments on commit 2a3d8ec

Please sign in to comment.