generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriteas-api.ts
42 lines (30 loc) · 1.12 KB
/
writeas-api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { MarkdownView, Setting } from "obsidian";
export async function authenticate(login: string, password: string): Promise<string> {
return '';
}
export function getBlogs() {
return ['Blog 1', 'Blog 2'];
}
// uploads the current page as an anonymous post, also handles errors
export async function uploadAsAnonymousPost(settings: any): Promise<any> {
// get the file name, which is used as the title
const postTitle = this.app.workspace.getActiveFile().basename;
// get document text. Using editor rather than view, since view doesn't render all the text?
const currentDocument = this.app.workspace.getActiveViewOfType(MarkdownView).editor.getDoc();
let currentText = currentDocument.getValue();
const postData = {
body: currentText,
title: postTitle,
font: settings.postType
}
const uploadResponse = await fetch('https://write.as/api/posts', {
method: 'POST',
mode: "no-cors",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(postData)
}
);
console.log(uploadResponse);
}