Skip to content

Commit

Permalink
fix a bug: no region config item
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzs committed Oct 11, 2023
1 parent 3e2c69a commit ae41e52
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "qiniu-image-uploader",
"name": "Qiniu Image Uploader",
"version": "1.0.0",
"version": "1.1.0",
"minAppVersion": "0.15.0",
"description": "Uploads images from your clipboard to qiniu.com and embeds uploaded image to your note.",
"author": "Jade Zheng",
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "",
"author": {
"name": "Shoujian Zheng",
"email": "zheng.shoujian@outlook.com"
},
"license": "MIT",
"devDependencies": {
"@types/node": "^16.11.6",
Expand All @@ -23,4 +26,4 @@
"tslib": "2.4.0",
"typescript": "4.7.4"
}
}
}
14 changes: 12 additions & 2 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export default {
"Access Key": "Access key",
"Access Key Desc": "You can get key from key management from Qiniu personal center.",
"Access Key Input": "Enter your access key",

"Access Secret Key": "Access secret key",
"Access Secret Key Desc": "You can get key from key management from Qiniu personal center.",
"Access Secret Key Input": "Enter your access secret key",

"Bucket Name": "Bucket name",
"Bucket Name Desc": "Please indicate the bucket where you would like to upload the image.",
"Bucket Name Input": "The specific bucket",
Expand All @@ -21,4 +21,14 @@ export default {
"Name Prefix": "Name prefix",
"Name Prefix Desc": "The uploaded filename's prefix in Qiniu, the uploaded filename will be: {{prefix}}{{timestamp}}.",
"Name Prefix Input": "The image's prefix",

"Region": "Region",
"Region Desc": "The region in which the bucket is located.",

"North China - Hebei": "North China - Hebei",
"East China - Zhejiang": "East China - Zhejiang",
"East China - Zhejiang 2": "East China - Zhejiang 2",
"South China - Guangdong": "South China - Guangdong",
"North America - Los Angeles": "North America - Los Angeles",
"Asia Pacific - Singapore (formerly Southeast Asia)": "Asia Pacific - Singapore (formerly Southeast Asia)",
};
14 changes: 12 additions & 2 deletions src/lang/locale/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export default {
"Access Key": "Access Key",
"Access Key Desc": "从七牛云/个人中心/密钥管理获取 Access Key",
"Access Key Input": "请输入 Access Key",

"Access Secret Key": "Access Secret Key",
"Access Secret Key Desc": "从七牛云/个人中心/密钥管理获取Access Secret Key",
"Access Secret Key Input": "请输入 Access Secret Key",

"Bucket Name": "空间名称",
"Bucket Name Desc": "指定你要上传到哪个存储空间",
"Bucket Name Input": "指定的空间名称",
Expand All @@ -21,4 +21,14 @@ export default {
"Name Prefix": "文件名前缀",
"Name Prefix Desc": "配置上传文件的前缀,文件名将为:前缀{{timestamp}}",
"Name Prefix Input": "上传后的文件前缀",

"Region": "区域",
"Region Desc": "指明桶所在的区域",

"North China - Hebei": "华北-河北",
"East China - Zhejiang": "华东-浙江",
"East China - Zhejiang 2": "华东-浙江2",
"South China - Guangdong": "华南-广东",
"North America - Los Angeles": "北美-洛杉矶",
"Asia Pacific - Singapore (formerly Southeast Asia)": "亚太-新加坡(原东南亚)",
};
18 changes: 18 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface PluginSettings {
bucketName: string;
domain: string;
namePrefix: string;
region: string;
deleteSource: boolean;
}

Expand All @@ -17,6 +18,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
bucketName: "",
domain: "",
namePrefix: "ob-",
region: "z1",
deleteSource: false,
};

Expand Down Expand Up @@ -66,6 +68,22 @@ export class SettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));

new Setting(containerEl)
.setName(t("Region"))
.setDesc(t("Region Desc"))
.addDropdown((dropDown) => {
dropDown.addOption("z1", t("North China - Hebei"));
dropDown.addOption("z0", t("East China - Zhejiang"));
dropDown.addOption("cn-east-2", t("East China - Zhejiang 2"));
dropDown.addOption("z2", t("South China - Guangdong"));
dropDown.addOption("na0", t("North America - Los Angeles"));
dropDown.addOption("as0", t("Asia Pacific - Singapore (formerly Southeast Asia)"));
dropDown.onChange(async (value) => {
this.plugin.settings.region = value;
await this.plugin.saveSettings();
});
});

new Setting(containerEl)
.setName(t("Domain"))
.setDesc(t("Domain Desc"))
Expand Down
11 changes: 10 additions & 1 deletion src/uploader/qiniu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { PluginSettings } from "../settings";
import * as qiniu from 'qiniu';
import { Uploader } from "./uploader";

const zoneMapping: { [key: string]: qiniu.conf.Zone } = {
"as0": qiniu.zone.Zone_as0,
"cn_east_2": qiniu.zone.Zone_cn_east_2,
"na0": qiniu.zone.Zone_na0,
"z0": qiniu.zone.Zone_z0,
"z1": qiniu.zone.Zone_z1,
"z2": qiniu.zone.Zone_z2,
}

export class QiniuUploader implements Uploader {
settings: PluginSettings;

Expand All @@ -19,7 +28,7 @@ export class QiniuUploader implements Uploader {

public async uploadFile(name: string, file: File): Promise<string> {
var config = new qiniu.conf.Config({
zone: qiniu.zone.Zone_z0,
zone: zoneMapping[this.settings.region]
});

var formUploader = new qiniu.form_up.FormUploader(config);
Expand Down
3 changes: 2 additions & 1 deletion src/uploader/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export interface Uploader {
}

export function buildUploaderFrom(settings: PluginSettings): Uploader | undefined {
if (settings.accessKey == "" || settings.accessSecretKey == "" || settings.bucketName == "" || settings.domain == "") {
if (settings.accessKey == "" || settings.accessSecretKey == "" || settings.bucketName == "" || settings.domain == "" || settings.region == "") {
console.log('Settings: ', settings);
return undefined
}
return new QiniuUploader(settings);
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"1.1.0": "0.15.0",
"1.0.0": "0.15.0"
}

0 comments on commit ae41e52

Please sign in to comment.