Skip to content

Commit

Permalink
feat: file permissions edit
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyzyykk committed Dec 16, 2024
1 parent b2b7ebc commit 2934577
Show file tree
Hide file tree
Showing 11 changed files with 315 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,33 @@ public Result untar(String sshKey, String path, String item) {
return Result.success(200, successMsg, null);
}

/**
* chmod 文件权限修改
*/
@PostMapping("/chmod")
public Result chmod(String sshKey, String path, String item, String perms, Boolean sub) {
String errorMsg = "权限修改失败";
String successMsg = "权限修改成功";

SSHClient ssh = WebSocketServer.sshClientMap.get(sshKey);
if(ssh == null) {
return Result.error(FileBlockStateEnum.SSH_NOT_EXIST.getState(),"连接断开," + errorMsg,null);
}
String command = "cd " + path + " && chmod " + (sub ? "-R " : "") + perms + " " + item;
try(Session session = ssh.startSession();
Session.Command cmd = session.exec(command))
{
// 等待命令执行完毕
cmd.join();
int exitStatus = cmd.getExitStatus();
if (exitStatus != 0) return Result.error(500, errorMsg, null);
} catch (Exception e) {
e.printStackTrace();
return Result.error(500, errorMsg, null);
}
return Result.success(200, successMsg, null);
}


