Skip to content

Commit

Permalink
support chevereto
Browse files Browse the repository at this point in the history
  • Loading branch information
yaleiyale committed Apr 24, 2023
1 parent 981e2e6 commit 270e4bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "emo-uploader",
"name": "Emo",
"version": "2.14",
"version": "2.15",
"minAppVersion": "0.15.6",
"description": "Embed markdown online file/image links. This plugin is for uploading images to hosting or files to github in Obsidian.",
"author": "yaleiyale",
Expand Down
28 changes: 20 additions & 8 deletions src/uploader/uploader-chevereto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { request, RequestUrlParam } from 'obsidian'
import { EmoUploader } from '../base/emo-uploader'
import { CheveretoParms } from '../parms/parms-chevereto'
import { getBase64 } from '../utils/file-helper'
import { ReqFormData } from '../utils/req-formdata'
import { CONTENT_TYPE_FORMDATA } from '../base/constants'

export class CheveretoUploader extends EmoUploader {
parms!: CheveretoParms
Expand All @@ -10,17 +11,28 @@ export class CheveretoUploader extends EmoUploader {
this.parms = cheveretoParms
}

async upload (file: File): Promise<string> {
const jsonBody = {
key: this.parms.required.token,
source: await getBase64(file)
// here chevereto API should be look like this: https://imgloc.com/api/1/upload
formatUrl (str: string): string {
if (!str.startsWith('https://') && !str.startsWith('http:https://')) {
str = 'https://' + str
}
if (str.endsWith('/')) { // remove '/'
str = str.slice(0, -1)
}
const form = JSON.stringify(jsonBody)
return str
}

async upload (file: File): Promise<string> {
const domain = this.formatUrl(this.parms.required.domain)
const formData = new ReqFormData()
await formData.addFile('source', file)
const form = formData.pack()
const req: RequestUrlParam = {
url: this.parms.required.domain,
url: domain,
method: 'POST',
headers: {
'X-API-Key': this.parms.required.token
'X-API-Key': this.parms.required.token,
'Content-Type': CONTENT_TYPE_FORMDATA
},
body: form
}
Expand Down

0 comments on commit 270e4bb

Please sign in to comment.