mirror of
https://github.com/chaos-zhu/easynode.git
synced 2026-10-07 13:38:14 +08:00
feat: sftp默认常用目录&展示优先级调整
This commit is contained in:
@@ -63,7 +63,7 @@ const login = async (ctx) => {
|
||||
// 登录流程
|
||||
try {
|
||||
let loginPwd = await RSADecryptAsync(ciphertext)
|
||||
let { user, pwd, enableMFA2, secret, _id } = await keyDB.findOneAsync({})
|
||||
let { user, pwd, enableMFA2, secret } = await keyDB.findOneAsync({})
|
||||
if (enableMFA2) {
|
||||
const isValid = speakeasy.totp.verify({ secret, encoding: 'base32', token: String(mfa2Token), window: 1 })
|
||||
console.log('MFA2 verfify:', isValid)
|
||||
|
||||
@@ -1656,25 +1656,39 @@ module.exports = (httpServer) => {
|
||||
let isRootUser = true
|
||||
let currentWorkingDir = '/'
|
||||
|
||||
try {
|
||||
rootList = await sftpClient.list('/')
|
||||
logger.info('获取根目录成功')
|
||||
} catch (error) {
|
||||
logger.error('获取根目录失败:', error.message)
|
||||
logger.info('尝试获取当前目录')
|
||||
isRootUser = false
|
||||
|
||||
// 如果是 root 用户,直接进入 root 家目录
|
||||
if (username === 'root') {
|
||||
try {
|
||||
// 获取当前工作目录的绝对路径
|
||||
currentWorkingDir = await sftpClient.cwd()
|
||||
logger.info('当前工作目录:', currentWorkingDir)
|
||||
rootList = await sftpClient.list(currentWorkingDir)
|
||||
logger.info('获取当前目录成功')
|
||||
} catch (cwdError) {
|
||||
logger.warn('获取工作目录失败,使用相对路径:', cwdError.message)
|
||||
currentWorkingDir = '~'
|
||||
rootList = await sftpClient.list('./')
|
||||
logger.info('获取当前目录成功')
|
||||
currentWorkingDir = '/root'
|
||||
rootList = await sftpClient.list('/root')
|
||||
} catch (rootError) {
|
||||
// 如果 /root 不存在或无权限,降级到根目录
|
||||
logger.warn('获取 /root 失败,降级到根目录:', rootError.message)
|
||||
currentWorkingDir = '/'
|
||||
rootList = await sftpClient.list('/')
|
||||
logger.info('root 用户进入根目录成功')
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
rootList = await sftpClient.list('/')
|
||||
logger.info('获取根目录成功')
|
||||
} catch (error) {
|
||||
logger.error('获取根目录失败:', error.message)
|
||||
logger.info('尝试获取当前目录')
|
||||
isRootUser = false
|
||||
|
||||
try {
|
||||
// 获取当前工作目录的绝对路径
|
||||
currentWorkingDir = await sftpClient.cwd()
|
||||
logger.info('当前工作目录:', currentWorkingDir)
|
||||
rootList = await sftpClient.list(currentWorkingDir)
|
||||
logger.info('获取当前目录成功')
|
||||
} catch (cwdError) {
|
||||
logger.warn('获取工作目录失败,使用相对路径:', cwdError.message)
|
||||
currentWorkingDir = '~'
|
||||
rootList = await sftpClient.list('./')
|
||||
logger.info('获取当前目录成功')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ const verifyWsAuthSync = async (socket, next) => {
|
||||
logger.warn('ws终端连接身份验证失败, code:', code)
|
||||
return next(new Error('Authentication Failed'))
|
||||
}
|
||||
console.log('🤓 ws terminal auth success')
|
||||
// console.log('🤓 ws terminal auth success')
|
||||
next()
|
||||
}
|
||||
|
||||
|
||||
@@ -737,10 +737,16 @@ function getRank(item) {
|
||||
const isHidden = item.name.startsWith('.')
|
||||
const isDir = item.type === 'd'
|
||||
const isLink = item.type === 'l'
|
||||
if (isHidden && isDir) return 0 // hidden dir
|
||||
if (isDir && item.name === 'root') return 1 // root directory special
|
||||
if (isHidden) return 2 // hidden file
|
||||
if (isDir) return 3 // visible dir
|
||||
|
||||
// .文件夹 -> 文件夹 -> .文件 -> 文件
|
||||
if (isDir) {
|
||||
if (isHidden) return 0 // hidden dir
|
||||
if (item.name === 'root') return 1 // root directory special
|
||||
return 2 // visible dir
|
||||
}
|
||||
|
||||
// 非文件夹
|
||||
if (isHidden) return 3 // hidden file
|
||||
if (isLink) return 4 // link
|
||||
return 5 // regular file
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user