mirror of
https://github.com/jxpeng98/obsidian-to-NotionNext
synced 2026-07-29 08:08:34 +08:00
refactor: remove redundant debug logs from upload commands and base class
This commit is contained in:
@@ -90,12 +90,6 @@ export class Upload2Notion extends UploadBase {
|
|||||||
|
|
||||||
async sync(request: SyncRequest): Promise<NotionPageResponse> {
|
async sync(request: SyncRequest): Promise<NotionPageResponse> {
|
||||||
const startedAt = Date.now();
|
const startedAt = Date.now();
|
||||||
this.debugLog("Upload2Notion", "Sync invoked", {
|
|
||||||
dataset: request.dataset,
|
|
||||||
filePath: request.nowFile.path,
|
|
||||||
databaseId: this.dbDetails.databaseID,
|
|
||||||
abName: this.dbDetails.abName,
|
|
||||||
});
|
|
||||||
|
|
||||||
let response: NotionPageResponse;
|
let response: NotionPageResponse;
|
||||||
|
|
||||||
@@ -113,19 +107,7 @@ export class Upload2Notion extends UploadBase {
|
|||||||
throw new Error(`Unsupported dataset type: ${(request as any).dataset}`);
|
throw new Error(`Unsupported dataset type: ${(request as any).dataset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[Upload2Notion] Notion response status`, response.response?.status);
|
|
||||||
this.debugLog("Upload2Notion", "Sync completed", {
|
|
||||||
status: response.response?.status ?? null,
|
|
||||||
durationMs: Date.now() - startedAt,
|
|
||||||
pageId: response.data?.id ?? null,
|
|
||||||
pageUrl: response.data?.url ?? null,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.response && response.response.status === 200) {
|
if (response.response && response.response.status === 200) {
|
||||||
console.log(`[Upload2Notion] Sync success`, {
|
|
||||||
notionPageId: response.data?.id,
|
|
||||||
notionPageUrl: response.data?.url,
|
|
||||||
});
|
|
||||||
await updateYamlInfo(
|
await updateYamlInfo(
|
||||||
request.markdown,
|
request.markdown,
|
||||||
request.nowFile,
|
request.nowFile,
|
||||||
@@ -247,11 +229,6 @@ export class Upload2Notion extends UploadBase {
|
|||||||
const {abName} = this.dbDetails;
|
const {abName} = this.dbDetails;
|
||||||
const notionIDKey = `NotionID-${abName}`;
|
const notionIDKey = `NotionID-${abName}`;
|
||||||
const notionId = frontMatter[notionIDKey];
|
const notionId = frontMatter[notionIDKey];
|
||||||
this.debugLog("Upload2Notion", "Resolved Notion ID from frontmatter", {
|
|
||||||
filePath: nowFile.path,
|
|
||||||
notionId: notionId ? String(notionId) : null,
|
|
||||||
frontMatterKeys: Object.keys(frontMatter),
|
|
||||||
});
|
|
||||||
return notionId ? String(notionId) : undefined;
|
return notionId ? String(notionId) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ export abstract class UploadBase {
|
|||||||
|
|
||||||
async deletePage(notionID: string) {
|
async deletePage(notionID: string) {
|
||||||
const {notionAPI} = this.dbDetails;
|
const {notionAPI} = this.dbDetails;
|
||||||
this.debugLog("UploadBase", "Deleting Notion page", {
|
|
||||||
notionId: notionID,
|
|
||||||
apiTokenPreview: this.maskValue(notionAPI),
|
|
||||||
});
|
|
||||||
return requestUrl({
|
return requestUrl({
|
||||||
url: `https://api.notion.com/v1/blocks/${notionID}`,
|
url: `https://api.notion.com/v1/blocks/${notionID}`,
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
@@ -47,7 +43,6 @@ export abstract class UploadBase {
|
|||||||
this.stripCodeAnnotations(childArr);
|
this.stripCodeAnnotations(childArr);
|
||||||
|
|
||||||
const childArrLength = childArr.length;
|
const childArrLength = childArr.length;
|
||||||
console.log(`Page includes ${childArrLength} blocks`);
|
|
||||||
|
|
||||||
if (childArrLength <= 100) {
|
if (childArrLength <= 100) {
|
||||||
this.debugLog("UploadBase", "Blocks fit into a single request", {
|
this.debugLog("UploadBase", "Blocks fit into a single request", {
|
||||||
@@ -108,9 +103,6 @@ export abstract class UploadBase {
|
|||||||
return cover;
|
return cover;
|
||||||
}
|
}
|
||||||
const databaseCover = await this.fetchDatabaseCover();
|
const databaseCover = await this.fetchDatabaseCover();
|
||||||
this.debugLog("UploadBase", "Cover fetched from database", {
|
|
||||||
databaseCover: databaseCover ?? null,
|
|
||||||
});
|
|
||||||
return databaseCover ?? undefined;
|
return databaseCover ?? undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,8 +136,6 @@ export abstract class UploadBase {
|
|||||||
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 ID: ${data.id}`);
|
|
||||||
if (extraChunks.length > 0) {
|
if (extraChunks.length > 0) {
|
||||||
await this.appendExtraBlocks(data.id, extraChunks);
|
await this.appendExtraBlocks(data.id, extraChunks);
|
||||||
}
|
}
|
||||||
@@ -206,10 +196,6 @@ export abstract class UploadBase {
|
|||||||
|
|
||||||
private async fetchDatabaseCover(): Promise<string | null> {
|
private async fetchDatabaseCover(): Promise<string | null> {
|
||||||
const {notionAPI, databaseID} = this.dbDetails;
|
const {notionAPI, databaseID} = this.dbDetails;
|
||||||
this.debugLog("UploadBase", "Fetching database cover", {
|
|
||||||
databaseId: databaseID,
|
|
||||||
apiTokenPreview: this.maskValue(notionAPI),
|
|
||||||
});
|
|
||||||
const response = await requestUrl({
|
const response = await requestUrl({
|
||||||
url: `https://api.notion.com/v1/databases/${databaseID}`,
|
url: `https://api.notion.com/v1/databases/${databaseID}`,
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -222,11 +208,6 @@ export abstract class UploadBase {
|
|||||||
this.handleRequestError(error, `Fetching database ${databaseID}`),
|
this.handleRequestError(error, `Fetching database ${databaseID}`),
|
||||||
);
|
);
|
||||||
|
|
||||||
this.debugLog("UploadBase", "Database cover response received", {
|
|
||||||
status: response.status,
|
|
||||||
hasCover: !!response.json.cover,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (response.json.cover && response.json.cover.external) {
|
if (response.json.cover && response.json.cover.external) {
|
||||||
return response.json.cover.external.url;
|
return response.json.cover.external.url;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,10 +43,6 @@ export async function uploadCommandNext(
|
|||||||
|
|
||||||
const {notionAPI, databaseID} = dbDetails;
|
const {notionAPI, databaseID} = dbDetails;
|
||||||
console.log(`[uploadCommandNext] ${new Date().toISOString()} Triggered for file`, app.workspace.getActiveFile()?.path);
|
console.log(`[uploadCommandNext] ${new Date().toISOString()} Triggered for file`, app.workspace.getActiveFile()?.path);
|
||||||
logCommandDebug("uploadCommandNext", "Command invoked", {
|
|
||||||
databaseId: databaseID,
|
|
||||||
apiTokenPreview: `${notionAPI?.slice(0, 4) ?? ""}***`,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if the user has set up the Notion API and database ID
|
// Check if the user has set up the Notion API and database ID
|
||||||
if (notionAPI === "" || databaseID === "") {
|
if (notionAPI === "" || databaseID === "") {
|
||||||
@@ -123,7 +119,7 @@ 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"]}`);
|
|
||||||
logCommandDebug("uploadCommandNext", "Sync succeeded", {
|
logCommandDebug("uploadCommandNext", "Sync succeeded", {
|
||||||
filename: basename,
|
filename: basename,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
@@ -154,10 +150,6 @@ export async function uploadCommandGeneral(
|
|||||||
|
|
||||||
const {notionAPI, databaseID} = dbDetails;
|
const {notionAPI, databaseID} = dbDetails;
|
||||||
console.log(`[uploadCommandGeneral] ${new Date().toISOString()} Triggered for file`, app.workspace.getActiveFile()?.path);
|
console.log(`[uploadCommandGeneral] ${new Date().toISOString()} Triggered for file`, app.workspace.getActiveFile()?.path);
|
||||||
logCommandDebug("uploadCommandGeneral", "Command invoked", {
|
|
||||||
databaseId: databaseID,
|
|
||||||
apiTokenPreview: `${notionAPI?.slice(0, 4) ?? ""}***`,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if the user has set up the Notion API and database ID
|
// Check if the user has set up the Notion API and database ID
|
||||||
if (notionAPI === "" || databaseID === "") {
|
if (notionAPI === "" || databaseID === "") {
|
||||||
@@ -204,7 +196,7 @@ 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"]}`);
|
|
||||||
logCommandDebug("uploadCommandGeneral", "Sync succeeded", {
|
logCommandDebug("uploadCommandGeneral", "Sync succeeded", {
|
||||||
filename: basename,
|
filename: basename,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
@@ -235,10 +227,6 @@ export async function uploadCommandCustom(
|
|||||||
|
|
||||||
const {notionAPI, databaseID} = dbDetails;
|
const {notionAPI, databaseID} = dbDetails;
|
||||||
console.log(`[uploadCommandCustom] ${new Date().toISOString()} Triggered for file`, app.workspace.getActiveFile()?.path);
|
console.log(`[uploadCommandCustom] ${new Date().toISOString()} Triggered for file`, app.workspace.getActiveFile()?.path);
|
||||||
logCommandDebug("uploadCommandCustom", "Command invoked", {
|
|
||||||
databaseId: databaseID,
|
|
||||||
apiTokenPreview: `${notionAPI?.slice(0, 4) ?? ""}***`,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if the user has set up the Notion API and database ID
|
// Check if the user has set up the Notion API and database ID
|
||||||
if (notionAPI === "" || databaseID === "") {
|
if (notionAPI === "" || databaseID === "") {
|
||||||
@@ -285,7 +273,7 @@ export async function uploadCommandCustom(
|
|||||||
|
|
||||||
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"]}`);
|
|
||||||
logCommandDebug("uploadCommandCustom", "Sync succeeded", {
|
logCommandDebug("uploadCommandCustom", "Sync succeeded", {
|
||||||
filename: basename,
|
filename: basename,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
|
|||||||
Reference in New Issue
Block a user