Skip to content

Commit

Permalink
solve: the fail to load of mobile caused by the node version
Browse files Browse the repository at this point in the history
  • Loading branch information
jxpeng98 committed Sep 1, 2024
1 parent a90e487 commit 1b385cc
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 169 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
.history
.history

# local data
local-data
112 changes: 56 additions & 56 deletions src/upload/upload_general/Upload2NotionGeneral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MyPlugin from "src/main";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
import {UploadBaseGeneral} from "./BaseUpload2NotionGeneral";
import {updateYamlInfo} from "../updateYaml";
// import fetch from 'node-fetch';
import fetch from 'node-fetch';
import {i18nConfig} from "../../lang/I18n";

interface CreatePageResponse {
Expand Down Expand Up @@ -166,61 +166,61 @@ export class Upload2NotionGeneral extends UploadBaseGeneral {
}
}

// 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();
//
// if (!response.ok) {
// new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
// console.log(`Error message: \n ${data.message}`);
// } else {
// console.log(`Page created: ${data.url}`);
// console.log(`Page ID: ${data.id}`);
// }
//
// // upload the rest of the blocks
// if (pushCount > 0) {
// for (let i = 0; i < pushCount; i++) {
// const extraBlocks = {
// children: extraArr[i],
// };
//
// console.log(extraBlocks)
//
// const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
// method: "PATCH",
// headers: {
// "Content-Type": "application/json",
// "Authorization": "Bearer " + notionAPI,
// "Notion-Version": "2022-06-28",
// },
// body: JSON.stringify(extraBlocks),
// });
//
// const extraData: any = await extraResponse.json();
//
// if (!extraResponse.ok) {
// new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
// console.log(`Error message: \n ${extraData.message}`);
// } else {
// console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
// if (i === pushCount - 1) {
// console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
// new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
// }
// }
// }
// }
// }
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();

if (!response.ok) {
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
console.log(`Error message: \n ${data.message}`);
} else {
console.log(`Page created: ${data.url}`);
console.log(`Page ID: ${data.id}`);
}

// upload the rest of the blocks
if (pushCount > 0) {
for (let i = 0; i < pushCount; i++) {
const extraBlocks = {
children: extraArr[i],
};

console.log(extraBlocks)

const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + notionAPI,
"Notion-Version": "2022-06-28",
},
body: JSON.stringify(extraBlocks),
});

const extraData: any = await extraResponse.json();

if (!extraResponse.ok) {
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
console.log(`Error message: \n ${extraData.message}`);
} else {
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
if (i === pushCount - 1) {
console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
}
}
}
}
}

return {
response,
Expand Down
112 changes: 56 additions & 56 deletions src/upload/upload_next/Upload2NotionNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import MyPlugin from "src/main";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
import {updateYamlInfo} from "../updateYaml";
import {LIMITS, paragraph} from "@jxpeng98/martian/src/notion";
// import fetch from 'node-fetch';
import fetch from 'node-fetch';
import {i18nConfig} from "../../lang/I18n";

interface CreatePageResponse {
Expand Down Expand Up @@ -266,61 +266,61 @@ export class Upload2NotionNext extends UploadBaseNext {
}
}

// 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();
//
// if (!response.ok) {
// new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
// console.log(`Error message: \n ${data.message}`);
// } else {
// console.log(`Page created: ${data.url}`);
// console.log(`Page ID: ${data.id}`);
// }
//
// // upload the rest of the blocks
// if (pushCount > 0) {
// for (let i = 0; i < pushCount; i++) {
// const extraBlocks = {
// children: extraArr[i],
// };
//
// console.log(extraBlocks)
//
// const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
// method: "PATCH",
// headers: {
// "Content-Type": "application/json",
// "Authorization": "Bearer " + notionAPI,
// "Notion-Version": "2022-06-28",
// },
// body: JSON.stringify(extraBlocks),
// });
//
// const extraData: any = await extraResponse.json();
//
// if (!extraResponse.ok) {
// new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
// console.log(`Error message: \n ${extraData.message}`);
// } else {
// console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
// if (i === pushCount - 1) {
// console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
// new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
// }
// }
// }
// }
// }
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();

if (!response.ok) {
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
console.log(`Error message: \n ${data.message}`);
} else {
console.log(`Page created: ${data.url}`);
console.log(`Page ID: ${data.id}`);
}

// upload the rest of the blocks
if (pushCount > 0) {
for (let i = 0; i < pushCount; i++) {
const extraBlocks = {
children: extraArr[i],
};

console.log(extraBlocks)

const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + notionAPI,
"Notion-Version": "2022-06-28",
},
body: JSON.stringify(extraBlocks),
});

