mirror of
https://github.com/yv1ing/obsidian-cos-picbed.git
synced 2025-09-16 15:09:08 +08:00
修复插件加载错误,更换设置样式
This commit is contained in:
31
main.ts
31
main.ts
@@ -10,6 +10,14 @@ interface CosPicbedPluginSettings {
|
|||||||
prefix: string;
|
prefix: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DEFAULT_SETTINGS: CosPicbedPluginSettings = {
|
||||||
|
secretId: "",
|
||||||
|
secretKey: "",
|
||||||
|
bucket: "",
|
||||||
|
region: "",
|
||||||
|
prefix: "",
|
||||||
|
};
|
||||||
|
|
||||||
class CosUploader {
|
class CosUploader {
|
||||||
private cos: any;
|
private cos: any;
|
||||||
private settings: CosPicbedPluginSettings;
|
private settings: CosPicbedPluginSettings;
|
||||||
@@ -139,6 +147,7 @@ class CosPicbedSettingTab extends PluginSettingTab {
|
|||||||
.setName("Secret Id")
|
.setName("Secret Id")
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
text
|
text
|
||||||
|
.setPlaceholder("xxxxxxxxxxxxxxxxxxxxxx")
|
||||||
.setValue(this.plugin.settings.secretId)
|
.setValue(this.plugin.settings.secretId)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.secretId = value.trim();
|
this.plugin.settings.secretId = value.trim();
|
||||||
@@ -150,6 +159,7 @@ class CosPicbedSettingTab extends PluginSettingTab {
|
|||||||
.setName("Secret Key")
|
.setName("Secret Key")
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
text
|
text
|
||||||
|
.setPlaceholder("xxxxxxxxxxxxxxxxxxxxxx")
|
||||||
.setValue(this.plugin.settings.secretKey)
|
.setValue(this.plugin.settings.secretKey)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.secretKey = value.trim();
|
this.plugin.settings.secretKey = value.trim();
|
||||||
@@ -169,28 +179,23 @@ class CosPicbedSettingTab extends PluginSettingTab {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Region")
|
.setName("Region")
|
||||||
.addDropdown((dropdown) => {
|
.addText((text) =>
|
||||||
dropdown
|
text
|
||||||
.addOption("ap-beijing", "Beijing")
|
.setPlaceholder("ap-beijing")
|
||||||
.addOption("ap-chengdu", "Chengdu")
|
|
||||||
.addOption("ap-nanjing", "Nanjing")
|
|
||||||
.addOption("ap-shanghai", "Shanghai")
|
|
||||||
.addOption("ap-hongkong", "Hongkong")
|
|
||||||
.addOption("ap-guangzhou", "Guangzhou")
|
|
||||||
.addOption("ap-chongqing", "Chongqing")
|
|
||||||
.setValue(this.plugin.settings.region)
|
.setValue(this.plugin.settings.region)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
this.plugin.settings.region = value.trim();
|
this.plugin.settings.region = value.trim();
|
||||||
await this.plugin.saveSettings();
|
await this.plugin.saveSettings();
|
||||||
});
|
})
|
||||||
});
|
);
|
||||||
|
|
||||||
new Setting(containerEl)
|
new Setting(containerEl)
|
||||||
.setName("Prefix")
|
.setName("Prefix")
|
||||||
.addText((text) =>
|
.addText((text) =>
|
||||||
text
|
text
|
||||||
|
.setPlaceholder("/")
|
||||||
.setValue(this.plugin.settings.prefix)
|
.setValue(this.plugin.settings.prefix)
|
||||||
.onChange(async (value) => {
|
.onChange(async (value) => {
|
||||||
let prefix = value.trim().replace(/^\/+|\/+$/g, "");
|
let prefix = value.trim().replace(/^\/+|\/+$/g, "");
|
||||||
@@ -304,7 +309,7 @@ export default class CosPicbedPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async loadSettings() {
|
async loadSettings() {
|
||||||
this.settings = Object.assign(await this.loadData());
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
|
|||||||
Reference in New Issue
Block a user