mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-31 01:40:05 +08:00
complete the new version for add button
This commit is contained in:
@@ -87,13 +87,14 @@ export async function uploadCommandGeneral(
|
||||
export async function uploadCommandCustom(
|
||||
plugin: ObsidianSyncNotionPlugin,
|
||||
settings: PluginSettings,
|
||||
dbDetails: DatabaseDetails,
|
||||
app: App,
|
||||
) {
|
||||
|
||||
const { notionAPIGeneral, databaseIDGeneral } = settings;
|
||||
const { notionAPI, databaseID } = settings;
|
||||
|
||||
// Check if the user has set up the Notion API and database ID
|
||||
if (notionAPIGeneral === "" || databaseIDGeneral === "") {
|
||||
if (notionAPI === "" || databaseID === "") {
|
||||
const setAPIMessage = i18nConfig["set-api-id"];
|
||||
new Notice(setAPIMessage);
|
||||
return;
|
||||
@@ -104,7 +105,7 @@ export async function uploadCommandCustom(
|
||||
if (markDownData) {
|
||||
const { basename } = nowFile;
|
||||
|
||||
const upload = new Upload2NotionCustom(plugin);
|
||||
const upload = new Upload2NotionCustom(plugin,dbDetails);
|
||||
const res = await upload.syncMarkdownToNotionCustom(basename, cover, tags, customValues, markDownData, nowFile, this.app);
|
||||
|
||||
if (res.status === 200) {
|
||||
|
||||
@@ -14,6 +14,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
|
||||
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
||||
super(plugin);
|
||||
this.dbDetails = dbDetails;
|
||||
}
|
||||
|
||||
// 因为需要解析notion的block进行对比,非常的麻烦,
|
||||
@@ -28,12 +29,13 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
await this.deletePage(notionID);
|
||||
|
||||
const { databaseID } = this.dbDetails;
|
||||
const databasecover = await this.getDataBase(
|
||||
|
||||
const databaseCover = await this.getDataBase(
|
||||
databaseID,
|
||||
);
|
||||
|
||||
if (cover == null) {
|
||||
cover = databasecover;
|
||||
cover = databaseCover;
|
||||
}
|
||||
|
||||
return await this.createPage(title, cover, tags, childArr);
|
||||
@@ -45,13 +47,22 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
tags: string[],
|
||||
childArr: any,
|
||||
) {
|
||||
|
||||
const {
|
||||
databaseID,
|
||||
customTitleButton,
|
||||
customTitleName,
|
||||
tagButton,
|
||||
notionAPI
|
||||
} = this.dbDetails;
|
||||
|
||||
const bodyString: any = {
|
||||
parent: {
|
||||
database_id: this.plugin.settings.databaseIDGeneral,
|
||||
database_id: databaseID,
|
||||
},
|
||||
properties: {
|
||||
[this.plugin.settings.CustomTitleButton
|
||||
? this.plugin.settings.CustomTitleName
|
||||
[customTitleButton
|
||||
? customTitleName
|
||||
: "title"]: {
|
||||
title: [
|
||||
{
|
||||
@@ -61,7 +72,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
},
|
||||
],
|
||||
},
|
||||
...(this.plugin.settings.tagsButton
|
||||
...(tagButton
|
||||
? {
|
||||
tags: {
|
||||
multi_select: tags && true ? tags.map((tag) => ({ name: tag })) : [],
|
||||
@@ -98,7 +109,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
"Content-Type": "application/json",
|
||||
// 'User-Agent': 'obsidian.md',
|
||||
Authorization:
|
||||
"Bearer " + this.plugin.settings.notionAPIGeneral,
|
||||
"Bearer " + notionAPI,
|
||||
"Notion-Version": "2022-06-28",
|
||||
},
|
||||
body: JSON.stringify(bodyString),
|
||||
@@ -144,7 +155,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
||||
res = await this.createPage(title, cover, tags, file2Block);
|
||||
}
|
||||
if (res.status === 200) {
|
||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin);
|
||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
||||
} else {
|
||||
new Notice(`${res.text}`);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
|
||||
const { databaseID} = this.dbDetails
|
||||
|
||||
const databasecover = await this.getDataBase(databaseID)
|
||||
const databaseCover = await this.getDataBase(databaseID)
|
||||
|
||||
if (cover == null) {
|
||||
cover = databasecover
|
||||
cover = databaseCover
|
||||
}
|
||||
|
||||
return await this.createPage(
|
||||
@@ -77,9 +77,16 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
datetime: string,
|
||||
childArr: any
|
||||
) {
|
||||
|
||||
const {
|
||||
databaseID,
|
||||
notionAPI
|
||||
} = this.dbDetails
|
||||
|
||||
|
||||
const bodyString: any = {
|
||||
parent: {
|
||||
database_id: this.plugin.settings.databaseIDNext
|
||||
database_id: databaseID,
|
||||
},
|
||||
icon: {
|
||||
emoji: emoji || '📜'
|
||||
@@ -183,7 +190,7 @@ export class Upload2NotionNext extends UploadBaseNext {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
// 'User-Agent': 'obsidian.md',
|
||||
'Authorization': 'Bearer ' + this.plugin.settings.notionAPINext,
|
||||
'Authorization': 'Bearer ' + notionAPI,
|
||||
'Notion-Version': '2022-06-28',
|
||||
},
|
||||
body: JSON.stringify(bodyString),
|
||||
|
||||
@@ -4,15 +4,17 @@ import { markdownToBlocks } from "@tryfabric/martian";
|
||||
import * as yamlFrontMatter from "yaml-front-matter";
|
||||
// import * as yaml from "yaml"
|
||||
import MyPlugin from "src/main";
|
||||
import { PluginSettings } from "../../ui/settingTabs";
|
||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||
import { updateYamlInfo } from "../updateYaml";
|
||||
import {UploadBaseCustom} from "./BaseUpload2NotionCustom";
|
||||
|
||||
export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
settings: PluginSettings;
|
||||
dbDetails: DatabaseDetails;
|
||||
|
||||
constructor(plugin: MyPlugin) {
|
||||
constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) {
|
||||
super(plugin);
|
||||
this.dbDetails = dbDetails;
|
||||
}
|
||||
|
||||
// 因为需要解析notion的block进行对比,非常的麻烦,
|
||||
@@ -27,12 +29,14 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
) {
|
||||
await this.deletePage(notionID);
|
||||
|
||||
const databasecover = await this.getDataBase(
|
||||
this.plugin.settings.databaseIDGeneral,
|
||||
const { databaseID } = this.dbDetails;
|
||||
|
||||
const databaseCover = await this.getDataBase(
|
||||
databaseID
|
||||
);
|
||||
|
||||
if (cover == null) {
|
||||
cover = databasecover;
|
||||
cover = databaseCover;
|
||||
}
|
||||
|
||||
return await this.createPage(title, cover, tags, customValues, childArr);
|
||||
@@ -45,13 +49,22 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
customValues: Record<string, string>,
|
||||
childArr: any,
|
||||
) {
|
||||
|
||||
const {
|
||||
databaseID,
|
||||
customTitleButton,
|
||||
customTitleName,
|
||||
tagButton,
|
||||
notionAPI
|
||||
} = this.dbDetails;
|
||||
|
||||
const bodyString: any = {
|
||||
parent: {
|
||||
database_id: this.plugin.settings.databaseIDGeneral,
|
||||
database_id: databaseID,
|
||||
},
|
||||
properties: {
|
||||
[this.plugin.settings.CustomTitleButton
|
||||
? this.plugin.settings.CustomTitleName
|
||||
[customTitleButton
|
||||
? customTitleName
|
||||
: "title"]: {
|
||||
title: [
|
||||
{
|
||||
@@ -148,7 +161,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
||||
res = await this.createPage(title, cover, tags, customValues, file2Block);
|
||||
}
|
||||
if (res.status === 200) {
|
||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin);
|
||||
await updateYamlInfo(markdown, nowFile, res, app, this.plugin, this.dbDetails);
|
||||
} else {
|
||||
new Notice(`${res.text}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user