Skip to content

Commit

Permalink
fix the notification bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpeng98 committed Aug 10, 2023
1 parent 55804e4 commit 2434ddd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 43 deletions.
16 changes: 8 additions & 8 deletions Upload2Notion.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Notice, requestUrl,TFile,normalizePath, App } from "obsidian";
import { Client } from "@notionhq/client";
import { markdownToBlocks, } from "@tryfabric/martian";
import {App, Notice, requestUrl, TFile} from "obsidian";
import {Client} from "@notionhq/client";
import {markdownToBlocks,} from "@tryfabric/martian";
import * as yamlFrontMatter from "yaml-front-matter";
import * as yaml from "yaml"
import MyPlugin from "main";

export class Upload2Notion {
app: MyPlugin;
notion: Client;
Expand All @@ -13,7 +14,7 @@ export class Upload2Notion {
}

async deletePage(notionID:string){
const response = await requestUrl({
return await requestUrl({
url: `https://api.notion.com/v1/blocks/${notionID}`,
method: 'DELETE',
headers: {
Expand All @@ -23,7 +24,6 @@ export class Upload2Notion {
},
body: ''
})
return response;
}

async getDataBase(databaseID:string){
Expand All @@ -49,13 +49,14 @@ export class Upload2Notion {
// 暂时就直接删除,新建一个page
async updatePage(notionID:string, title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, paword:string, favicon:string, datetime:string, childArr:any) {
await this.deletePage(notionID)

const databasecover = await this.getDataBase(this.app.settings.databaseID)

if (cover == null) {
cover = databasecover
}

const res = await this.createPage(title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr)
return await this.createPage(title, allowTags, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, childArr)
}

async createPage(title:string, allowTags:boolean, emoji:string, cover:string, tags:string[], type:string, slug:string, stats:string, category:string, summary:string, pawrod:string, favicon:string, datetime:string, childArr: any) {
Expand Down Expand Up @@ -159,7 +160,7 @@ export class Upload2Notion {
}

try {
const response = await requestUrl({
return await requestUrl({
url: `https://api.notion.com/v1/pages`,
method: 'POST',
headers: {
Expand All @@ -170,7 +171,6 @@ export class Upload2Notion {
},
body: JSON.stringify(bodyString),
})
return response;
} catch (error) {
new Notice(`network error ${error}`)
}
Expand Down
53 changes: 20 additions & 33 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import {
App,
Editor,
MarkdownView,
Modal,
Notice,
Plugin,
PluginSettingTab,
Setting,
normalizePath
} from "obsidian";
import {addIcons} from 'icon';
import { Upload2Notion } from "Upload2Notion";
import {App, Editor, MarkdownView, Notice, Plugin, PluginSettingTab, Setting} from "obsidian";
import {addIcons} from 'icon';
import {Upload2Notion} from "Upload2Notion";
import {NoticeMConfig} from "Message";
import { CLIENT_RENEG_LIMIT } from "tls";


// Remember to rename these classes and interfaces!
Expand Down Expand Up @@ -48,7 +37,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
"Share to NotionNext",
async (evt: MouseEvent) => {
// Called when the user clicks the icon.
this.upload();
await this.upload();
}
);

Expand All @@ -60,7 +49,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {
id: "share-to-notionnext",
name: "share to notionnext",
editorCallback: async (editor: Editor, view: MarkdownView) => {
this.upload()
await this.upload()
},
});

Expand Down Expand Up @@ -184,31 +173,29 @@ class SampleSettingTab extends PluginSettingTab {
.setName("Notion API Token")
.setDesc("It's a secret")
.addText((text) =>{
let t = text
.setPlaceholder("Enter your Notion API Token")
.setValue(this.plugin.settings.notionAPI)
.onChange(async (value) => {
this.plugin.settings.notionAPI = value;
await this.plugin.saveSettings();
})
// t.inputEl.type = 'password'
return t
return text
.setPlaceholder("Enter your Notion API Token")
.setValue(this.plugin.settings.notionAPI)
.onChange(async (value) => {
this.plugin.settings.notionAPI = value;
await this.plugin.saveSettings();
})
});


const notionDatabaseID = new Setting(containerEl)
.setName("Database ID")
.setDesc("It's a secret")
.addText((text) => {
let t = text
.setPlaceholder("Enter your Database ID")
.setValue(this.plugin.settings.databaseID)
.onChange(async (value) => {
this.plugin.settings.databaseID = value;
await this.plugin.saveSettings();
})
// t.inputEl.type = 'password'
return t
// t.inputEl.type = 'password'
return text
.setPlaceholder("Enter your Database ID")
.setValue(this.plugin.settings.databaseID)
.onChange(async (value) => {
this.plugin.settings.databaseID = value;
await this.plugin.saveSettings();
})
}

);
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "share-to-notionnext",
"name": "Share to NotionNext",
"version": "0.0.7",
"version": "0.0.8",
"minAppVersion": "0.0.1",
"description": "This is a plugin for Obsidian. This plugin shares obsidian md file to notion with notion api for NotionNext web deploy.",
"author": "jxpeng98",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "share-to-notionnext",
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"description": "This is a plugin for Obsidian. This plugin share obsidian md file to notion with notion api for NotionNext web deploy.",
"main": "main.js",
Expand Down

0 comments on commit 2434ddd

Please sign in to comment.