🚧 WIP: add sftp into manage page

This commit is contained in:
萌萌哒赫萝
2023-08-19 03:02:50 -07:00
parent 3e32cbba33
commit 1629dcaef0
9 changed files with 333 additions and 21 deletions

View File

View File

@@ -562,7 +562,7 @@ function handleConfigImport (alias: string) {
async function getCurrentConfigList () {
const configList = await getPicBedsConfig<any>('uploader') ?? {}
const pbList = ['aliyun', 'aws-s3', 'github', 'imgur', 'local', 'qiniu', 'smms', 'tcyun', 'upyun', 'webdavplist']
const pbList = ['aliyun', 'aws-s3', 'github', 'imgur', 'local', 'qiniu', 'sftpplist', 'smms', 'tcyun', 'upyun', 'webdavplist']
const filteredConfigList = pbList.flatMap((pb) => {
const config = configList[pb]
@@ -593,7 +593,13 @@ function initArray (arrayT: string | string[], defaultValue: string[]) {
}
async function transUpToManage (config: IUploaderConfigListItem, picBedName: string, autoImportPicBed: string[]) {
const alias = `${picBedName === 'webdavplist' ? 'webdav' : picBedName}-${config._configName ?? 'Default'}-imp`
const alias = `${picBedName === 'webdavplist'
? 'webdav'
: picBedName === 'sftpplist'
? 'sftp'
: picBedName === 'aws-s3'
? 's3plist'
: picBedName}-${config._configName ?? 'Default'}-imp`
if (!autoImportPicBed.includes(picBedName) || isImported(alias)) return
const commonConfig = {
alias,
@@ -728,10 +734,30 @@ async function transUpToManage (config: IUploaderConfigListItem, picBedName: str
})
delete resultMap.paging
break
case 'sftpplist':
if (!config.host) return
Object.assign(resultMap, {
...commonConfig,
picBedName: 'sftp',
host: config.host,
port: config.port || 22,
username: config.username,
password: config.password,
privateKey: config.privateKey,
passphrase: config.passphrase,
baseDir: config.uploadPath || '/',
webPath: config.webPath || '',
customUrl: config.customUrl || '',
fileMode: config.fileMode || '0664',
dirMode: config.dirMode || '0775'
})
delete resultMap.paging
break
case 'aws-s3':
if (!config.accessKeyID || !config.secretAccessKey) return
Object.assign(resultMap, {
...commonConfig,
picBedName: 's3plist',
accessKeyId: config.accessKeyID,
secretAccessKey: config.secretAccessKey,
endpoint: config.endpoint || '',

View File

@@ -336,16 +336,17 @@ watch(route, async (newRoute) => {
const getCurrentActiveBucket = computed(() => bucketNameList.value.length === 0 ? '' : bucketNameList.value[0])
const urlMap : IStringKeyMap = {
smms: 'https://smms.app',
aliyun: 'https://oss.console.aliyun.com',
github: 'https://github.com',
imgur: 'https://imgur.com',
aliyun: 'https://oss.console.aliyun.com',
local: 'https://piclist.cn',
qiniu: 'https://portal.qiniu.com',
s3plist: 'https://aws.amazon.com/cn/s3/',
sftp: 'https://github.com/imba97/picgo-plugin-sftp-uploader',
smms: 'https://smms.app',
tcyun: 'https://console.cloud.tencent.com/cos',
upyun: 'https://console.upyun.com',
s3plist: 'https://aws.amazon.com/cn/s3/',
webdavplist: 'https://baike.baidu.com/item/WebDAV/4610909',
local: 'https://piclist.cn'
webdavplist: 'https://baike.baidu.com/item/WebDAV/4610909'
}
const showNewIconList = ['aliyun', 'qiniu', 'tcyun']
@@ -360,6 +361,7 @@ const menuTitleMap:IStringKeyMap = {
tcyun: bucketT,
upyun: bucketT,
s3plist: bucketT,
sftp: '',
smms: galleryT,
imgur: galleryT,
github: repositoryT,

View File

@@ -52,15 +52,17 @@ export function renameFileNameWithCustomString (oldName: string, customFormat: s
}, customFormat) + ext
}
export function renameFile (typeMap : IStringKeyMap, oldName: string): string {
if (typeMap.timestampRename) {
return renameFileNameWithTimestamp(oldName)
} else if (typeMap.randomStringRename) {
return renameFileNameWithRandomString(oldName, 20)
} else if (typeMap.customRename) {
return renameFileNameWithCustomString(oldName, typeMap.customRenameFormat)
export function renameFile ({ timestampRename, randomStringRename, customRename, customRenameFormat }: IStringKeyMap, oldName = ''): string {
switch (true) {
case timestampRename:
return renameFileNameWithTimestamp(oldName)
case randomStringRename:
return renameFileNameWithRandomString(oldName, 20)
case customRename:
return renameFileNameWithCustomString(oldName, customRenameFormat)
default:
return oldName
}
return oldName
}
export async function formatLink (url: string, fileName: string, type: string, format?: string) : Promise<string> {

View File

@@ -22,7 +22,7 @@ const itemsPerPageRule = [
trigger: 'change'
},
{
validator: (rule: any, value: any, callback: any) => {
validator: (_rule: any, value: any, callback: any) => {
if (value < 20 || value > 1000) {
callback(new Error($T('MANAGE_CONSTANT_ITEMS_PAGE_RULE_MESSAGE_C')))
} else {
@@ -40,7 +40,7 @@ const aliasRule = [
trigger: 'blur'
},
{
validator: (rule: any, value: any, callback: any) => {
validator: (_rule: any, value: any, callback: any) => {
const reg = /^[\u4e00-\u9fff_a-zA-Z0-9-]+$/
if (!reg.test(value)) {
callback(new Error($T('MANAGE_CONSTANT_ALIAS_RULE_MESSAGE_B')))
@@ -469,7 +469,7 @@ export const supportedPicBedList: IStringKeyMap = {
trigger: 'change'
},
{
validator: (rule: any, value: any, callback: any) => {
validator: (_rule: any, value: any, callback: any) => {
if (value) {
const customUrlList = value.split(',')
const customUrlValid = customUrlList.every((customUrl: string) => {
@@ -722,7 +722,7 @@ export const supportedPicBedList: IStringKeyMap = {
tooltip: $T('MANAGE_CONSTANT_WEBDAV_CUSTOM_URL_TOOLTIP'),
rule: [
{
validator: (rule: any, value: any, callback: any) => {
validator: (_rule: any, value: any, callback: any) => {
if (value) {
if (!/^https?:\/\/.+/.test(value)) {
callback(new Error($T('MANAGE_CONSTANT_WEBDAV_CUSTOM_URL_RULE_MESSAGE')))
@@ -786,7 +786,7 @@ export const supportedPicBedList: IStringKeyMap = {
default: '',
rule: [
{
validator: (rule: any, value: any, callback: any) => {
validator: (_rule: any, value: any, callback: any) => {
if (!value) {
callback(new Error($T('MANAGE_CONSTANT_LOCAL_BASE_DIR_RULE_MESSAGE')))
} else {
@@ -804,7 +804,7 @@ export const supportedPicBedList: IStringKeyMap = {
tooltip: $T('MANAGE_CONSTANT_LOCAL_CUSTOM_URL_TOOLTIP'),
rule: [
{
validator: (rule: any, value: any, callback: any) => {
validator: (_rule: any, value: any, callback: any) => {
if (value) {
if (!/^https?:\/\/.+/.test(value)) {
callback(new Error($T('MANAGE_CONSTANT_WEBDAV_CUSTOM_URL_RULE_MESSAGE')))
@@ -841,5 +841,139 @@ export const supportedPicBedList: IStringKeyMap = {
options: ['alias', 'baseDir', 'customUrl', 'bucketName', 'webPath'],
refLink: 'https://piclist.cn',
referenceText: $T('MANAGE_CONSTANT_LOCAL_REFER_TEXT')
},
sftp: {
name: $T('MANAGE_CONSTANT_SFTP_NAME'),
icon: 'sftp',
configOptions: {
alias: {
required: true,
description: $T('MANAGE_CONSTANT_SFTP_ALIAS_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_ALIAS_PLACEHOLDER'),
type: 'string',
rule: aliasRule,
default: 'sftp-A',
tooltip: aliasTooltip
},
host: {
required: true,
description: $T('MANAGE_CONSTANT_SFTP_HOST_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_HOST_PLACEHOLDER'),
type: 'string',
rule: defaultBaseRule('host'),
default: ''
},
port: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_PORT_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_PORT_PLACEHOLDER'),
type: 'number',
default: 22
},
username: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_USERNAME_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_USERNAME_PLACEHOLDER'),
type: 'string',
default: ''
},
password: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_PASSWORD_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_PASSWORD_PLACEHOLDER'),
type: 'string',
default: ''
},
privateKey: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_PRIVATE_KEY_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_PRIVATE_KEY_PLACEHOLDER'),
type: 'string',
default: ''
},
passphrase: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_PASSPHRASE_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_PASSPHRASE_PLACEHOLDER'),
type: 'string',
default: ''
},
fileMode: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_FILE_PERMISSIONS_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_FILE_PERMISSIONS_PLACEHOLDER'),
type: 'string',
default: '0664'
},
dirMode: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_DIR_PERMISSIONS_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_DIR_PERMISSIONS_PLACEHOLDER'),
type: 'string',
default: '0755'
},
baseDir: {
required: true,
description: $T('MANAGE_CONSTANT_SFTP_BASE_DIR_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_BASE_DIR_PLACEHOLDER'),
type: 'string',
default: '',
rule: [
{
validator: (_rule: any, value: any, callback: any) => {
if (!value) {
callback(new Error($T('MANAGE_CONSTANT_SFTP_BASE_DIR_RULE_MESSAGE')))
} else {
callback()
}
}
}
]
},
customUrl: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_CUSTOM_URL_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_CUSTOM_URL_PLACEHOLDER'),
type: 'string',
tooltip: $T('MANAGE_CONSTANT_SFTP_CUSTOM_URL_TOOLTIP'),
rule: [
{
validator: (_rule: any, value: any, callback: any) => {
if (value) {
if (!/^https?:\/\/.+/.test(value)) {
callback(new Error($T('MANAGE_CONSTANT_WEBDAV_CUSTOM_URL_RULE_MESSAGE')))
} else {
callback()
}
} else {
callback()
}
},
trigger: 'change'
}
]
},
bucketName: {
required: true,
description: $T('MANAGE_CONSTANT_SFTP_BUCKET_DESC'),
placeholder: $T('MANAGE_CONSTANT_SFTP_BUCKET_PLACEHOLDER'),
type: 'string',
default: 'sftp',
disabled: true,
tooltip: $T('MANAGE_CONSTANT_SFTP_BUCKET_TOOLTIP')
},
webPath: {
required: false,
description: $T('MANAGE_CONSTANT_SFTP_WEB_PATH'),
placeholder: $T('MANAGE_CONSTANT_SFTP_WEB_PATH_PLACEHOLDER'),
type: 'string',
tooltip: $T('MANAGE_CONSTANT_SFTP_WEB_PATH_TOOLTIP'),
default: ''
}
},
explain: $T('MANAGE_CONSTANT_SFTP_EXPLAIN'),
options: ['alias', 'host', 'port', 'username', 'password', 'privateKey', 'passphrase', 'fileMode', 'dirMode', 'baseDir', 'customUrl', 'bucketName', 'webPath'],
refLink: 'https://github.com/imba97/picgo-plugin-sftp-uploader',
referenceText: $T('MANAGE_CONSTANT_SFTP_REFER_TEXT')
}
}

View File

@@ -589,6 +589,42 @@ interface ILocales {
MANAGE_CONSTANT_LOCAL_BUCKET_DESC: string
MANAGE_CONSTANT_LOCAL_BUCKET_PLACEHOLDER: string
MANAGE_CONSTANT_LOCAL_BUCKET_TOOLTIP: string
MANAGE_CONSTANT_SFTP_NAME: string
MANAGE_CONSTANT_SFTP_ALIAS_DESC: string
MANAGE_CONSTANT_SFTP_ALIAS_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_HOST_DESC: string
MANAGE_CONSTANT_SFTP_HOST_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_PORT_DESC: string
MANAGE_CONSTANT_SFTP_PORT_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_USERNAME_DESC: string
MANAGE_CONSTANT_SFTP_USERNAME_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_PASSWORD_DESC: string
MANAGE_CONSTANT_SFTP_PASSWORD_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_PRIVATE_KEY_DESC: string
MANAGE_CONSTANT_SFTP_PRIVATE_KEY_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_PRIVATE_KEY_TOOLTIP: string
MANAGE_CONSTANT_SFTP_PASSPHRASE_DESC: string
MANAGE_CONSTANT_SFTP_PASSPHRASE_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_BASE_DIR_DESC: string
MANAGE_CONSTANT_SFTP_BASE_DIR_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_CUSTOM_URL_DESC: string
MANAGE_CONSTANT_SFTP_CUSTOM_URL_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_CUSTOM_URL_TOOLTIP: string
MANAGE_CONSTANT_SFTP_WEB_PATH: string
MANAGE_CONSTANT_SFTP_WEB_PATH_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_WEB_PATH_TOOLTIP: string
MANAGE_CONSTANT_SFTP_FILE_PERMISSIONS_DESC: string
MANAGE_CONSTANT_SFTP_FILE_PERMISSIONS_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_FILE_PERMISSIONS_TOOLTIP: string
MANAGE_CONSTANT_SFTP_DIR_PERMISSIONS_DESC: string
MANAGE_CONSTANT_SFTP_DIR_PERMISSIONS_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_DIR_PERMISSIONS_TOOLTIP: string
MANAGE_CONSTANT_SFTP_EXPLAIN: string
MANAGE_CONSTANT_SFTP_REFER_TEXT: string
MANAGE_CONSTANT_SFTP_BASE_DIR_RULE_MESSAGE: string
MANAGE_CONSTANT_SFTP_BUCKET_DESC: string
MANAGE_CONSTANT_SFTP_BUCKET_PLACEHOLDER: string
MANAGE_CONSTANT_SFTP_BUCKET_TOOLTIP: string
MANAGE_LOGIN_PAGE_PANE_NAME: string
MANAGE_LOGIN_PAGE_PANE_DESC: string
MANAGE_LOGIN_PAGE_PANE_LOADING: string