mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 16:35:57 +08:00
use node-fetch to post notes for a better debug
This commit is contained in:
@@ -41,6 +41,7 @@ const ctx = await esbuild.context({
|
|||||||
"@codemirror/view",
|
"@codemirror/view",
|
||||||
...builtins,
|
...builtins,
|
||||||
],
|
],
|
||||||
|
platform: "node",
|
||||||
format: "cjs",
|
format: "cjs",
|
||||||
target: "es2016",
|
target: "es2016",
|
||||||
logLevel: "info",
|
logLevel: "info",
|
||||||
|
|||||||
@@ -19,13 +19,14 @@
|
|||||||
"@typescript-eslint/parser": "^6.16.0",
|
"@typescript-eslint/parser": "^6.16.0",
|
||||||
"builtin-modules": "^3.3.0",
|
"builtin-modules": "^3.3.0",
|
||||||
"esbuild": "0.19.5",
|
"esbuild": "0.19.5",
|
||||||
"obsidian": "latest",
|
"obsidian": "^1.6.6",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
"typescript": "5.2.2"
|
"typescript": "5.2.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tryfabric/martian": "^1.2.4",
|
"@tryfabric/martian": "^1.2.4",
|
||||||
"https-proxy-agent": "^7.0.2",
|
"https-proxy-agent": "^7.0.2",
|
||||||
|
"node-fetch": "^3.3.2",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"remark-math": "^6.0.0",
|
"remark-math": "^6.0.0",
|
||||||
"yaml": "^2.3.4",
|
"yaml": "^2.3.4",
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import {App, Notice, requestUrl, TFile} from "obsidian";
|
import {App, Notice, requestUrl, TFile} from "obsidian";
|
||||||
import { markdownToBlocks } from "@tryfabric/martian";
|
import {markdownToBlocks} from "@tryfabric/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
// import * as yaml from "yaml"
|
// import * as yaml from "yaml"
|
||||||
import MyPlugin from "src/main";
|
import MyPlugin from "src/main";
|
||||||
import { DatabaseDetails, PluginSettings } from "../../ui/settingTabs";
|
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||||
import { updateYamlInfo } from "../updateYaml";
|
import {updateYamlInfo} from "../updateYaml";
|
||||||
import { UploadBaseCustom } from "./BaseUpload2NotionCustom";
|
import {UploadBaseCustom} from "./BaseUpload2NotionCustom";
|
||||||
import axios from 'axios';
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
|
|
||||||
export class Upload2NotionCustom extends UploadBaseCustom {
|
export class Upload2NotionCustom extends UploadBaseCustom {
|
||||||
settings: PluginSettings;
|
settings: PluginSettings;
|
||||||
@@ -27,7 +28,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
) {
|
) {
|
||||||
await this.deletePage(notionID);
|
await this.deletePage(notionID);
|
||||||
|
|
||||||
const { databaseID } = this.dbDetails;
|
const {databaseID} = this.dbDetails;
|
||||||
|
|
||||||
const databaseCover = await this.getDataBase(
|
const databaseCover = await this.getDataBase(
|
||||||
databaseID
|
databaseID
|
||||||
@@ -74,8 +75,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
|
|
||||||
console.log(bodyString)
|
console.log(bodyString)
|
||||||
|
|
||||||
try {
|
const response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
await fetch("https://api.notion.com/v1/pages", {
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -83,11 +83,15 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
"Notion-Version": "2022-06-28",
|
"Notion-Version": "2022-06-28",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
})
|
});
|
||||||
} catch (e) {
|
|
||||||
console.log(JSON.stringify(e))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const data: any = await response.json();
|
||||||
|
new Notice(`Error ${data.status}: ${data.code} \n Check the console for more information \n opt+cmd+i/ctrl+shift+i`, 5000);
|
||||||
|
console.log(data.message);
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async syncMarkdownToNotionCustom(
|
async syncMarkdownToNotionCustom(
|
||||||
@@ -109,7 +113,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
const file2Block = markdownToBlocks(__content, options);
|
const file2Block = markdownToBlocks(__content, options);
|
||||||
const frontmasster =
|
const frontmasster =
|
||||||
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
app.metadataCache.getFileCache(nowFile)?.frontmatter;
|
||||||
const { abName } = this.dbDetails
|
const {abName} = this.dbDetails
|
||||||
const notionIDKey = `NotionID-${abName}`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
const notionID = frontmasster ? frontmasster[notionIDKey] : null;
|
||||||
|
|
||||||
@@ -208,7 +212,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
};
|
};
|
||||||
case "multi_select":
|
case "multi_select":
|
||||||
return {
|
return {
|
||||||
multi_select: Array.isArray(value) ? value.map(item => ({ name: item })) : [{ name: value }],
|
multi_select: Array.isArray(value) ? value.map(item => ({name: item})) : [{name: value}],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,7 +226,7 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
const properties: { [key: string]: any } = {};
|
const properties: { [key: string]: any } = {};
|
||||||
|
|
||||||
// Only include custom properties that have values
|
// Only include custom properties that have values
|
||||||
customProperties.forEach(({ customName, customType }) => {
|
customProperties.forEach(({customName, customType}) => {
|
||||||
if (customValues[customName] !== undefined) {
|
if (customValues[customName] !== undefined) {
|
||||||
properties[customName] = this.buildPropertyObject(customName, customType, customValues);
|
properties[customName] = this.buildPropertyObject(customName, customType, customValues);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user