mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
Backup mobile requesturl after version 2.4.1
This commit is contained in:
@@ -76,6 +76,9 @@ export async function uploadCommandGeneral(
|
|||||||
|
|
||||||
const {markDownData, nowFile, cover, tags} = await getNowFileMarkdownContentGeneral(app, settings)
|
const {markDownData, nowFile, cover, tags} = await getNowFileMarkdownContentGeneral(app, settings)
|
||||||
|
|
||||||
|
new Notice(`Start upload ${nowFile.basename}`);
|
||||||
|
console.log(`Start upload ${nowFile.basename}`);
|
||||||
|
|
||||||
if (markDownData) {
|
if (markDownData) {
|
||||||
const {basename} = nowFile;
|
const {basename} = nowFile;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ 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 fetch from 'node-fetch';
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
interface CreatePageResponse {
|
interface CreatePageResponse {
|
||||||
@@ -166,61 +166,61 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
// if (Platform.isDesktopApp) {
|
||||||
response = await fetch("https://api.notion.com/v1/pages", {
|
// response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notionAPI,
|
// "Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
// "Notion-Version": "2022-06-28",
|
||||||
},
|
// },
|
||||||
body: JSON.stringify(bodyString),
|
// body: JSON.stringify(bodyString),
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
data = await response.json();
|
// data = await response.json();
|
||||||
|
//
|
||||||
if (!response.ok) {
|
// if (!response.ok) {
|
||||||
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++) {
|
||||||
const extraBlocks = {
|
// const extraBlocks = {
|
||||||
children: extraArr[i],
|
// children: extraArr[i],
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
console.log(extraBlocks)
|
// console.log(extraBlocks)
|
||||||
|
//
|
||||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
// const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
||||||
method: "PATCH",
|
// method: "PATCH",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notionAPI,
|
// "Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
// "Notion-Version": "2022-06-28",
|
||||||
},
|
// },
|
||||||
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.ok) {
|
||||||
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 {
|
||||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
// console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
||||||
if (i === pushCount - 1) {
|
// if (i === pushCount - 1) {
|
||||||
console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
|
// console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
|
||||||
new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
|
// new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response,
|
response,
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
import {UploadBaseNext} from "./BaseUpload2NotionNext";
|
||||||
import {App, Notice, TFile, Platform, requestUrl} from "obsidian";
|
import {App, Notice, TFile, Platform, requestUrl} from "obsidian";
|
||||||
import {Client} from "@notionhq/client";
|
|
||||||
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 * 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 {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
import {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
|
||||||
import fetch from 'node-fetch';
|
// import fetch from 'node-fetch';
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
interface CreatePageResponse {
|
interface CreatePageResponse {
|
||||||
@@ -268,61 +266,61 @@ export class Upload2NotionNext extends UploadBaseNext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
// if (Platform.isDesktopApp) {
|
||||||
response = await fetch("https://api.notion.com/v1/pages", {
|
// response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notionAPI,
|
// "Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
// "Notion-Version": "2022-06-28",
|
||||||
},
|
// },
|
||||||
body: JSON.stringify(bodyString),
|
// body: JSON.stringify(bodyString),
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
data = await response.json();
|
// data = await response.json();
|
||||||
|
//
|
||||||
if (!response.ok) {
|
// if (!response.ok) {
|
||||||
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++) {
|
||||||
const extraBlocks = {
|
// const extraBlocks = {
|
||||||
children: extraArr[i],
|
// children: extraArr[i],
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
console.log(extraBlocks)
|
// console.log(extraBlocks)
|
||||||
|
//
|
||||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
// const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
||||||
method: "PATCH",
|
// method: "PATCH",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notionAPI,
|
// "Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
// "Notion-Version": "2022-06-28",
|
||||||
},
|
// },
|
||||||
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.ok) {
|
||||||
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 {
|
||||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
// console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
||||||
if (i === pushCount - 1) {
|
// if (i === pushCount - 1) {
|
||||||
console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
|
// console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
|
||||||
new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
|
// new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response,
|
response,
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import {App, Notice, Platform, TFile} from "obsidian";
|
import {App, Notice, Platform, 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 * 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 fetch from 'node-fetch';
|
// import fetch from 'node-fetch';
|
||||||
import {i18nConfig} from "../../lang/I18n";
|
import {i18nConfig} from "../../lang/I18n";
|
||||||
|
|
||||||
|
|
||||||
@@ -139,61 +138,61 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Platform.isDesktopApp) {
|
// if (Platform.isDesktopApp) {
|
||||||
response = await fetch("https://api.notion.com/v1/pages", {
|
// response = await fetch("https://api.notion.com/v1/pages", {
|
||||||
method: "POST",
|
// method: "POST",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notionAPI,
|
// "Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
// "Notion-Version": "2022-06-28",
|
||||||
},
|
// },
|
||||||
body: JSON.stringify(bodyString),
|
// body: JSON.stringify(bodyString),
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
data = await response.json();
|
// data = await response.json();
|
||||||
|
//
|
||||||
if (!response.ok) {
|
// if (!response.ok) {
|
||||||
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++) {
|
||||||
const extraBlocks = {
|
// const extraBlocks = {
|
||||||
children: extraArr[i],
|
// children: extraArr[i],
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
console.log(extraBlocks)
|
// console.log(extraBlocks)
|
||||||
|
//
|
||||||
const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
// const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
|
||||||
method: "PATCH",
|
// method: "PATCH",
|
||||||
headers: {
|
// headers: {
|
||||||
"Content-Type": "application/json",
|
// "Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notionAPI,
|
// "Authorization": "Bearer " + notionAPI,
|
||||||
"Notion-Version": "2022-06-28",
|
// "Notion-Version": "2022-06-28",
|
||||||
},
|
// },
|
||||||
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.ok) {
|
||||||
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 {
|
||||||
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
// console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
|
||||||
if (i === pushCount - 1) {
|
// if (i === pushCount - 1) {
|
||||||
console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
|
// console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
|
||||||
new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
|
// new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
response, // for status code
|
response, // for status code
|
||||||
@@ -265,7 +264,6 @@ export class Upload2NotionCustom extends UploadBaseCustom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user