From e1ab585103334c2da012fa15309f44b74453b59d Mon Sep 17 00:00:00 2001 From: ltctceplrm <14954927+ltctceplrm@users.noreply.github.com> Date: Sun, 21 Jun 2026 20:06:38 +0200 Subject: [PATCH] fix lint errors and ran bun run check:fix --- packages/obsidian/src/main.ts | 14 +- .../obsidian/src/modals/LegacyApiKeysModal.ts | 132 +++++++++--------- packages/obsidian/src/styles.css | 3 + 3 files changed, 78 insertions(+), 71 deletions(-) diff --git a/packages/obsidian/src/main.ts b/packages/obsidian/src/main.ts index 6f08ad5..8dbb8dd 100644 --- a/packages/obsidian/src/main.ts +++ b/packages/obsidian/src/main.ts @@ -173,7 +173,7 @@ export default class MediaDbPlugin extends Plugin { } private getLegacyApiKeyEntries(diskSettings: Record): LegacyApiKeyEntry[] { - return LEGACY_API_KEYS.filter(key => typeof diskSettings[key] === 'string' && (diskSettings[key]).length > 0).map(key => ({ + return LEGACY_API_KEYS.filter(key => typeof diskSettings[key] === 'string' && diskSettings[key].length > 0).map(key => ({ key, value: diskSettings[key] as string, })); @@ -199,11 +199,13 @@ export default class MediaDbPlugin extends Plugin { const legacyEntries = this.getLegacyApiKeyEntries(diskSettings); if (legacyEntries.length > 0) { - this.app.workspace.onLayoutReady(() => { - window.setTimeout(() => { - new LegacyApiKeysModal(this.app, legacyEntries, async () => { - this.removeLegacyApiKeys(this.settings as unknown as Record); - await this.saveSettings(); + this.app.workspace.onLayoutReady((): void => { + window.setTimeout((): void => { + new LegacyApiKeysModal(this.app, legacyEntries, (): void => { + void (async (): Promise => { + this.removeLegacyApiKeys(this.settings as unknown as Record); + await this.saveSettings(); + })(); }).open(); }, 0); }); diff --git a/packages/obsidian/src/modals/LegacyApiKeysModal.ts b/packages/obsidian/src/modals/LegacyApiKeysModal.ts index 7a13f6d..144e48e 100644 --- a/packages/obsidian/src/modals/LegacyApiKeysModal.ts +++ b/packages/obsidian/src/modals/LegacyApiKeysModal.ts @@ -2,90 +2,92 @@ import type { App } from 'obsidian'; import { Modal, Setting, Notice } from 'obsidian'; export interface LegacyApiKeyEntry { - key: string; - value: string; + key: string; + value: string; } export class LegacyApiKeysModal extends Modal { - private entries: LegacyApiKeyEntry[]; - private onConfirm: () => void; + private entries: LegacyApiKeyEntry[]; + private onConfirm: () => void; - constructor(app: App, entries: LegacyApiKeyEntry[], onConfirm: () => void) { - super(app); - this.entries = entries; - this.onConfirm = onConfirm; - } + constructor(app: App, entries: LegacyApiKeyEntry[], onConfirm: () => void) { + super(app); + this.entries = entries; + this.onConfirm = onConfirm; + } - onOpen(): void { - const { contentEl } = this; - contentEl.addClass('media-db-plugin-legacy-keys-modal'); + onOpen(): void { + const { contentEl } = this; + contentEl.addClass('media-db-plugin-legacy-keys-modal'); - contentEl.createEl('h2', { text: 'Media DB plugin: Legacy API keys found' }); + contentEl.createEl('h2', { text: 'Media DB plugin: Legacy API keys found' }); - const wrapper = contentEl.createDiv({ cls: 'media-db-plugin-legacy-keys-wrapper' }); + const wrapper = contentEl.createDiv({ cls: 'media-db-plugin-legacy-keys-wrapper' }); - const intro = wrapper.createDiv({ cls: 'media-db-plugin-legacy-keys-intro' }); - intro.createEl('p', { - text: 'Media DB plugin has found old plaintext API keys in your settings. Copy them now if needed, they should be removed for safety. The new keychain-backed system will be used instead. The plugin will not be usable until the old plaintext keys have been deleted.', - }); + const intro = wrapper.createDiv({ cls: 'media-db-plugin-legacy-keys-intro' }); + intro.createEl('p', { + text: 'Media DB plugin has found old plaintext API keys in your settings. Copy them now if needed, they should be removed for safety.', + }); - const textarea = wrapper.createEl('textarea', { - cls: 'media-db-plugin-legacy-keys-textarea', - attr: { - readonly: 'true', - spellcheck: 'false', - }, - }); + intro.createEl('p', { + text: 'The new keychain-backed system will be used instead. The plugin will not be usable until the old plaintext keys have been deleted.', + }); - textarea.value = this.entries.map(e => `${e.key}: ${e.value}`).join('\n'); - textarea.style.display = 'none'; + const textarea = wrapper.createEl('textarea', { + cls: 'media-db-plugin-legacy-keys-textarea', + attr: { + readonly: 'true', + spellcheck: 'false', + }, + }); - contentEl.createDiv({ cls: 'media-db-plugin-spacer' }); + textarea.value = this.entries.map(e => `${e.key}: ${e.value}`).join('\n'); + textarea.addClass('media-db-plugin-hidden'); - const bottomSettingRow = new Setting(contentEl); + contentEl.createDiv({ cls: 'media-db-plugin-spacer' }); - bottomSettingRow.addButton(btn => { - btn.setButtonText('Copy'); - btn.onClick(async () => { - await navigator.clipboard.writeText(textarea.value); - new Notice('Legacy API keys copied to clipboard.'); - }); - btn.buttonEl.addClass('media-db-plugin-button'); - }); + const bottomSettingRow = new Setting(contentEl); - bottomSettingRow.addButton(btn => { - btn.setButtonText('Show keys'); + bottomSettingRow.addButton(btn => { + btn.setButtonText('Copy'); + btn.onClick(async () => { + await navigator.clipboard.writeText(textarea.value); + new Notice('Legacy API keys copied to clipboard.'); + }); + btn.buttonEl.addClass('media-db-plugin-button'); + }); - btn.onClick(() => { - const isHidden = textarea.style.display === 'none'; + bottomSettingRow.addButton(btn => { + btn.setButtonText('Show keys'); - if (isHidden) { - textarea.style.display = ''; - btn.setButtonText('Hide keys'); - } else { - textarea.style.display = 'none'; - btn.setButtonText('Show keys'); - } - }); + btn.onClick(() => { + const isHidden = textarea.hasClass('media-db-plugin-hidden'); + if (isHidden) { + textarea.removeClass('media-db-plugin-hidden'); + btn.setButtonText('Hide keys'); + } else { + textarea.addClass('media-db-plugin-hidden'); + btn.setButtonText('Show keys'); + } + }); - btn.buttonEl.addClass('media-db-plugin-button'); - }); + btn.buttonEl.addClass('media-db-plugin-button'); + }); - bottomSettingRow.addButton(btn => { - btn.setButtonText('Delete plaintext keys'); - btn.setCta(); - btn.onClick(() => { - this.close(); - this.onConfirm(); - }); - btn.buttonEl.addClass('media-db-plugin-button'); + bottomSettingRow.addButton(btn => { + btn.setButtonText('Delete plaintext keys'); + btn.setCta(); + btn.onClick(() => { + this.close(); + this.onConfirm(); + }); + btn.buttonEl.addClass('media-db-plugin-button'); btn.buttonEl.addClass('mod-warning'); btn.buttonEl.addClass('mod-danger'); + }); + } - }); - } - - onClose(): void { - this.contentEl.empty(); - } + onClose(): void { + this.contentEl.empty(); + } } diff --git a/packages/obsidian/src/styles.css b/packages/obsidian/src/styles.css index 90e6c6b..a2a83b1 100644 --- a/packages/obsidian/src/styles.css +++ b/packages/obsidian/src/styles.css @@ -329,3 +329,6 @@ small.media-db-plugin-list-text { line-height: 1.5; white-space: pre; } +.media-db-plugin-hidden { + display: none !important; +}