mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-30 17:18:36 +08:00
Compare commits
6 Commits
2.4.2
...
a950e2e301
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a950e2e301 | ||
|
|
aac7bc154a | ||
|
|
a573ef728d | ||
|
|
1344c14933 | ||
|
|
c1f4ecd14b | ||
|
|
5942876c92 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,4 +1,15 @@
|
|||||||
## Fix
|
## Fix
|
||||||
|
|
||||||
- Fix a bug that plugin does not work when Obsidian language is not set to Englisht, Chinese or Japanese.
|
- Fix the bug that the plugin does not work in the mobile app.
|
||||||
- 修复了当 Obsidian 语言设置不是英文、中文或日文时插件无法工作的问题。
|
- 修复了在移动端应用中插件无法工作的问题。
|
||||||
|
|
||||||
|
## Feature
|
||||||
|
|
||||||
|
- Both desktop and mobile apps support syncing long markdown files.
|
||||||
|
- 桌面端和移动端应用都支持长篇 markdown 文件同步。
|
||||||
|
|
||||||
|
## Issue
|
||||||
|
- Bullet list over 3 levels is not supported.
|
||||||
|
- 无法同步超过三个分支的列表。
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ 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",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "share-to-notionnext",
|
"id": "share-to-notionnext",
|
||||||
"name": "Share to NotionNext",
|
"name": "Share to NotionNext",
|
||||||
"version": "2.4.2",
|
"version": "2.5.0",
|
||||||
"minAppVersion": "0.0.1",
|
"minAppVersion": "0.0.1",
|
||||||
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
"description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.",
|
||||||
"author": "EasyChris, jxpeng98",
|
"author": "EasyChris, jxpeng98",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "share-to-notionnext",
|
"name": "share-to-notionnext",
|
||||||
"version": "2.4.2",
|
"version": "2.5.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Share files to any Notion database using the Notion API, originally created by EasyChris/obsidian-to-notion.",
|
"description": "Share files to any Notion database using the Notion API, originally created by EasyChris/obsidian-to-notion.",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
@@ -26,7 +26,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jxpeng98/martian": "^1.2.7",
|
"@jxpeng98/martian": "^1.2.7",
|
||||||
"https-proxy-agent": "^7.0.2",
|
"https-proxy-agent": "^7.0.2",
|
||||||
"node-fetch": "^3.3.2",
|
|
||||||
"remark-math": "^6.0.0",
|
"remark-math": "^6.0.0",
|
||||||
"yaml": "^2.3.4",
|
"yaml": "^2.3.4",
|
||||||
"yaml-front-matter": "^4.1.1"
|
"yaml-front-matter": "^4.1.1"
|
||||||
|
|||||||
@@ -50,8 +50,10 @@ export async function uploadCommandNext(
|
|||||||
const {response} = res;
|
const {response} = res;
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||||
|
console.log(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
||||||
|
console.log(`${i18nConfig["sync-fail"]} ${basename}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -88,8 +90,10 @@ export async function uploadCommandGeneral(
|
|||||||
const {response} = res;
|
const {response} = res;
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||||
|
console.log(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
||||||
|
console.log(`${i18nConfig["sync-fail"]} ${basename}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -124,10 +128,13 @@ export async function uploadCommandCustom(
|
|||||||
const res = await upload.syncMarkdownToNotionCustom(cover, customValues, markDownData, nowFile, this.app);
|
const res = await upload.syncMarkdownToNotionCustom(cover, customValues, markDownData, nowFile, this.app);
|
||||||
|
|
||||||
const {response} = res;
|
const {response} = res;
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
new Notice(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`).noticeEl.style.color = "green";
|
||||||
|
console.log(`${i18nConfig["sync-preffix"]} ${basename} ${i18nConfig["sync-success"]}`);
|
||||||
} else {
|
} else {
|
||||||
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
new Notice(`${i18nConfig["sync-fail"]} ${basename}`, 5000);
|
||||||
|
console.log(`${i18nConfig["sync-fail"]} ${basename}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import {App, Notice, TFile, Platform, requestUrl} from "obsidian";
|
import {App, Notice, TFile, requestUrl} from "obsidian";
|
||||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
import MyPlugin from "src/main";
|
import MyPlugin from "src/main";
|
||||||
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
|
||||||
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
|
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
|
||||||
import {updateYamlInfo} from "../updateYaml";
|
import {updateYamlInfo} from "../updateYaml";
|
||||||
import fetch from 'node-fetch';
|
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
interface CreatePageResponse {
|
interface CreatePageResponse {
|
||||||
@@ -142,15 +141,10 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(bodyString)
|
console.log(bodyString)
|
||||||
console.log(Platform.isDesktopApp)
|
|
||||||
|
|
||||||
let response: any;
|
let response: any;
|
||||||
let data: any;
|
let data: any;
|
||||||
|
|
||||||
if (Platform.isMobileApp) {
|
|
||||||
if(childArrLength > 100) {
|
|
||||||
new Notice(i18nConfig["reach-mobile-limit"], 5000);
|
|
||||||
} else {
|
|
||||||
response = await requestUrl({
|
response = await requestUrl({
|
||||||
url: `https://api.notion.com/v1/pages`,
|
url: `https://api.notion.com/v1/pages`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -162,31 +156,22 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
"Notion-Version": "2022-06-28",
|
"Notion-Version": "2022-06-28",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
throw: false
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
|
||||||
response = await fetch("https://api.notion.com/v1/pages", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Authorization": "Bearer " + notionAPI,
|
|
||||||
"Notion-Version": "2022-06-28",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(bodyString),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
data = await response.json();
|
data = await response.json;
|
||||||
|
|
||||||
if (!response.ok) {
|
// console.log(data)
|
||||||
|
// console.log(response.status)
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${data.message}`);
|
console.log(`Error message: \n ${data.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Page created: ${data.url}`);
|
console.log(`Page created: ${data.url}`);
|
||||||
console.log(`Page ID: ${data.id}`);
|
console.log(`Page ID: ${data.id}`);
|
||||||
}
|
}
|
||||||
|
//
|
||||||
// upload the rest of the blocks
|
// upload the rest of the blocks
|
||||||
if (pushCount > 0) {
|
if (pushCount > 0) {
|
||||||
for (let i = 0; i < pushCount; i++) {
|
for (let i = 0; i < pushCount; i++) {
|
||||||
@@ -196,7 +181,8 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
|
|
||||||
console.log(extraBlocks)
|
console.log(extraBlocks)
|
||||||
|
|
||||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
const extraResponse = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -206,9 +192,9 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
body: JSON.stringify(extraBlocks),
|
body: JSON.stringify(extraBlocks),
|
||||||
});
|
});
|
||||||
|
|
||||||
const extraData: any = await extraResponse.json();
|
const extraData: any = await extraResponse.json;
|
||||||
|
|
||||||
if (!extraResponse.ok) {
|
if (extraResponse.status !== 200) {
|
||||||
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${extraData.message}`);
|
console.log(`Error message: \n ${extraData.message}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -220,7 +206,6 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response,
|
response,
|
||||||
@@ -266,7 +251,8 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
|
|
||||||
let {response, data} = res;
|
let {response, data} = res;
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
// console.log(response)
|
||||||
|
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
await updateYamlInfo(
|
await updateYamlInfo(
|
||||||
markdown,
|
markdown,
|
||||||
@@ -274,23 +260,9 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
data,
|
data,
|
||||||
app,
|
app,
|
||||||
this.plugin,
|
this.plugin,
|
||||||
this.dbDetails
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isMobileApp) {
|
|
||||||
if (response && response.status === 200) {
|
|
||||||
await updateYamlInfo(
|
|
||||||
markdown,
|
|
||||||
nowFile,
|
|
||||||
response,
|
|
||||||
app,
|
|
||||||
this.plugin,
|
|
||||||
this.dbDetails,
|
this.dbDetails,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
||||||
import {App, Notice, TFile, Platform, requestUrl} from "obsidian";
|
import {App, Notice, TFile, requestUrl} from "obsidian";
|
||||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
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 {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
import {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
||||||
import fetch from 'node-fetch';
|
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
interface CreatePageResponse {
|
interface CreatePageResponse {
|
||||||
@@ -247,10 +246,6 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
let response: any;
|
let response: any;
|
||||||
let data: any;
|
let data: any;
|
||||||
|
|
||||||
if (Platform.isMobileApp) {
|
|
||||||
if(childArrLength > 100) {
|
|
||||||
new Notice(i18nConfig["reach-mobile-limit"], 5000);
|
|
||||||
} else {
|
|
||||||
response = await requestUrl({
|
response = await requestUrl({
|
||||||
url: `https://api.notion.com/v1/pages`,
|
url: `https://api.notion.com/v1/pages`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -262,31 +257,22 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
"Notion-Version": "2022-06-28",
|
"Notion-Version": "2022-06-28",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
throw: false
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
|
||||||
response = await fetch("https://api.notion.com/v1/pages", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Authorization": "Bearer " + notionAPI,
|
|
||||||
"Notion-Version": "2022-06-28",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(bodyString),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
data = await response.json();
|
data = await response.json;
|
||||||
|
|
||||||
if (!response.ok) {
|
// console.log(data)
|
||||||
|
// console.log(response.status)
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${data.message}`);
|
console.log(`Error message: \n ${data.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Page created: ${data.url}`);
|
console.log(`Page created: ${data.url}`);
|
||||||
console.log(`Page ID: ${data.id}`);
|
console.log(`Page ID: ${data.id}`);
|
||||||
}
|
}
|
||||||
|
//
|
||||||
// upload the rest of the blocks
|
// upload the rest of the blocks
|
||||||
if (pushCount > 0) {
|
if (pushCount > 0) {
|
||||||
for (let i = 0; i < pushCount; i++) {
|
for (let i = 0; i < pushCount; i++) {
|
||||||
@@ -296,7 +282,8 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
|
|
||||||
console.log(extraBlocks)
|
console.log(extraBlocks)
|
||||||
|
|
||||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
const extraResponse = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -306,9 +293,9 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
body: JSON.stringify(extraBlocks),
|
body: JSON.stringify(extraBlocks),
|
||||||
});
|
});
|
||||||
|
|
||||||
const extraData: any = await extraResponse.json();
|
const extraData: any = await extraResponse.json;
|
||||||
|
|
||||||
if (!extraResponse.ok) {
|
if (extraResponse.status !== 200) {
|
||||||
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${extraData.message}`);
|
console.log(`Error message: \n ${extraData.message}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -320,7 +307,6 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response,
|
response,
|
||||||
@@ -416,7 +402,8 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
|
|
||||||
let {response, data} = res;
|
let {response, data} = res;
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
// console.log(response)
|
||||||
|
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
await updateYamlInfo(
|
await updateYamlInfo(
|
||||||
markdown,
|
markdown,
|
||||||
@@ -424,23 +411,9 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
data,
|
data,
|
||||||
app,
|
app,
|
||||||
this.plugin,
|
this.plugin,
|
||||||
this.dbDetails
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isMobileApp) {
|
|
||||||
if (response && response.status === 200) {
|
|
||||||
await updateYamlInfo(
|
|
||||||
markdown,
|
|
||||||
nowFile,
|
|
||||||
response,
|
|
||||||
app,
|
|
||||||
this.plugin,
|
|
||||||
this.dbDetails,
|
this.dbDetails,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import {App, Notice, Platform, TFile, requestUrl} from "obsidian";
|
import {App, Notice, TFile, requestUrl} from "obsidian";
|
||||||
import {markdownToBlocks} from "@jxpeng98/martian";
|
import {markdownToBlocks} from "@jxpeng98/martian";
|
||||||
import * as yamlFrontMatter from "yaml-front-matter";
|
import * as yamlFrontMatter from "yaml-front-matter";
|
||||||
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 fetch from 'node-fetch';
|
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
|
|
||||||
@@ -114,15 +113,10 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(bodyString)
|
console.log(bodyString)
|
||||||
console.log(Platform.isDesktopApp)
|
|
||||||
|
|
||||||
let response: any;
|
let response: any;
|
||||||
let data: any;
|
let data: any;
|
||||||
|
|
||||||
if (Platform.isMobileApp) {
|
|
||||||
if(childArrLength > 100) {
|
|
||||||
new Notice(i18nConfig["reach-mobile-limit"], 5000);
|
|
||||||
} else {
|
|
||||||
response = await requestUrl({
|
response = await requestUrl({
|
||||||
url: `https://api.notion.com/v1/pages`,
|
url: `https://api.notion.com/v1/pages`,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -134,31 +128,22 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
"Notion-Version": "2022-06-28",
|
"Notion-Version": "2022-06-28",
|
||||||
},
|
},
|
||||||
body: JSON.stringify(bodyString),
|
body: JSON.stringify(bodyString),
|
||||||
});
|
throw: false
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
|
||||||
response = await fetch("https://api.notion.com/v1/pages", {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"Authorization": "Bearer " + notionAPI,
|
|
||||||
"Notion-Version": "2022-06-28",
|
|
||||||
},
|
|
||||||
body: JSON.stringify(bodyString),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
data = await response.json();
|
data = await response.json;
|
||||||
|
|
||||||
if (!response.ok) {
|
// console.log(data)
|
||||||
|
// console.log(response.status)
|
||||||
|
|
||||||
|
if (response.status !== 200) {
|
||||||
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${data.message}`);
|
console.log(`Error message: \n ${data.message}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Page created: ${data.url}`);
|
console.log(`Page created: ${data.url}`);
|
||||||
console.log(`Page ID: ${data.id}`);
|
console.log(`Page ID: ${data.id}`);
|
||||||
}
|
}
|
||||||
|
//
|
||||||
// upload the rest of the blocks
|
// upload the rest of the blocks
|
||||||
if (pushCount > 0) {
|
if (pushCount > 0) {
|
||||||
for (let i = 0; i < pushCount; i++) {
|
for (let i = 0; i < pushCount; i++) {
|
||||||
@@ -168,7 +153,8 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
|
|
||||||
console.log(extraBlocks)
|
console.log(extraBlocks)
|
||||||
|
|
||||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
const extraResponse = await requestUrl({
|
||||||
|
url: `https://api.notion.com/v1/blocks/${data.id}/children`,
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -178,9 +164,9 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
body: JSON.stringify(extraBlocks),
|
body: JSON.stringify(extraBlocks),
|
||||||
});
|
});
|
||||||
|
|
||||||
const extraData: any = await extraResponse.json();
|
const extraData: any = await extraResponse.json;
|
||||||
|
|
||||||
if (!extraResponse.ok) {
|
if (extraResponse.status !== 200) {
|
||||||
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
|
||||||
console.log(`Error message: \n ${extraData.message}`);
|
console.log(`Error message: \n ${extraData.message}`);
|
||||||
} else {
|
} else {
|
||||||
@@ -192,7 +178,6 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response, // for status code
|
response, // for status code
|
||||||
@@ -238,7 +223,6 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
|
|
||||||
// console.log(response)
|
// console.log(response)
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
|
||||||
if (response && response.status === 200) {
|
if (response && response.status === 200) {
|
||||||
await updateYamlInfo(
|
await updateYamlInfo(
|
||||||
markdown,
|
markdown,
|
||||||
@@ -246,23 +230,9 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
data,
|
data,
|
||||||
app,
|
app,
|
||||||
this.plugin,
|
this.plugin,
|
||||||
this.dbDetails
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Platform.isMobileApp) {
|
|
||||||
if (response && response.status === 200) {
|
|
||||||
await updateYamlInfo(
|
|
||||||
markdown,
|
|
||||||
nowFile,
|
|
||||||
response,
|
|
||||||
app,
|
|
||||||
this.plugin,
|
|
||||||
this.dbDetails,
|
this.dbDetails,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ export async function getNowFileMarkdownContentCustom(
|
|||||||
|
|
||||||
// If a 'title' type property exists, use the file's basename as its value
|
// If a 'title' type property exists, use the file's basename as its value
|
||||||
if (titleProperty) {
|
if (titleProperty) {
|
||||||
customValues[titleProperty.customName] = nowFile.basename; // Use 'basename' for the file name without extension
|
customValues[titleProperty.customName] =
|
||||||
|
(FileCache.frontmatter && FileCache.frontmatter[titleProperty.customName]) ?
|
||||||
|
FileCache.frontmatter[titleProperty.customName] : // use the front matter value if it exists
|
||||||
|
nowFile.basename; // Use 'basename' for the file name without extension
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -460,6 +460,13 @@ commander@^8.3.0:
|
|||||||
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
|
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
|
||||||
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
|
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
|
||||||
|
|
||||||
|
cross-fetch@^4.0.0:
|
||||||
|
version "4.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-4.0.0.tgz#f037aef1580bb3a1a35164ea2a848ba81b445983"
|
||||||
|
integrity sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==
|
||||||
|
dependencies:
|
||||||
|
node-fetch "^2.6.12"
|
||||||
|
|
||||||
data-uri-to-buffer@^4.0.0:
|
data-uri-to-buffer@^4.0.0:
|
||||||
version "4.0.1"
|
version "4.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e"
|
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e"
|
||||||
@@ -1199,7 +1206,7 @@ node-domexception@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
|
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
|
||||||
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
|
integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==
|
||||||
|
|
||||||
node-fetch@^2.6.1:
|
node-fetch@^2.6.1, node-fetch@^2.6.12:
|
||||||
version "2.7.0"
|
version "2.7.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
|
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
|
||||||
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
|
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
|
||||||
|
|||||||
Reference in New Issue
Block a user