feat: 扩展上传渠道和语言支持,优化设置界面

This commit is contained in:
fantasy-ke 2026-06-23 17:41:58 +08:00
parent f5de615d68
commit f2acaa349d
3 changed files with 15 additions and 8 deletions

View file

@ -1,19 +1,19 @@
import { App, DropdownComponent, PluginSettingTab, Setting, SliderComponent, TextComponent, ToggleComponent, getLanguage } from 'obsidian';
import CFImageBedPlugin from '../../main';
import { I18n, resolveLanguage } from '../utils/i18n';
import { UploadChannel } from '../types';
import { UploadChannel, UPLOAD_CHANNELS, Language, LANGUAGES } from '../types';
import { extractHostname, formatDomainList, parseDomainList } from '../utils/domainUtils';
export class CFImageBedSettingTab extends PluginSettingTab {
plugin: CFImageBedPlugin;
private i18n: I18n;
private isLanguage(value: string): value is 'zh' | 'en' {
return value === 'zh' || value === 'en';
private isLanguage(value: string): value is Language {
return (LANGUAGES as readonly string[]).includes(value);
}
private isUploadChannel(value: string): value is UploadChannel {
return value === 'telegram' || value === 'cfr2' || value === 's3' || value === 'discord' || value === 'huggingface';
return (UPLOAD_CHANNELS as readonly string[]).includes(value);
}
constructor(app: App, plugin: CFImageBedPlugin) {
@ -151,6 +151,7 @@ export class CFImageBedSettingTab extends PluginSettingTab {
.addOption('s3', this.i18n.t('settings.basic.uploadChannel.options.s3'))
.addOption('discord', this.i18n.t('settings.basic.uploadChannel.options.discord'))
.addOption('huggingface', this.i18n.t('settings.basic.uploadChannel.options.huggingface'))
.addOption('webdav', this.i18n.t('settings.basic.uploadChannel.options.webdav'))
.setValue(this.plugin.settings.uploadChannel)
.onChange(async (value: string) => {
if (!this.isUploadChannel(value)) {

View file

@ -1,4 +1,8 @@
export type UploadChannel = 'telegram' | 'cfr2' | 's3' | 'discord' | 'huggingface';
export const UPLOAD_CHANNELS = ['telegram', 'cfr2', 's3', 'discord', 'huggingface', 'webdav'] as const;
export type UploadChannel = (typeof UPLOAD_CHANNELS)[number];
export const LANGUAGES = ['zh', 'en'] as const;
export type Language = (typeof LANGUAGES)[number];
export interface CFImageBedSettings {
// 基础配置
@ -45,7 +49,7 @@ export interface CFImageBedSettings {
customReturnBaseUrl: string;
// 语言配置
language: 'zh' | 'en';
language: Language;
}
export const DEFAULT_SETTINGS: CFImageBedSettings = {

View file

@ -42,7 +42,8 @@ const translations: Record<Language, Translations> = {
cfr2: 'Cloudflare R2',
s3: 'S3 兼容存储',
discord: 'Discord',
huggingface: 'HuggingFace'
huggingface: 'HuggingFace',
webdav: 'WebDAV'
}
},
channelName: {
@ -292,7 +293,8 @@ const translations: Record<Language, Translations> = {
cfr2: 'Cloudflare R2',
s3: 'S3 compatible storage',
discord: 'Discord',
huggingface: 'HuggingFace'
huggingface: 'HuggingFace',
webdav: 'WebDAV'
}
},
channelName: {