Skip to content

Commit

Permalink
✨ Feature: add backupDomain for sm.ms
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Aug 27, 2022
1 parent c0107f1 commit c6d54f1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export const EN: ILocales = {
// smms
PICBED_SMMS: 'SM.MS',
PICBED_SMMS_TOKEN: 'Set Token',
PICBED_SMMS_BACKUP_DOMAIN: 'Set Backup Domain',
PICBED_SMMS_MESSAGE_BACKUP_DOMAIN: 'Ex. smms.app',

// Ali-cloud
PICBED_ALICLOUD: 'Ali Cloud',
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export const ZH_CN = {
// smms
PICBED_SMMS: 'SM.MS',
PICBED_SMMS_TOKEN: '设定Token',
PICBED_SMMS_BACKUP_DOMAIN: '备用域名',
PICBED_SMMS_MESSAGE_BACKUP_DOMAIN: '例如 smms.app',

// Ali-cloud
PICBED_ALICLOUD: '阿里云OSS',
Expand Down
17 changes: 14 additions & 3 deletions src/plugins/uploader/smms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { Options } from 'request-promise-native'
import { IBuildInEvent } from '../../utils/enum'
import { ILocalesKey } from '../../i18n/zh-CN'

const postOptions = (fileName: string, image: Buffer, apiToken: string): Options => {
const postOptions = (fileName: string, image: Buffer, apiToken: string, backupDomain = ''): Options => {
const domain = backupDomain || 'sm.ms'
return {
method: 'POST',
url: 'https://sm.ms/api/v2/upload',
url: `https://${domain}/api/v2/upload`,
headers: {
contentType: 'multipart/form-data',
'User-Agent': 'PicGo',
Expand All @@ -33,7 +34,7 @@ const handle = async (ctx: IPicGo): Promise<IPicGo> => {
if (!image && img.base64Image) {
image = Buffer.from(img.base64Image, 'base64')
}
const postConfig = postOptions(img.fileName, image, smmsConfig?.token)
const postConfig = postOptions(img.fileName, image, smmsConfig?.token, smmsConfig.backupDomain)
let body = await ctx.Request.request(postConfig)
body = JSON.parse(body)
if (body.code === 'success') {
Expand Down Expand Up @@ -66,6 +67,16 @@ const config = (ctx: IPicGo): IPluginConfig[] => {
get alias () { return ctx.i18n.translate<ILocalesKey>('PICBED_SMMS_TOKEN') },
default: userConfig.token || '',
required: true
},
{
name: 'backupDomain',
get message () {
return ctx.i18n.translate<ILocalesKey>('PICBED_SMMS_BACKUP_DOMAIN')
},
type: 'input',
get alias () { return ctx.i18n.translate<ILocalesKey>('PICBED_SMMS_BACKUP_DOMAIN') },
default: userConfig.backupDomain || '',
required: false
}
]
return config
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export interface ICLIConfigs {
/** SM.MS 图床配置项 */
export interface ISmmsConfig {
token: string
backupDomain?: string
}
/** 七牛云图床配置项 */
export interface IQiniuConfig {
Expand Down

0 comments on commit c6d54f1

Please sign in to comment.