新增CDN全球加速选项

This commit is contained in:
2025-04-20 15:01:40 +08:00
parent f3a3aba1fe
commit 8ff7ab6337
4 changed files with 25 additions and 8 deletions

17
main.ts
View File

@@ -9,6 +9,7 @@ interface CosPicbedPluginSettings {
bucket: string; bucket: string;
region: string; region: string;
prefix: string; prefix: string;
accelerate: boolean;
} }
const DEFAULT_SETTINGS: CosPicbedPluginSettings = { const DEFAULT_SETTINGS: CosPicbedPluginSettings = {
@@ -17,6 +18,7 @@ const DEFAULT_SETTINGS: CosPicbedPluginSettings = {
bucket: "", bucket: "",
region: "", region: "",
prefix: "", prefix: "",
accelerate: false,
}; };
class CosUploader { class CosUploader {
@@ -76,7 +78,11 @@ class CosUploader {
try { try {
const url = await this.getUrl(fullPath); const url = await this.getUrl(fullPath);
if (this.settings.accelerate) {
resolve(url.replace(this.settings.region, 'accelerate'));
} else {
resolve(url); resolve(url);
}
} catch (error) { } catch (error) {
reject(error); reject(error);
return; return;
@@ -204,6 +210,17 @@ class CosPicbedSettingTab extends PluginSettingTab {
await this.plugin.saveSettings(); await this.plugin.saveSettings();
}) })
); );
new Setting(containerEl)
.setName("Accelerate")
.addToggle((toggle) => {
toggle
.setValue(this.plugin.settings.accelerate)
.onChange(async (value) => {
this.plugin.settings.accelerate = value;
await this.plugin.saveSettings();
})
})
} }
} }

View File

@@ -1,8 +1,8 @@
{ {
"id": "obsidian-cos-picbed", "id": "obsidian-cos-picbed",
"name": "COS Picbed", "name": "COS Picbed",
"version": "1.0.2", "version": "1.0.3",
"minAppVersion": "1.0.2", "minAppVersion": "1.0.3",
"description": "This plug-in is used to automatically upload pictures to Tencent Cloud COS, and supports manual deletion of useless pictures to reduce storage space!", "description": "This plug-in is used to automatically upload pictures to Tencent Cloud COS, and supports manual deletion of useless pictures to reduce storage space!",
"author": "yv1ing", "author": "yv1ing",
"authorUrl": "https://github.com/yv1ing", "authorUrl": "https://github.com/yv1ing",

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "obsidian-cos-picbed", "name": "obsidian-cos-picbed",
"version": "1.0.2", "version": "1.0.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "obsidian-cos-picbed", "name": "obsidian-cos-picbed",
"version": "1.0.2", "version": "1.0.3",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cos-js-sdk-v5": "^1.8.7" "cos-js-sdk-v5": "^1.8.7"

View File

@@ -1,6 +1,6 @@
{ {
"name": "obsidian-cos-picbed", "name": "obsidian-cos-picbed",
"version": "1.0.2", "version": "1.0.3",
"description": "This plug-in is used to automatically upload pictures to Tencent Cloud COS, and supports manual deletion of useless pictures to reduce storage space!", "description": "This plug-in is used to automatically upload pictures to Tencent Cloud COS, and supports manual deletion of useless pictures to reduce storage space!",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {