mirror of
https://github.com/fantasy-ke/obsidian-cf-imgbed.git
synced 2026-07-22 06:43:08 +00:00
feat: 添加自定义返回链接前缀功能,优化默认格式下的链接拼接
This commit is contained in:
parent
22ce38ccc7
commit
f5de615d68
4 changed files with 34 additions and 3 deletions
|
|
@ -233,8 +233,23 @@ export class CFImageBedSettingTab extends PluginSettingTab {
|
|||
.onChange(async (value: string) => {
|
||||
this.plugin.settings.returnFormat = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
}));
|
||||
|
||||
// 自定义返回链接前缀(仅默认格式时显示)
|
||||
if (this.plugin.settings.returnFormat !== 'full') {
|
||||
new Setting(container)
|
||||
.setName(this.i18n.t('settings.basic.customReturnBaseUrl.name'))
|
||||
.setDesc(this.i18n.t('settings.basic.customReturnBaseUrl.desc'))
|
||||
.addText((text: TextComponent) => text
|
||||
.setPlaceholder(this.i18n.t('settings.basic.customReturnBaseUrl.placeholder'))
|
||||
.setValue(this.plugin.settings.customReturnBaseUrl || '')
|
||||
.onChange(async (value: string) => {
|
||||
this.plugin.settings.customReturnBaseUrl = value.trim();
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
}
|
||||
|
||||
// 上传目录设置
|
||||
new Setting(container)
|
||||
.setName(this.i18n.t('settings.basic.uploadFolder.name'))
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ export interface CFImageBedSettings {
|
|||
enableLocalBackup: boolean;
|
||||
backupPath: string;
|
||||
|
||||
// 返回链接自定义前缀
|
||||
customReturnBaseUrl: string;
|
||||
|
||||
// 语言配置
|
||||
language: 'zh' | 'en';
|
||||
}
|
||||
|
|
@ -86,6 +89,9 @@ export const DEFAULT_SETTINGS: CFImageBedSettings = {
|
|||
enableLocalBackup: false,
|
||||
backupPath: 'attachments/backup',
|
||||
|
||||
// 返回链接自定义前缀
|
||||
customReturnBaseUrl: '',
|
||||
|
||||
// 语言配置
|
||||
language: 'zh',
|
||||
|
||||
|
|
|
|||
|
|
@ -125,9 +125,9 @@ export class UploadService {
|
|||
// 完整链接格式,直接返回
|
||||
return src;
|
||||
} else {
|
||||
// 默认格式,需要拼接API URL
|
||||
const fullUrl = `${this.settings.apiUrl}${src}`;
|
||||
return fullUrl;
|
||||
// 默认格式,需要拼接基础 URL(优先使用自定义前缀,否则回退到 API URL)
|
||||
const baseUrl = this.settings.customReturnBaseUrl?.trim() || this.settings.apiUrl;
|
||||
return `${baseUrl}${src}`;
|
||||
}
|
||||
} else {
|
||||
throw new Error(this.i18n.t('errors.serverResponseInvalid'));
|
||||
|
|
|
|||
|
|
@ -78,6 +78,11 @@ const translations: Record<Language, Translations> = {
|
|||
full: '完整链接格式'
|
||||
}
|
||||
},
|
||||
customReturnBaseUrl: {
|
||||
name: '自定义返回链接前缀',
|
||||
desc: '默认格式下拼接返回链接时使用的基础 URL,为空时使用 API URL',
|
||||
placeholder: 'https://cdn.example.com'
|
||||
},
|
||||
uploadFolder: {
|
||||
name: '上传目录',
|
||||
desc: '上传目录,使用相对路径',
|
||||
|
|
@ -323,6 +328,11 @@ const translations: Record<Language, Translations> = {
|
|||
full: 'Full link format'
|
||||
}
|
||||
},
|
||||
customReturnBaseUrl: {
|
||||
name: 'Custom return URL prefix',
|
||||
desc: 'Base URL used when concatenating the return link in default format. Falls back to API URL when empty.',
|
||||
placeholder: 'https://cdn.example.com'
|
||||
},
|
||||
uploadFolder: {
|
||||
name: 'Upload folder',
|
||||
desc: 'Upload folder using a relative path',
|
||||
|
|
|
|||
Loading…
Reference in a new issue