const extraData: any = await extraResponse.json();

if (!extraResponse.ok) {
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
console.log(`Error message: \n ${extraData.message}`);
} else {
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
if (i === pushCount - 1) {
console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
}
}
}
}
}

return {
response,
Expand Down
112 changes: 56 additions & 56 deletions src/upload/upoload_custom/Upload2NotionCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import MyPlugin from "src/main";
import {DatabaseDetails, PluginSettings} from "../../ui/settingTabs";
import {updateYamlInfo} from "../updateYaml";
import {UploadBaseCustom} from "./BaseUpload2NotionCustom";
// import fetch from 'node-fetch';
import fetch from 'node-fetch';
import {i18nConfig} from "../../lang/I18n";


Expand Down Expand Up @@ -138,61 +138,61 @@ export class Upload2NotionCustom extends UploadBaseCustom {
}
}

// 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();
//
// if (!response.ok) {
// new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
// console.log(`Error message: \n ${data.message}`);
// } else {
// console.log(`Page created: ${data.url}`);
// console.log(`Page ID: ${data.id}`);
// }
//
// // upload the rest of the blocks
// if (pushCount > 0) {
// for (let i = 0; i < pushCount; i++) {
// const extraBlocks = {
// children: extraArr[i],
// };
//
// console.log(extraBlocks)
//
// const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
// method: "PATCH",
// headers: {
// "Content-Type": "application/json",
// "Authorization": "Bearer " + notionAPI,
// "Notion-Version": "2022-06-28",
// },
// body: JSON.stringify(extraBlocks),
// });
//
// const extraData: any = await extraResponse.json();
//
// if (!extraResponse.ok) {
// new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
// console.log(`Error message: \n ${extraData.message}`);
// } else {
// console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
// if (i === pushCount - 1) {
// console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
// new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
// }
// }
// }
// }
// }
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();

if (!response.ok) {
new Notice(`Error ${data.status}: ${data.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
console.log(`Error message: \n ${data.message}`);
} else {
console.log(`Page created: ${data.url}`);
console.log(`Page ID: ${data.id}`);
}

// upload the rest of the blocks
if (pushCount > 0) {
for (let i = 0; i < pushCount; i++) {
const extraBlocks = {
children: extraArr[i],
};

console.log(extraBlocks)

const extraResponse = await fetch(`https://api.notion.com/v1/blocks/${data.id}/children`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + notionAPI,
"Notion-Version": "2022-06-28",
},
body: JSON.stringify(extraBlocks),
});

const extraData: any = await extraResponse.json();

if (!extraResponse.ok) {
new Notice(`Error ${extraData.status}: ${extraData.code} \n ${i18nConfig["CheckConsole"]}`, 5000);
console.log(`Error message: \n ${extraData.message}`);
} else {
console.log(`${i18nConfig["ExtraBlockUploaded"]} to page: ${data.id}`);
if (i === pushCount - 1) {
console.log(`${i18nConfig["BlockUploaded"]} to page: ${data.id}`);
new Notice(`${i18nConfig["BlockUploaded"]} page: ${data.id}`, 5000);
}
}
}
}
}

return {
response, // for status code
Expand Down

0 comments on commit 1b385cc

Please sign in to comment.