Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/assets/locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ const message = {
change: '更 换',
editorTip: '你可以插入单独行的 <!-- more --> 为摘要分隔标识(此行之前内容为摘要)',
saveError: '保存失败',
privateKeyTip: '请填写绝对路径,例如:/home/username/.ssh/id_rsa',
remotePathTip: '请填写绝对路径,例如:/home/username/www/',
testConnection: '检测远程连接',
connectSuccess: '远程连接成功',
connectFailed: '远程连接失败,请检查仓库、用户名和 Token 设置',
Expand Down Expand Up @@ -182,6 +184,8 @@ const message = {
change: '更 換',
editorTip: '你可以插入單獨行的 <!-- more --> 為摘要分隔標識(此行之前內容為摘要)',
saveError: '保存失敗',
privateKeyTip: '請填寫絕對路徑,例如:/home/username/.ssh/id_rsa',
remotePathTip: '請填寫絕對路徑,例如:/home/username/www/',
testConnection: '檢測遠程連接',
connectSuccess: '遠程連接成功',
connectFailed: '遠程連接失敗,請檢查倉庫、用戶名和 Token 設置',
Expand Down Expand Up @@ -290,6 +294,8 @@ const message = {
change: 'Change',
editorTip: 'You can insert a separate line <!-- more --> is the abstract separator identifier ( the content before this line is the abstract)',
saveError: 'Save failed',
privateKeyTip: 'Please fill in the absolute path, for example: /home/username/.ssh/id_rsa',
remotePathTip: 'Please fill in the absolute path, for example::/home/username/www/',
testConnection: 'Test Connection',
connectSuccess: 'Remote connection succeeded',
connectFailed: 'Remote connection failed, please check repository, username and token settings',
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface ISetting {
port: string
server: string
password: string
privateKey: string
remotePath: string
[index: string]: string
}
Expand Down
1 change: 1 addition & 0 deletions src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class App {
port: '22',
server: '',
password: '',
privateKey: '',
remotePath: '',
},
commentSetting: {
Expand Down
42 changes: 36 additions & 6 deletions src/server/plugins/deploys/sftp.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import * as fse from 'fs-extra'
// import * as fs from 'fs'
import path from 'path'
import SftpClient from 'ssh2-sftp-client'
import NodeSsh from 'node-ssh'
import normalizePath from 'normalize-path'
import Model from '../../model'

type sftpConnectConfig = {
host: string;
port: number;
type?: string;
username: string;
password?: string;
privateKey?: string | Buffer;
}

export default class SftpDeploy extends Model {
// connect: SftpClient
constructor(appInstance: any) {
Expand All @@ -22,11 +32,24 @@ export default class SftpDeploy extends Model {
const client = new SftpClient()

const { setting } = this.db
const connectConfig = {

const connectConfig: sftpConnectConfig = {
host: setting.server,
port: Number(setting.port),
username: setting.username,
password: setting.password,
}

if (setting.privateKey) {
try {
connectConfig.privateKey = fse.readFileSync(setting.privateKey)
} catch (e) {
console.error('SFTP Test Remote Error: ', e.message)
result.success = false
result.message = e.message
return result
}
} else {
connectConfig.password = setting.password
}

const testFilename = 'gridea.txt'
Expand Down Expand Up @@ -58,7 +81,7 @@ export default class SftpDeploy extends Model {
} finally {
await client.end()
}

return result
}

Expand All @@ -71,12 +94,19 @@ export default class SftpDeploy extends Model {
const client = new NodeSsh()

const { setting } = this.db
const connectConfig = {

const connectConfig: sftpConnectConfig = {
host: setting.server,
port: Number(setting.port),
username: setting.username,
password: setting.password,
type: 'sftp',
username: setting.username,
}

// node-ssh: privateKey is path string.
if (setting.privateKey) {
connectConfig.privateKey = setting.privateKey
} else {
connectConfig.password = setting.password
}

const localPath = normalizePath(path.join(this.appDir, 'output'))
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const siteState: Site = {
port: '22',
server: '',
password: '',
privateKey: '',
remotePath: '',
},
commentSetting: {
Expand Down
10 changes: 7 additions & 3 deletions src/views/setting/includes/BasicSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
<a-icon class="icon" slot="addonAfter" :type="passVisible ? 'eye-invisible' : 'eye'" @click="passVisible = !passVisible" />
</a-input>
</a-form-item>
<a-form-item label="Remote Path" :labelCol="formLayout.label" :wrapperCol="formLayout.wrapper" :colon="false" help="请填写绝对路径,例如:/home/username/www/">
<a-form-item label="Private Key" :labelCol="formLayout.label" :wrapperCol="formLayout.wrapper" :colon="false" :help="$t('privateKeyTip')">
<a-input v-model="form.privateKey" />
</a-form-item>
<a-form-item label="Remote Path" :labelCol="formLayout.label" :wrapperCol="formLayout.wrapper" :colon="false" :help="$t('remotePathTip')">
<a-input v-model="form.remotePath" />
</a-form-item>
</template>
Expand Down Expand Up @@ -99,6 +102,7 @@ export default class BasicSetting extends Vue {
port: '22',
server: '',
password: '',
privateKey: '',
remotePath: '',
}

Expand All @@ -110,13 +114,13 @@ export default class BasicSetting extends Vue {
&& form.branch
&& form.username
&& form.token

const sftpPlatformValid = ['sftp'].includes(form.platform)
&& form.port
&& form.server
&& form.username
&& form.password
&& form.remotePath
&& (form.password || form.privateKey)

return pagesPlatfomValid || sftpPlatformValid
}
Expand Down