Skip to content

Commit c6d54f1

Browse files
committed
✨ Feature: add backupDomain for sm.ms
1 parent c0107f1 commit c6d54f1

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/i18n/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const EN: ILocales = {
1212
// smms
1313
PICBED_SMMS: 'SM.MS',
1414
PICBED_SMMS_TOKEN: 'Set Token',
15+
PICBED_SMMS_BACKUP_DOMAIN: 'Set Backup Domain',
16+
PICBED_SMMS_MESSAGE_BACKUP_DOMAIN: 'Ex. smms.app',
1517

1618
// Ali-cloud
1719
PICBED_ALICLOUD: 'Ali Cloud',

src/i18n/zh-CN.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const ZH_CN = {
1010
// smms
1111
PICBED_SMMS: 'SM.MS',
1212
PICBED_SMMS_TOKEN: '设定Token',
13+
PICBED_SMMS_BACKUP_DOMAIN: '备用域名',
14+
PICBED_SMMS_MESSAGE_BACKUP_DOMAIN: '例如 smms.app',
1315

1416
// Ali-cloud
1517
PICBED_ALICLOUD: '阿里云OSS',

src/plugins/uploader/smms.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { Options } from 'request-promise-native'
33
import { IBuildInEvent } from '../../utils/enum'
44
import { ILocalesKey } from '../../i18n/zh-CN'
55

6-
const postOptions = (fileName: string, image: Buffer, apiToken: string): Options => {
6+
const postOptions = (fileName: string, image: Buffer, apiToken: string, backupDomain = ''): Options => {
7+
const domain = backupDomain || 'sm.ms'
78
return {
89
method: 'POST',
9-
url: 'https://sm.ms/api/v2/upload',
10+
url: `https://${domain}/api/v2/upload`,
1011
headers: {
1112
contentType: 'multipart/form-data',
1213
'User-Agent': 'PicGo',
@@ -33,7 +34,7 @@ const handle = async (ctx: IPicGo): Promise<IPicGo> => {
3334
if (!image && img.base64Image) {
3435
image = Buffer.from(img.base64Image, 'base64')
3536
}
36-
const postConfig = postOptions(img.fileName, image, smmsConfig?.token)
37+
const postConfig = postOptions(img.fileName, image, smmsConfig?.token, smmsConfig.backupDomain)
3738
let body = await ctx.Request.request(postConfig)
3839
body = JSON.parse(body)
3940
if (body.code === 'success') {
@@ -66,6 +67,16 @@ const config = (ctx: IPicGo): IPluginConfig[] => {
6667
get alias () { return ctx.i18n.translate<ILocalesKey>('PICBED_SMMS_TOKEN') },
6768
default: userConfig.token || '',
6869
required: true
70+
},
71+
{
72+
name: 'backupDomain',
73+
get message () {
74+
return ctx.i18n.translate<ILocalesKey>('PICBED_SMMS_BACKUP_DOMAIN')
75+
},
76+
type: 'input',
77+
get alias () { return ctx.i18n.translate<ILocalesKey>('PICBED_SMMS_BACKUP_DOMAIN') },
78+
default: userConfig.backupDomain || '',
79+
required: false
6980
}
7081
]
7182
return config

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ export interface ICLIConfigs {
196196
/** SM.MS 图床配置项 */
197197
export interface ISmmsConfig {
198198
token: string
199+
backupDomain?: string
199200
}
200201
/** 七牛云图床配置项 */
201202
export interface IQiniuConfig {

0 commit comments

Comments
 (0)