From 46e547750924196e12623ada105a4246328e1b37 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 Jun 2022 21:36:42 +0800 Subject: [PATCH] Refactor password and notice --- Upload2Notion.ts | 2 -- main.ts | 52 +++++++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Upload2Notion.ts b/Upload2Notion.ts index 4198672..0c85cc7 100644 --- a/Upload2Notion.ts +++ b/Upload2Notion.ts @@ -4,8 +4,6 @@ import { markdownToBlocks, } from "@tryfabric/martian"; import * as yamlFrontMatter from "yaml-front-matter"; import * as yaml from "yaml" import MyPlugin from "main"; -import { join } from "path"; - export class Upload2Notion { app: MyPlugin; notion: Client; diff --git a/main.ts b/main.ts index 01c18b4..514f500 100644 --- a/main.ts +++ b/main.ts @@ -24,16 +24,16 @@ interface PluginSettings { bannerUrl: string; notionID: string; proxy: string; - langConfig: any; } +const langConfig = NoticeMConfig( window.localStorage.getItem('language') || 'en') + const DEFAULT_SETTINGS: PluginSettings = { notionAPI: "", databaseID: "", bannerUrl: "", notionID: "", proxy: "", - langConfig: NoticeMConfig( window.localStorage.getItem('language') || 'en') }; export default class ObsidianSyncNotionPlugin extends Plugin { @@ -88,9 +88,9 @@ export default class ObsidianSyncNotionPlugin extends Plugin { const upload = new Upload2Notion(this); const res = await upload.syncMarkdownToNotion(basename, markDownData,nowFile, this.app, this.settings) if(res.status === 200){ - new Notice(`${this.settings.langConfig["sync-success"]}${basename}`) + new Notice(`${langConfig["sync-success"]}${basename}`) }else { - new Notice(`${this.settings.langConfig["sync-fail"]}${basename}`) + new Notice(`${langConfig["sync-fail"]}${basename}`) } } } @@ -104,7 +104,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin { nowFile, }; } else { - new Notice(this.settings.langConfig["open-file"]); + new Notice(langConfig["open-file"]); return; } } @@ -142,28 +142,34 @@ class SampleSettingTab extends PluginSettingTab { const notionApiKye = new Setting(containerEl) .setName("Notion API Token") .setDesc("It's a secret") - .addText((text) => - text - .setPlaceholder("Enter your Notion API Token") - .setValue(this.plugin.settings.notionAPI) - .onChange(async (value) => { - this.plugin.settings.notionAPI = value; - await this.plugin.saveSettings(); - }) - ); - notionApiKye.controlEl.querySelector('input').type='password' + .addText((text) =>{ + let t = text + .setPlaceholder("Enter your Notion API Token") + .setValue(this.plugin.settings.notionAPI) + .onChange(async (value) => { + this.plugin.settings.notionAPI = value; + await this.plugin.saveSettings(); + }) + t.inputEl.type = 'password' + return t + }); + const notionDatabaseID = new Setting(containerEl) .setName("Database ID") .setDesc("It's a secret") - .addText((text) => - text - .setPlaceholder("Enter your Database ID") - .setValue(this.plugin.settings.databaseID) - .onChange(async (value) => { - this.plugin.settings.databaseID = value; - await this.plugin.saveSettings(); - }) + .addText((text) => { + let t = text + .setPlaceholder("Enter your Database ID") + .setValue(this.plugin.settings.databaseID) + .onChange(async (value) => { + this.plugin.settings.databaseID = value; + await this.plugin.saveSettings(); + }) + t.inputEl.type = 'password' + return t + } + ); notionDatabaseID.controlEl.querySelector('input').type='password'