fix lint errors and ran bun run check:fix

This commit is contained in:
ltctceplrm 2026-06-21 20:06:38 +02:00
parent 54f971f609
commit e1ab585103
3 changed files with 78 additions and 71 deletions

View file

@ -173,7 +173,7 @@ export default class MediaDbPlugin extends Plugin {
} }
private getLegacyApiKeyEntries(diskSettings: Record<string, unknown>): LegacyApiKeyEntry[] { private getLegacyApiKeyEntries(diskSettings: Record<string, unknown>): 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, key,
value: diskSettings[key] as string, value: diskSettings[key] as string,
})); }));
@ -199,11 +199,13 @@ export default class MediaDbPlugin extends Plugin {
const legacyEntries = this.getLegacyApiKeyEntries(diskSettings); const legacyEntries = this.getLegacyApiKeyEntries(diskSettings);
if (legacyEntries.length > 0) { if (legacyEntries.length > 0) {
this.app.workspace.onLayoutReady(() => { this.app.workspace.onLayoutReady((): void => {
window.setTimeout(() => { window.setTimeout((): void => {
new LegacyApiKeysModal(this.app, legacyEntries, async () => { new LegacyApiKeysModal(this.app, legacyEntries, (): void => {
this.removeLegacyApiKeys(this.settings as unknown as Record<string, unknown>); void (async (): Promise<void> => {
await this.saveSettings(); this.removeLegacyApiKeys(this.settings as unknown as Record<string, unknown>);
await this.saveSettings();
})();
}).open(); }).open();
}, 0); }, 0);
}); });

View file

@ -2,90 +2,92 @@ import type { App } from 'obsidian';
import { Modal, Setting, Notice } from 'obsidian'; import { Modal, Setting, Notice } from 'obsidian';
export interface LegacyApiKeyEntry { export interface LegacyApiKeyEntry {
key: string; key: string;
value: string; value: string;
} }
export class LegacyApiKeysModal extends Modal { export class LegacyApiKeysModal extends Modal {
private entries: LegacyApiKeyEntry[]; private entries: LegacyApiKeyEntry[];
private onConfirm: () => void; private onConfirm: () => void;
constructor(app: App, entries: LegacyApiKeyEntry[], onConfirm: () => void) { constructor(app: App, entries: LegacyApiKeyEntry[], onConfirm: () => void) {
super(app); super(app);
this.entries = entries; this.entries = entries;
this.onConfirm = onConfirm; this.onConfirm = onConfirm;
} }
onOpen(): void { onOpen(): void {
const { contentEl } = this; const { contentEl } = this;
contentEl.addClass('media-db-plugin-legacy-keys-modal'); 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' }); const intro = wrapper.createDiv({ cls: 'media-db-plugin-legacy-keys-intro' });
intro.createEl('p', { 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.', 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', { intro.createEl('p', {
cls: 'media-db-plugin-legacy-keys-textarea', text: 'The new keychain-backed system will be used instead. The plugin will not be usable until the old plaintext keys have been deleted.',
attr: { });
readonly: 'true',
spellcheck: 'false',
},
});
textarea.value = this.entries.map(e => `${e.key}: ${e.value}`).join('\n'); const textarea = wrapper.createEl('textarea', {
textarea.style.display = 'none'; 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 => { const bottomSettingRow = new Setting(contentEl);
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');
});
bottomSettingRow.addButton(btn => { bottomSettingRow.addButton(btn => {
btn.setButtonText('Show keys'); 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(() => { bottomSettingRow.addButton(btn => {
const isHidden = textarea.style.display === 'none'; btn.setButtonText('Show keys');
if (isHidden) { btn.onClick(() => {
textarea.style.display = ''; const isHidden = textarea.hasClass('media-db-plugin-hidden');
btn.setButtonText('Hide keys'); if (isHidden) {
} else { textarea.removeClass('media-db-plugin-hidden');
textarea.style.display = 'none'; btn.setButtonText('Hide keys');
btn.setButtonText('Show 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 => { bottomSettingRow.addButton(btn => {
btn.setButtonText('Delete plaintext keys'); btn.setButtonText('Delete plaintext keys');
btn.setCta(); btn.setCta();
btn.onClick(() => { btn.onClick(() => {
this.close(); this.close();
this.onConfirm(); this.onConfirm();
}); });
btn.buttonEl.addClass('media-db-plugin-button'); btn.buttonEl.addClass('media-db-plugin-button');
btn.buttonEl.addClass('mod-warning'); btn.buttonEl.addClass('mod-warning');
btn.buttonEl.addClass('mod-danger'); btn.buttonEl.addClass('mod-danger');
});
}
}); onClose(): void {
} this.contentEl.empty();
}
onClose(): void {
this.contentEl.empty();
}
} }

View file

@ -329,3 +329,6 @@ small.media-db-plugin-list-text {
line-height: 1.5; line-height: 1.5;
white-space: pre; white-space: pre;
} }
.media-db-plugin-hidden {
display: none !important;
}