diff --git a/src/commands/NotionCommands.ts b/src/commands/NotionCommands.ts index 2ca4b2b..13a7bad 100644 --- a/src/commands/NotionCommands.ts +++ b/src/commands/NotionCommands.ts @@ -1,8 +1,9 @@ import { i18nConfig } from "src/lang/I18n"; -import { Editor, MarkdownView } from "obsidian"; +import {Editor, MarkdownView, setTooltip} from "obsidian"; import { FuzzySuggester, DatabaseList } from "./FuzzySuggester"; import { uploadCommandGeneral, uploadCommandNext } from "../upload/uploadCommand"; import ObsidianSyncNotionPlugin from "src/main"; +import {DatabaseDetails} from "../ui/settingTabs"; interface Command { @@ -21,26 +22,11 @@ export default class RibbonCommands { constructor(plugin: ObsidianSyncNotionPlugin) { this.plugin = plugin; - // Check if NextButton is true, then include the corresponding command - if (this.plugin.settings.NextButton) { - this.Ncommand.push({ - id: "share-to-notionnext", - name: i18nConfig.CommandName, // Use the translated text from i18nConfig - editorCallback: async (editor: Editor, view: MarkdownView) => { - await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app); - } - }); - } + // iterate through the database detail - // Check if GeneralButton is true, then include the corresponding command - if (this.plugin.settings.GeneralButton) { - this.Ncommand.push({ - id: "share-to-notion", - name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig - editorCallback: async (editor: Editor, view: MarkdownView) => { - await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app); - } - }); + for (let key in this.plugin.settings.databaseDetails) { + let dbDetails = this.plugin.settings.databaseDetails[key]; + this.addCommandForDatabase(dbDetails); } // Register all the commands @@ -77,24 +63,9 @@ export default class RibbonCommands { this.Ncommand = []; - if (this.plugin.settings.NextButton) { - this.Ncommand.push({ - id: "share-to-notionnext", - name: i18nConfig.CommandName, // Use the translated text from i18nConfig - editorCallback: async (editor: Editor, view: MarkdownView) => { - await uploadCommandNext(this.plugin, this.plugin.settings, this.plugin.app); - } - }); - } - - if (this.plugin.settings.GeneralButton) { - this.Ncommand.push({ - id: "share-to-notion", - name: i18nConfig.CommandNameGeneral, // Use the translated text from i18nConfig - editorCallback: async (editor: Editor, view: MarkdownView) => { - await uploadCommandGeneral(this.plugin, this.plugin.settings, this.plugin.app); - } - }); + for (let key in this.plugin.settings.databaseDetails) { + let dbDetails = this.plugin.settings.databaseDetails[key]; + this.addCommandForDatabase(dbDetails); } this.Ncommand.forEach(command => { @@ -107,4 +78,30 @@ export default class RibbonCommands { ); }); } + + private addCommandForDatabase(dbDetails: DatabaseDetails) { + // Example logic - adjust based on your specific requirements + let commandId = `share-to-${dbDetails.abName}`; + let commandName = `Share to ${dbDetails.abName}`; // or use a translated name + + let editorCallback: (editor: Editor, view: MarkdownView) => Promise; + if (dbDetails.format === 'next') { + editorCallback = async (editor, view) => { + await uploadCommandNext(this.plugin, this.plugin.settings, dbDetails, this.plugin.app); + }; + } else if (dbDetails.format === 'general') { + editorCallback = async (editor, view) => { + await uploadCommandGeneral(this.plugin, this.plugin.settings, dbDetails, this.plugin.app); + }; + } + // else if (dbDetails.format === 'custom') { + // editorCallback = async (editor, view) => { + // await uploadCommandGeneral(this.plugin, dbDetails, this.plugin.app); + // }; + // } + + this.Ncommand.push({ id: commandId, name: commandName, editorCallback }); + } + + } diff --git a/src/main.ts b/src/main.ts index 5352417..8263f0c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,7 @@ import { Upload2NotionGeneral } from "src/upload/upload_general/Upload2NotionGen import { Upload2NotionNext } from "src/upload/upload_next/Upload2NotionNext"; import { i18nConfig } from "src/lang/I18n"; import ribbonCommands from "src/commands/NotionCommands"; -import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS } from "src/ui/settingTabs"; +import { ObsidianSettingTab, PluginSettings, DEFAULT_SETTINGS, DatabaseDetails } from "src/ui/settingTabs"; // Remember to rename these classes and interfaces! @@ -55,6 +55,15 @@ export default class ObsidianSyncNotionPlugin extends Plugin { await this.saveData(this.settings); } + async addDatabaseDetails(dbDetails: DatabaseDetails) { + this.settings.databaseDetails = { + ...this.settings.databaseDetails, + [dbDetails.abName]: dbDetails, + }; + + await this.saveSettings(); + } + } diff --git a/src/ui/settingModal.ts b/src/ui/settingModal.ts index 764a90b..d16e3c4 100644 --- a/src/ui/settingModal.ts +++ b/src/ui/settingModal.ts @@ -7,29 +7,46 @@ import { import { i18nConfig } from "../lang/I18n"; import ObsidianSyncNotionPlugin from "../main"; -import {ObsidianSettingTab} from "./settingTabs"; +import {DatabaseDetails, ObsidianSettingTab} from "./settingTabs"; import {SettingNextTabs} from "./settingNextTabs"; import {SettingGeneralTabs} from "./settingGeneralTabs"; export class SettingModal extends Modal { - databaseFormat: string = 'none'; - databaseAbbreviateName: string = ''; - notionAPINext: string = ''; - databaseIDNext: string = ''; - GeneralButton: boolean = false; + data: Record = { + databaseFormat: 'none', + databaseAbbreviateName: '', + notionAPI: '', + databaseID: '', + tagButton: true, + customTitleButton: false, + customTitleName: '', + // customValues: '', + saved: false, + }; plugin: ObsidianSyncNotionPlugin; settingTab: ObsidianSettingTab; - constructor(app: App, plugin: ObsidianSyncNotionPlugin, settingTab: ObsidianSettingTab) { + constructor(app: App, plugin: ObsidianSyncNotionPlugin, settingTab: ObsidianSettingTab, dbDetails?: DatabaseDetails) { super(app); this.plugin = plugin; this.settingTab = settingTab; + if (dbDetails) { + this.data.databaseFormat = dbDetails.format; + this.data.databaseAbbreviateName = dbDetails.abName; + this.data.notionAPI = dbDetails.notionAPI; + this.data.databaseID = dbDetails.databaseID; + this.data.tagButton = dbDetails.tagButton; + this.data.customTitleButton = dbDetails.customTitleButton; + this.data.customTitleName = dbDetails.customTitleName; + // this.data.customValues = dbDetails.customValues; + } } display(): void { this.containerEl.addClass("settings-modal"); + this.titleEl.setText('Add new database'); // create the dropdown button to select the database format let { contentEl } = this; @@ -48,15 +65,41 @@ export class SettingModal extends Modal { .addOption('general', i18nConfig.databaseGeneral) .addOption('next', i18nConfig.databaseNext) .addOption('custom', i18nConfig.databaseCustom) - .setValue(this.databaseFormat) + .setValue(this.data.databaseFormat) .onChange(async (value) => { - this.databaseFormat = value; + this.data.databaseFormat = value; + nextTabs.empty(); this.updateContentBasedOnSelection(value, nextTabs); }); // Initialize content based on the current dropdown value this.updateContentBasedOnSelection(this.plugin.settings.databaseFormat, nextTabs); }); + + // add save button + + let footerEl = contentEl.createDiv('save-button'); + let saveButton = new Setting(footerEl) + saveButton.addButton((button: ButtonComponent) => { + return button + .setTooltip('Save') + .setIcon('checkmark') + .onClick(async () => { + this.data.saved = true; + this.close(); + }); + } + ); + saveButton.addExtraButton((button) => { + return button + .setTooltip('Cancel') + .setIcon('cross') + .onClick(() => { + this.data.saved = false; + this.close(); + }); + } + ); } updateContentBasedOnSelection(value: string, nextTabs: HTMLElement): void { @@ -68,134 +111,92 @@ export class SettingModal extends Modal { nextTabs.createEl('h3', { text: i18nConfig.NotionGeneralSettingHeader }); // add abbreviate name - new Setting(nextTabs) - .setName(i18nConfig.databaseAbbreviateName) - .setDesc(i18nConfig.databaseAbbreviateNameDesc) - .addText((text) => - text - .setPlaceholder(i18nConfig.databaseAbbreviateNameText) - .setValue(this.databaseAbbreviateName) - .onChange(async (value) => { - this.databaseAbbreviateName = value; - }) - ); + this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'databaseAbbreviateName') + + // tag button + this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton, 'tagButton') - new Setting(nextTabs) - .setName(i18nConfig.NotionGeneralButton) - .setDesc(i18nConfig.NotionGeneralButtonDesc) - .addToggle((toggle) => - toggle - .setValue(this.GeneralButton) - .onChange(async (value) => { - this.GeneralButton = value; - - this.updateSettingEl(notionAPIGeneralEl, value) - this.updateSettingEl(databaseIDGeneralEl, value) - - - }) - ); - - - const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton); - - new Setting(notionAPIGeneralEl) - .setName(i18nConfig.NotionAPI) - .setDesc(i18nConfig.NotionAPIDesc) - .addText((text) => { - text.inputEl.type = 'password'; - return text - .setPlaceholder(i18nConfig.NotionAPIText) - .setValue(this.notionAPINext) - .onChange(async (value) => { - this.notionAPINext = value; // Update the plugin settings directly - }) - }); - - - const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton); - - new Setting(databaseIDGeneralEl) - .setName(i18nConfig.DatabaseID) - .setDesc(i18nConfig.NotionAPIDesc) - .addText((text) => { - text.inputEl.type = 'password'; - return text - .setPlaceholder(i18nConfig.DatabaseIDText) - .setValue(this.databaseIDNext) - .onChange(async (value) => { - this.databaseIDNext = value; // Update the plugin settings directly - }) - }); + // add api key + this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'notionAPI') + // add database id + this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'databaseID') } else if (value === 'next') { + nextTabs.createEl('h3', { text: i18nConfig.NotionNextSettingHeader }); + // add abbreviate name - this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.databaseAbbreviateName) + this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'databaseAbbreviateName') + + // add api key + this.createSettingEl(nextTabs, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'notionAPI') + + + // add database id + this.createSettingEl(nextTabs, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'databaseID') + + } else if (value === 'custom') { + nextTabs.createEl('h3', { text: i18nConfig.NotionCustomSettingHeader}); + + // add abbreviate name + this.createSettingEl(nextTabs, i18nConfig.databaseAbbreviateName, i18nConfig.databaseAbbreviateNameDesc, 'text', i18nConfig.databaseAbbreviateNameText, this.data.databaseAbbreviateName, 'databaseAbbreviateName') + + // tag button + this.createSettingEl(nextTabs, i18nConfig.NotionTagButton, i18nConfig.NotionTagButtonDesc, 'toggle', i18nConfig.NotionCustomTitleText, this.data.tagButton, 'tagButton') + + // add custom title button new Setting(nextTabs) - .setName(i18nConfig.databaseAbbreviateName) - .setDesc(i18nConfig.databaseAbbreviateNameDesc) - .addText((text) => - text - .setPlaceholder(i18nConfig.databaseAbbreviateNameText) - .setValue(this.databaseAbbreviateName) + .setName(i18nConfig.NotionCustomTitle) + .setDesc(i18nConfig.NotionCustomTitleDesc) + .addToggle((toggle) => + toggle + .setValue(this.data.CustomTitleButton) .onChange(async (value) => { - this.databaseAbbreviateName = value; + this.data.CustomTitleButton = value; + + this.updateSettingEl(CustomNameEl, value) + + // this.updateSettingEl(CustomValuesEl, value) + + await this.plugin.saveSettings(); + await this.plugin.commands.updateCommand(); }) ); - // add api key - const notionAPINextEl = this.createStyleDiv('api-next', this.plugin.settings.NextButton) - new Setting(notionAPINextEl) - .setName(i18nConfig.NotionAPI) - .setDesc(i18nConfig.NotionAPIDesc) - .addText((text) => { - text.inputEl.type = 'password'; - return text - .setPlaceholder(i18nConfig.NotionAPIText) - .setValue(this.notionAPINext) - .onChange(async (value) => { - this.notionAPINext = value; // Update the plugin settings directly - }) - }); + // add custom title name + const CustomNameEl = this.createStyleDiv('custom-name', (this.data.CustomTitleButton), nextTabs); + this.createSettingEl(CustomNameEl, i18nConfig.NotionCustomTitleName, i18nConfig.NotionCustomTitleNameDesc, 'text', i18nConfig.NotionCustomTitleText, this.data.CustomTitleName, 'CustomTitleName') + + // // add custom values + // const CustomValuesEl = this.createStyleDiv('custom-values', (this.data.CustomTitleButton), nextTabs); + // new Setting(CustomValuesEl) + // .setName(i18nConfig.NotionCustomValues) + // .setDesc(i18nConfig.NotionCustomValuesDesc) + // .addTextArea((text) => { + // return text + // .setPlaceholder(i18nConfig.NotionCustomValuesText) + // .setValue(this.data.CustomValues) + // .onChange(async (value) => { + // this.data.CustomValues = value; + // await this.plugin.saveSettings(); + // }); + // }); + + + // add api key + const notionAPIGeneralEl = this.createStyleDiv('api-general', this.plugin.settings.GeneralButton, nextTabs); + this.createSettingEl(notionAPIGeneralEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.data.notionAPI, 'notionAPI') // add database id - const databaseIDNextEl = this.createStyleDiv('databaseID-next', this.plugin.settings.NextButton) - - new Setting(databaseIDNextEl) - .setName(i18nConfig.DatabaseID) - .setDesc(i18nConfig.NotionAPIDesc) - .addText((text) => { - text.inputEl.type = 'password'; - return text - .setPlaceholder(i18nConfig.DatabaseIDText) - .setValue(this.databaseIDNext) - .onChange(async (value) => { - this.databaseIDNext = value; // Update the plugin settings directly - }) - }); - - // // test button - // new Setting(nextTabs) - // .setName(i18nConfig.NotionNextButton) - // .setDesc(i18nConfig.NotionNextButtonDesc) - // .addToggle((toggle) => - // toggle - // .setValue(this.plugin.settings.NextButton) - // .onChange(async (value) => { - // this.plugin.settings.NextButton = value; - // }) - // ); - - } else if (value === 'custom') { - + const databaseIDGeneralEl = this.createStyleDiv('databaseID-general', this.plugin.settings.GeneralButton, nextTabs); + this.createSettingEl(databaseIDGeneralEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.data.databaseID, 'databaseID') } - // Implement for 'custom' if needed + } @@ -208,8 +209,8 @@ export class SettingModal extends Modal { // create a function to create a div with a style for pop over elements - public createStyleDiv(className: string, commandValue: boolean = false) { - return this.contentEl.createDiv(className, (div) => { + public createStyleDiv(className: string, commandValue: boolean = false,parentEl: HTMLElement ) { + return parentEl.createDiv(className, (div) => { this.updateSettingEl(div, commandValue); }); } @@ -222,7 +223,7 @@ export class SettingModal extends Modal { } // function to add one setting element in the setting tab. - public createSettingEl(contentEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any) { + public createSettingEl(contentEl: HTMLElement, name: string, desc: string, type: string, placeholder: string, holderValue: any,settingsKey: string) { if (type === 'password') { return new Setting(contentEl) .setName(name) @@ -233,8 +234,7 @@ export class SettingModal extends Modal { .setPlaceholder(placeholder) .setValue(holderValue) .onChange(async (value) => { - holderValue = value; // Update the plugin settings directly - await this.plugin.saveSettings(); + this.data[settingsKey] = value; // Update the settings dictionary await this.plugin.saveSettings(); }) }); } else if (type === 'toggle') { @@ -245,8 +245,7 @@ export class SettingModal extends Modal { toggle .setValue(holderValue) .onChange(async (value) => { - holderValue = value; // Update the plugin settings directly - await this.plugin.saveSettings(); + this.data[settingsKey] = value; // Update the settings dictionary await this.plugin.saveSettings(); }) ); } else if (type === 'text') { @@ -258,8 +257,7 @@ export class SettingModal extends Modal { .setPlaceholder(placeholder) .setValue(holderValue) .onChange(async (value) => { - holderValue = value; // Update the plugin settings directly - await this.plugin.saveSettings(); + this.data[settingsKey] = value; // Update the settings dictionary await this.plugin.saveSettings(); }) ); } diff --git a/src/ui/settingNextTabs.ts b/src/ui/settingNextTabs.ts index ed96ec1..faa1c34 100644 --- a/src/ui/settingNextTabs.ts +++ b/src/ui/settingNextTabs.ts @@ -40,10 +40,10 @@ export class SettingNextTabs extends PluginSettingTab { const notionAPINextEl = this.settingModal.createStyleDiv('api-next', this.plugin.settings.NextButton) - this.settingModal.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext, 'notionAPINext') + this.settingModal.createSettingEl(notionAPINextEl, i18nConfig.NotionAPI, i18nConfig.NotionAPIDesc, 'password', i18nConfig.NotionAPIText, this.plugin.settings.notionAPINext) const databaseIDNextEl = this.settingModal.createStyleDiv('databaseID-next', this.plugin.settings.NextButton) - this.settingModal.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext, 'databaseIDNext') + this.settingModal.createSettingEl(databaseIDNextEl, i18nConfig.DatabaseID, i18nConfig.NotionAPIDesc, 'password', i18nConfig.DatabaseIDText, this.plugin.settings.databaseIDNext) } } diff --git a/src/ui/settingTabs.ts b/src/ui/settingTabs.ts index 48bafe4..96959d8 100644 --- a/src/ui/settingTabs.ts +++ b/src/ui/settingTabs.ts @@ -23,6 +23,18 @@ export interface PluginSettings { notionAPICustom: string; databaseIDCustom: string; [key: string]: any; + databaseDetails: Record +} + +export interface DatabaseDetails { + format: string; + abName: string; + notionAPI: string; + databaseID: string; + tagButton: boolean; + customTitleButton: boolean; + customTitleName: string; + // customValues: string; } export const DEFAULT_SETTINGS: PluginSettings = { @@ -42,6 +54,7 @@ export const DEFAULT_SETTINGS: PluginSettings = { CustomValues: "", notionAPICustom: "", databaseIDCustom: "", + databaseDetails: {}, }; @@ -80,16 +93,24 @@ export class ObsidianSettingTab extends PluginSettingTab { let modal = new SettingModal(this.app, this.plugin, this); modal.onClose = () => { - // if (modal.saved) { - // const database = { - // - // } - // this.plugin.addDatabase(database); - // - // this.plugin.calloutManager.addDatabase(database); - // - // this.display(); - // } + if (modal.data.saved) { + const dbDetails = { + format: modal.data.databaseFormat, + abName: modal.data.databaseAbbreviateName, + notionAPI: modal.data.notionAPI, + databaseID: modal.data.databaseID, + tagButton: modal.data.tagButton, + customTitleButton: modal.data.customTitleButton, + customTitleName: modal.data.customTitleName, + // customValues: modal.data.customValues, + } + + this.plugin.addDatabaseDetails(dbDetails); + + this.plugin.commands.updateCommand(); + + this.display() + } } modal.open(); @@ -97,6 +118,9 @@ export class ObsidianSettingTab extends PluginSettingTab { }); + // list all created database + + // // notion next database settings // diff --git a/src/upload/uploadCommand.ts b/src/upload/uploadCommand.ts index 0230fff..58ed18e 100644 --- a/src/upload/uploadCommand.ts +++ b/src/upload/uploadCommand.ts @@ -3,7 +3,7 @@ import { App, Notice } from "obsidian"; import { Upload2NotionNext } from "./upload_next/Upload2NotionNext"; import { Upload2NotionGeneral } from "./upload_general/Upload2NotionGeneral"; import { Upload2NotionCustom } from "./upoload_custom/Upload2NotionCustom"; -import { PluginSettings } from "../ui/settingTabs"; +import {DatabaseDetails, PluginSettings} from "../ui/settingTabs"; import ObsidianSyncNotionPlugin from "../main"; import { getNowFileMarkdownContentNext } from "./upload_next/getMarkdownNext"; import { getNowFileMarkdownContentGeneral } from "./upload_general/getMarkdownGeneral"; @@ -12,10 +12,11 @@ import {getNowFileMarkdownContentCustom} from "./upoload_custom/getMarkdownCusto export async function uploadCommandNext( plugin: ObsidianSyncNotionPlugin, settings: PluginSettings, + dbDetails: DatabaseDetails, app: App, ) { - const { notionAPINext, databaseIDNext } = settings; + const { notionAPI, databaseID } = dbDetails; // Check if NNon exists // if (NNon === undefined) { @@ -25,7 +26,7 @@ export async function uploadCommandNext( // } // Check if the user has set up the Notion API and database ID - if (notionAPINext === "" || databaseIDNext === "") { + if (notionAPI === "" || databaseID === "") { const setAPIMessage = i18nConfig["set-api-id"]; new Notice(setAPIMessage); return; @@ -35,7 +36,7 @@ export async function uploadCommandNext( if (markDownData) { const { basename } = nowFile; - const upload = new Upload2NotionNext(plugin); + const upload = new Upload2NotionNext(plugin, dbDetails); const res = await upload.syncMarkdownToNotionNext(basename, emoji, cover, tags, type, slug, stats, category, summary, paword, favicon, datetime, markDownData, nowFile, this.app); if (res.status === 200) { @@ -52,13 +53,14 @@ export async function uploadCommandNext( export async function uploadCommandGeneral( 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; @@ -69,7 +71,7 @@ export async function uploadCommandGeneral( if (markDownData) { const { basename } = nowFile; - const upload = new Upload2NotionGeneral(plugin); + const upload = new Upload2NotionGeneral(plugin, dbDetails); const res = await upload.syncMarkdownToNotionGeneral(basename, cover, tags, markDownData, nowFile, this.app); if (res.status === 200) { diff --git a/src/upload/upload_general/Upload2NotionGeneral.ts b/src/upload/upload_general/Upload2NotionGeneral.ts index 18c707a..71f8dc0 100644 --- a/src/upload/upload_general/Upload2NotionGeneral.ts +++ b/src/upload/upload_general/Upload2NotionGeneral.ts @@ -4,14 +4,15 @@ 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 { UploadBaseGeneral } from "./BaseUpload2NotionGeneral"; import { updateYamlInfo } from "../updateYaml"; export class Upload2NotionGeneral extends UploadBaseGeneral { settings: PluginSettings; + dbDetails: DatabaseDetails; - constructor(plugin: MyPlugin) { + constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) { super(plugin); } @@ -26,8 +27,9 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { ) { await this.deletePage(notionID); + const { databaseID } = this.dbDetails; const databasecover = await this.getDataBase( - this.plugin.settings.databaseIDGeneral, + databaseID, ); if (cover == null) { @@ -125,7 +127,10 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { const file2Block = markdownToBlocks(__content, options); const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter; - const notionID = frontmasster ? frontmasster.notionID : null; + const {abName} = this.dbDetails + const notionIDKey = `${abName}-NotionID`; + const notionID = frontmasster ? frontmasster[notionIDKey] : null; + if (notionID) { res = await this.updatePage( diff --git a/src/upload/upload_next/Upload2NotionNext.ts b/src/upload/upload_next/Upload2NotionNext.ts index 480c962..a1e0d2f 100644 --- a/src/upload/upload_next/Upload2NotionNext.ts +++ b/src/upload/upload_next/Upload2NotionNext.ts @@ -5,14 +5,15 @@ 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 {LIMITS, paragraph} from "@tryfabric/martian/src/notion"; export class Upload2NotionNext extends UploadBaseNext { settings: PluginSettings; + dbDetails: DatabaseDetails - constructor(plugin: MyPlugin) { + constructor(plugin: MyPlugin, dbDetails: DatabaseDetails) { super(plugin); } @@ -36,7 +37,9 @@ export class Upload2NotionNext extends UploadBaseNext { ) { await this.deletePage(notionID) - const databasecover = await this.getDataBase(this.plugin.settings.databaseIDNext) + const { databaseID} = this.dbDetails + + const databasecover = await this.getDataBase(databaseID) if (cover == null) { cover = databasecover @@ -216,7 +219,10 @@ export class Upload2NotionNext extends UploadBaseNext { const __content = yamlContent.__content const file2Block = markdownToBlocks(__content, options); const frontmasster = app.metadataCache.getFileCache(nowFile)?.frontmatter - const notionID = frontmasster ? frontmasster.notionID : null + const {abName} = this.dbDetails + const notionIDKey = `${abName}-NotionID`; + const notionID = frontmasster ? frontmasster[notionIDKey] : null; + // increase the limits // Motivated by https://github.com/tryfabric/martian/issues/51