finish some command coding

This commit is contained in:
Jiaxin Peng
2023-12-27 00:27:32 +00:00
parent 59c15f1206
commit fb5f7b502d
8 changed files with 235 additions and 194 deletions

View File

@@ -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) {

View File

@@ -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(

View File

@@ -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