-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
1,958 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const IMGUR_ACCESS_TOKEN_LOCALSTORAGE_KEY = 'imgur-access_token' | ||
export const IMGUR_DEFAULT_ID = '4547d4aee97ce8f' | ||
export const RANDOM_BOUNDARY = 'loveaimeainixucheng' // magic, random, i just use it | ||
export const CONTENT_TYPE_FORMDATA = 'multipart/form-data;boundary=' + RANDOM_BOUNDARY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { HostingProvider } from '../config' | ||
import Emo from '../main' | ||
|
||
export abstract class EmoFragment { | ||
kind: HostingProvider | ||
element: HTMLDivElement | ||
protected constructor (kind: HostingProvider, el: HTMLElement, plugin: Emo) { | ||
this.kind = kind | ||
this.element = el.createDiv(kind) | ||
this.display(this.element, plugin) | ||
this.element.hide() | ||
} | ||
abstract display (el: HTMLElement, plugin: Emo): void | ||
|
||
update (choice: HostingProvider): void { | ||
this.kind === choice ? this.element.show() : this.element.hide() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface EmoParms { | ||
required: any // all string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { EmoParms } from './emo-parms' | ||
|
||
export abstract class EmoUploader { | ||
parms!: EmoParms | ||
abstract upload (file: File): Promise<string> | ||
isValid (): boolean { // check the necessary parameters, type: string | ||
let result = true | ||
for (const i in this.parms.required) { | ||
result &&= notEmpty(this.parms.required[i]) | ||
if (!result) return false | ||
} | ||
return true | ||
} | ||
} | ||
function notEmpty (value: string): boolean { | ||
return value.length > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { CatboxParms, CATBOX_DEFAULT_PARMS } from './parms/parms-catbox' | ||
import { CHEVERETO_DEFAULT_PARMS, CheveretoParms } from './parms/parms-chevereto' | ||
import { CloudinaryParms, CLOUDINARY_DEFAULT_PARMS } from './parms/parms-cloudinary' | ||
import { GithubParms, GITHUB_DEFAULT_PARMS } from './parms/parms-github' | ||
import { ImgbbParms, IMGBB_DEFAULT_PARMS } from './parms/parms-imgbb' | ||
import { ImgurParms, IMGUR_DEFAULT_PARMS } from './parms/parms-imgur' | ||
import { ImgurlParms, IMGURL_DEFAULT_PARMS } from './parms/parms-imgurl' | ||
import { SmmsParms, SMMS_DEFAULT_PARMS } from './parms/parms-smms' | ||
import { ALIST_DEFAULT_PARMS, AlistParms } from './parms/parms-alist' | ||
|
||
export interface Config { // data from data.json | ||
choice: HostingProvider | ||
github_parms: GithubParms | ||
smms_parms: SmmsParms | ||
imgurl_parms: ImgurlParms | ||
cloudinary_parms: CloudinaryParms | ||
imgbb_parms: ImgbbParms | ||
imgur_parms: ImgurParms | ||
catbox_parms: CatboxParms | ||
chevereto_parms: CheveretoParms | ||
alist_parms: AlistParms | ||
} | ||
|
||
export enum HostingProvider { // target hosting | ||
Github = 'Github', | ||
Cloudinary = 'Cloudinary', | ||
Catbox = 'Catbox', | ||
Imgur = 'Imgur', | ||
Smms = 'SM.MS', | ||
ImgURL = 'ImgURL', | ||
Imgbb = 'imgbb', | ||
Chevereto = 'chevereto', | ||
Alist = 'alist' | ||
} | ||
|
||
export const DEFAULT_SETTINGS: Config = { | ||
choice: HostingProvider.Github, | ||
github_parms: GITHUB_DEFAULT_PARMS, | ||
imgur_parms: IMGUR_DEFAULT_PARMS, | ||
cloudinary_parms: CLOUDINARY_DEFAULT_PARMS, | ||
smms_parms: SMMS_DEFAULT_PARMS, | ||
imgurl_parms: IMGURL_DEFAULT_PARMS, | ||
imgbb_parms: IMGBB_DEFAULT_PARMS, | ||
catbox_parms: CATBOX_DEFAULT_PARMS, | ||
chevereto_parms: CHEVERETO_DEFAULT_PARMS, | ||
alist_parms: ALIST_DEFAULT_PARMS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Setting } from 'obsidian' | ||
import Emo from '../main' | ||
import { EmoFragment } from '../base/emo-fragment' | ||
import { HostingProvider } from '../config' | ||
import { t } from '../lang/helpers' | ||
|
||
export class AlistFragment extends EmoFragment { | ||
constructor (el: HTMLElement, plugin: Emo) { | ||
super(HostingProvider.Alist, el, plugin) | ||
} | ||
|
||
display (el: HTMLElement, plugin: Emo): void { | ||
const parms = plugin.config.alist_parms | ||
el.createEl('h3', { text: 'Alist Settings'}) | ||
|
||
new Setting(el) | ||
.setName(t('domain')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.domain) | ||
.onChange(async (value) => { | ||
parms.required.domain = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName('username') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.username) | ||
.onChange(async (value) => { | ||
parms.required.username = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName('password') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.password) | ||
.onChange(async (value) => { | ||
parms.required.password = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName('uploadPath') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.uploadPath) | ||
.onChange(async (value) => { | ||
parms.required.uploadPath = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Setting } from 'obsidian' | ||
import Emo from '../main' | ||
import { EmoFragment } from '../base/emo-fragment' | ||
import { HostingProvider } from '../config' | ||
import { t } from '../lang/helpers' | ||
|
||
export class CatboxFragment extends EmoFragment { | ||
constructor (el: HTMLElement, plugin: Emo) { | ||
super(HostingProvider.Catbox, el, plugin) | ||
} | ||
|
||
display (el: HTMLElement, plugin: Emo): void { | ||
const parms = plugin.config.catbox_parms | ||
el.createEl('h3', { text: t('Catbox Settings') }) | ||
|
||
new Setting(el) | ||
.setName('userhash') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.userhash) | ||
.onChange(async (value) => { | ||
parms.required.userhash = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Setting } from 'obsidian' | ||
import Emo from '../main' | ||
import { EmoFragment } from '../base/emo-fragment' | ||
import { HostingProvider } from '../config' | ||
import { t } from '../lang/helpers' | ||
|
||
export class CheveretoFragment extends EmoFragment { | ||
constructor (el: HTMLElement, plugin: Emo) { | ||
super(HostingProvider.Chevereto, el, plugin) | ||
} | ||
|
||
display (el: HTMLElement, plugin: Emo): void { | ||
const parms = plugin.config.chevereto_parms | ||
el.createEl('h3', { text: t('Chevereto Settings') }) | ||
|
||
new Setting(el) | ||
.setName(t('domain')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.domain) | ||
.onChange(async (value) => { | ||
parms.required.domain = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName('token') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.token) | ||
.onChange(async (value) => { | ||
parms.required.token = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Setting } from 'obsidian' | ||
import Emo from '../main' | ||
import { EmoFragment } from '../base/emo-fragment' | ||
import { HostingProvider } from '../config' | ||
import { t } from '../lang/helpers' | ||
|
||
export class CloudinaryFragment extends EmoFragment { | ||
constructor (el: HTMLElement, plugin: Emo) { | ||
super(HostingProvider.Cloudinary, el, plugin) | ||
} | ||
|
||
display (el: HTMLElement, plugin: Emo): void { | ||
const parms = plugin.config.cloudinary_parms | ||
el.createEl('h3', { text: t('Cloudinary Settings') }) | ||
|
||
new Setting(el) | ||
.setName('Cloud Name') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.name) | ||
.onChange(async (value) => { | ||
parms.required.name = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName('Upload Presets') | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.present) | ||
.onChange(async (value) => { | ||
parms.required.present = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName('Upload Folder') | ||
.setDesc(t('Upload Folder desc')) | ||
.addText((text) => { | ||
text | ||
.setPlaceholder('obsidian -> obsidian/pic.png') | ||
.setValue(parms.folder) | ||
.onChange(async (value) => { | ||
parms.folder = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import { Setting } from 'obsidian' | ||
import Emo from '../main' | ||
import { EmoFragment } from '../base/emo-fragment' | ||
import { HostingProvider } from '../config' | ||
import { t } from '../lang/helpers' | ||
import { CDNprovider } from '../parms/parms-github' | ||
|
||
export class GithubFragment extends EmoFragment { | ||
constructor (el: HTMLElement, plugin: Emo) { | ||
super(HostingProvider.Github, el, plugin) | ||
} | ||
|
||
display (el: HTMLElement, plugin: Emo): void { | ||
const parms = plugin.config.github_parms | ||
el.createEl('h3', { text: t('Github Settings') }) | ||
|
||
new Setting(el) | ||
.setName(t('owner')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.owner) | ||
.onChange(async (value) => { | ||
parms.required.owner = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName(t('repo')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.repo) | ||
.onChange(async (value) => { | ||
parms.required.repo = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName(t('branch')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.branch) | ||
.onChange(async (value) => { | ||
parms.required.branch = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName(t('token')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.token) | ||
.onChange(async (value) => { | ||
parms.required.token = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName(t('message')) | ||
.addText((text) => { | ||
text | ||
.setValue(parms.required.message) | ||
.onChange(async (value) => { | ||
parms.required.message = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName(t('path')) | ||
.setDesc(t('not required')) | ||
.addText((text) => { | ||
text | ||
.setPlaceholder('obsidian/ -> obsidian/pic.png') | ||
.setValue(parms.path) | ||
.onChange(async (value) => { | ||
parms.path = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
new Setting(el) | ||
.setName(t('random filename')) | ||
.setDesc(t('random filename desc')) | ||
.addToggle((toggle) => { | ||
toggle.setValue(parms.random) | ||
toggle.onChange(async (value) => { | ||
parms.random = value | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
|
||
const supportList: string[] = [] | ||
for (const key in CDNprovider) { | ||
supportList.push(CDNprovider[key as keyof typeof CDNprovider]) | ||
} | ||
|
||
new Setting(el) | ||
.setName(t('cdn')) | ||
.addDropdown((dropdown) => { | ||
supportList.forEach((record) => { dropdown.addOption(record, record) }) | ||
dropdown.setValue(parms.cdn) | ||
.onChange(async (value) => { | ||
parms.cdn = value as CDNprovider | ||
await plugin.saveSettings() | ||
}) | ||
}) | ||
} | ||
} |
Oops, something went wrong.