/**
* 分片上传文件
Expand Down
2 changes: 1 addition & 1 deletion backend/terminal/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ spring.servlet.multipart.max-file-size=20MB
spring.servlet.multipart.max-request-size=100MB

# PC端启用窗口
kk.pc.window=true
kk.pc.window=false
4 changes: 3 additions & 1 deletion backend/terminal/src/main/resources/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,7 @@
"文件片缺失": "File Chunk Missing",
"上传文件大小不一致": "File Upload Size Diff",
"文件片合并失败": "File Chunks Merge Failed",
"ssh连接断开": "SSH Disconnected"
"ssh连接断开": "SSH Disconnected",
"权限修改失败": "Permissions Edit Failed",
"权限修改成功": "Permissions Edit Success"
}
32 changes: 29 additions & 3 deletions front/terminal/src/components/FileAttr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</div>
</template>
</ToolTip>
<div style="cursor: pointer; margin-left: 5px;" @click="doCopy(fileDir + fileInfo.name)">
<div style="cursor: pointer; margin-left: 7px;" @click="doCopy(fileDir + fileInfo.name)">
<el-icon size="18"><DocumentCopy /></el-icon>
</div>
</div>
Expand Down Expand Up @@ -81,6 +81,9 @@
<div>
{{ calcPriority(fileInfo.attributes.mode.type,fileInfo.attributes.permissions) }}
</div>
<div style="cursor: pointer; margin-left: 7px;" @click="openEditPermissions">
<el-icon size="18"><Edit /></el-icon>
</div>
<div style="flex: 1;"></div>
<div>
<el-button size="small" type="primary" @click="confirm" >{{ $t('确定') }}</el-button>
Expand All @@ -89,6 +92,10 @@
</div>
<div style="margin-top: -15px;"></div>
</el-dialog>

<!-- 权限修改 -->
<PermissionsEdit ref="permissionsEditRef" @editPermissions="editPermissions" ></PermissionsEdit>

</template>

<script>
Expand All @@ -99,10 +106,11 @@ import { formatDate } from '@/utils/FormatDate';
import { calcPriority } from '@/utils/CalcPriority';
import { ElMessage } from 'element-plus';
import useClipboard from "vue-clipboard3";
import { DocumentCopy, Refresh } from '@element-plus/icons-vue';
import { DocumentCopy, Refresh, Edit } from '@element-plus/icons-vue';
import { calcSize } from '@/utils/CalcSize';
import { escapeItem, escapePath } from '@/utils/StringUtil';
import ToolTip from './ToolTip.vue';
import PermissionsEdit from './PermissionsEdit.vue';
import i18n from "@/locales/i18n";
// 引入文件图标组件
Expand All @@ -115,6 +123,8 @@ export default {
FileIcons,
DocumentCopy,
Refresh,
Edit,
PermissionsEdit,
},
props:['sshKey'],
setup(props,context)
Expand Down Expand Up @@ -236,6 +246,10 @@ export default {
});
};
const editPermissions = (path,item, permissionsInfo) => {
context.emit('editPermissions', path, item, permissionsInfo);
};
// 重置
const reset = () => {
fileInfo.value = {
Expand All @@ -254,8 +268,18 @@ export default {
DialogVisilble.value = false;
};
// 权限修改
const permissionsEditRef = ref();
const openEditPermissions = () => {
permissionsEditRef.value.fileDir = fileDir.value;
permissionsEditRef.value.fileInfo = fileInfo.value;
permissionsEditRef.value.DialogVisilble = true;
permissionsEditRef.value.init();
};
// 关闭
const closeDialog = (done) => {
if(permissionsEditRef.value) permissionsEditRef.value.closeDialog();
setTimeout(() => {
reset();
},400);
Expand All @@ -280,7 +304,9 @@ export default {
includeInfo,
getFileSize,
getFolderInclude,
permissionsEditRef,
openEditPermissions,
editPermissions,
}
}
}
Expand Down
51 changes: 50 additions & 1 deletion front/terminal/src/components/FileBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@
<FileUrl ref="fileUrlRef" @callback="fileUrlUpload" ></FileUrl>
<TxtPreview ref="txtPreviewRef" @doSave="doSave" ></TxtPreview>
<MkFile ref="mkFileRef" @callback="handleMkFile" ></MkFile>
<FileAttr :sshKey="sshKey" ref="fileAttrRef" @callback="doRename" ></FileAttr>

<!-- 文件属性 -->
<FileAttr :sshKey="sshKey" ref="fileAttrRef" @callback="doRename" @editPermissions="editPermissions" ></FileAttr>

<!-- 菜单项 -->
<div ref="menuBlockRef" @contextmenu="preventDefault" v-show="isShowMenu" class="kk-menu no-select">
Expand Down Expand Up @@ -160,6 +162,7 @@ import { http_base_url } from '@/utils/BaseUrl';
import { Refresh, Fold, Download, Upload, DocumentAdd, FolderAdd, Link } from '@element-plus/icons-vue';
import { escapeItem, escapePath } from '@/utils/StringUtil';
import { isZipFile } from '@/utils/FileSuffix';
import { getChmodValue } from '@/utils/CalcPriority';
import ToolTip from './ToolTip.vue';
import NoData from '@/components/NoData';
Expand Down Expand Up @@ -254,6 +257,12 @@ export default {
}
return -1;
};
const getFileInfoByName = (name) => {
for(let i=0;i<files.value.length;i++) {
if(files.value[i].name == name) return files.value[i];
}
return null;
};
const dir = ref('');
// 保证路径正确
Expand Down Expand Up @@ -325,6 +334,19 @@ export default {
lastSelectedIndex = -1;
fileAreaRef.value.tabindex = '0';
fileAreaRef.value.focus();
if(fileAttrRef.value && fileAttrRef.value.DialogVisilble) {
let nowFileInfo = getFileInfoByName(fileAttrRef.value.fileInfo.name);
if(nowFileInfo) {
fileAttrRef.value.reset();
fileAttrRef.value.DialogVisilble = true;
fileAttrRef.value.fileInfo = nowFileInfo;
fileAttrRef.value.fileDir = dir.value;
fileAttrRef.value.rename = nowFileInfo.name;
if(nowFileInfo.isDirectory) fileAttrRef.value.getFolderInclude();
else fileAttrRef.value.getFileSize();
}
else fileAttrRef.value.closeDialog();
}
}
else {
files.value = [];
Expand Down Expand Up @@ -1103,6 +1125,32 @@ export default {
});
};
// 修改权限
const editPermissions = (path,item, permissionsInfo) => {
$.ajax({
url: http_base_url + '/chmod',
type:'post',
data:{
sshKey:props.sshKey,
path:escapePath(path),
item:escapeItem(item),
perms:getChmodValue(permissionsInfo),
sub:permissionsInfo.sub || false,
},
success(resp){
ElMessage({
message: resp.info,
type: resp.status,
grouping: true,
});
if(resp.status == 'success') {
if(fileAttrRef.value && fileAttrRef.value.permissionsEditRef) fileAttrRef.value.permissionsEditRef.closeDialog();
getDirList();
}
}
});
};
// 重置
const reset = (deep=false) => {
if(deep) {
Expand Down Expand Up @@ -1233,6 +1281,7 @@ export default {
deepCloseDialog,
isZipFile,
untar,
editPermissions,
}
}
}
Expand Down
Loading

0 comments on commit 2934577

Please sign in to comment.