Skip to content

Commit

Permalink
fix: 配置文件路径需要支持符号"."--bug=127533823 (TencentBlueKing#3402)
Browse files Browse the repository at this point in the history
* fix: 通过buffer判断文件是否是文本类型

* fix: 配置文件路径需要支持符号"."

* fix: 脚本表格和密钥表格描述样式处理
  • Loading branch information
Yuikill authored Jul 25, 2024
1 parent bd3f870 commit 487969e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
22 changes: 19 additions & 3 deletions bcs-services/bcs-bscp/ui/src/views/space/credentials/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
<template #default="{ row, index }">
<bk-input
v-if="index === 0 && isCreateCredential"
type="textarea"
:maxlength="200"
:resize="false"
:placeholder="t('请输入密钥说明')"
v-model="createCredentialMemo"></bk-input>
<div v-if="row.spec" class="credential-edit">
Expand All @@ -110,15 +113,15 @@
{{ row.spec.memo || '--' }}
</bk-overflow-title>
<span class="edit-icon">
<EditLine @click="handleEditMemo(row.id)" />
<EditLine @click="handleEditMemo(row)" />
</span>
</div>
<bk-input
v-else
ref="memoInputRef"
class="textarea"
type="textarea"
:model-value="row.spec.memo"
v-model="editMemoStr"
:maxlength="200"
:resize="false"
@blur="handleMemoOrNameBlur(row, false, $event)" />
Expand Down Expand Up @@ -294,6 +297,7 @@
const editingNameId = ref(0); // 记录当前正在编辑名称的密钥id
const memoInputRef = ref();
const nameInputRef = ref();
const editMemoStr = ref('');
const isAssociateSliderShow = ref(false);
const currentCredential = ref(0);
const isSearchEmpty = ref(false);
Expand Down Expand Up @@ -480,8 +484,13 @@
const handleSearchInputChange = debounce(() => refreshListWithLoading(), 300);

// 密钥说明编辑
const handleEditMemo = (id: number) => {
const handleEditMemo = (credential: ICredentialItem) => {
const {
id,
spec: { memo },
} = credential;
editingMemoId.value = id;
editMemoStr.value = memo;
nextTick(() => {
if (memoInputRef.value) {
memoInputRef.value.focus();
Expand All @@ -501,6 +510,7 @@

// 失焦时保存密钥说明或密钥名称
const handleMemoOrNameBlur = async (credential: ICredentialItem, isEditName = true, e: FocusEvent) => {
const { name, memo } = credential.spec;
const params = {
id: credential.id,
enable: credential.spec.enable,
Expand All @@ -511,9 +521,15 @@
if (isEditName) {
params.name = val;
editingNameId.value = 0;
if (val === name) {
return;
}
} else {
params.memo = val;
editingMemoId.value = 0;
if (val === memo) {
return;
}
}
await updateCredential(spaceId.value, params);
credential.spec.memo = params.memo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<bk-overflow-title class="memo-text" type="tips">
{{ row.hook.spec.memo || '--' }}
</bk-overflow-title>
<span class="edit-icon" @click="handleOpenMemoEdit(row.hook.id)">
<span class="edit-icon" @click="handleOpenMemoEdit(row)">
<EditLine />
</span>
</div>
Expand All @@ -117,7 +117,7 @@
ref="memoInputRef"
class="memo-input"
type="textarea"
:model-value="row.hook.spec.memo"
v-model="editMemoStr"
:autosize="{ maxRows: 4 }"
:resize="false"
:maxlength="200"
Expand Down Expand Up @@ -253,6 +253,7 @@
const memoInputRef = ref();
const tagEditHookId = ref(0); // 当前正在编辑标签的脚本id
const tagInputRef = ref();
const editMemoStr = ref(''); // 编辑描述内容

const maxTableHeight = computed(() => {
const windowHeight = window.innerHeight;
Expand Down Expand Up @@ -372,8 +373,13 @@
};

// 触发编辑脚本描述
const handleOpenMemoEdit = (id: number) => {
const handleOpenMemoEdit = (script: IScriptItem) => {
const {
id,
spec: { memo },
} = script.hook;
memoEditHookId.value = id;
editMemoStr.value = memo;
nextTick(() => {
memoInputRef.value?.focus();
});
Expand Down Expand Up @@ -601,15 +607,6 @@
color: #979ba5;
background: #ffffff;
}
// 脚本标签、描述编辑需要溢出table
:deep(.bk-table) {
&.table-with-memo-edit .bk-table-body {
overflow: visible;
}
.bk-table-body table td.memo-cell .cell {
overflow: visible;
}
}
.hook-name {
color: #348aff;
cursor: pointer;
Expand Down Expand Up @@ -662,7 +659,6 @@
}
}
.script-memo {
position: relative;
.memo-display {
display: flex;
align-items: center;
Expand All @@ -687,13 +683,6 @@
color: #3a84ff;
}
}
.memo-input {
position: absolute;
top: 4px;
left: 0;
right: 0;
z-index: 2;
}
}
.action-btns {
.bk-button {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
const input = event.target as HTMLInputElement;
const file = (input.files as FileList)[0];
const reader = new FileReader();
reader.readAsText(file);
reader.readAsArrayBuffer(file);
input.value = '';
reader.onload = () => {
const content = reader.result;
// 读取为 ArrayBuffer 成功
const isTextFile = checkFileIsText(content as string);
const buffer = reader.result as ArrayBuffer;
const isTextFile = checkIfTextFile(buffer);
if (isTextFile) {
// 是文本文件
const content = new TextDecoder().decode(buffer);
emits('completed', content);
} else {
// 不是文本文件,处理错误
Expand All @@ -43,9 +42,10 @@
};
};
const checkFileIsText = (content: string) => {
// eslint-disable-next-line
return /^[\x00-\x7F]*$/.test(content.slice(0, 4096));
const checkIfTextFile = (buffer: ArrayBuffer): boolean => {
const uint8Array = new Uint8Array(buffer.slice(0, 4096));
const isBinary = uint8Array.some((byte) => byte === 0);
return !isBinary; // 如果存在 0 字节,则认为是二进制文件
};
</script>
<style lang="scss" scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,15 @@
const fileName = parts.pop() as string;
// 文件名称校验
if (!/^[\u4e00-\u9fa5A-Za-z0-9.\-_#%,:?!@$^+=\\[\]{}]+$/.test(fileName)) {
// 文件名和路径不能全由.组成
if (!/^((?!\.{1,}$)[\u4e00-\u9fa5A-Za-z0-9.\-_#%,:?!@$^+=\\[\]{}]+)$/.test(fileName)) {
return false;
}
let isValid = true;
// 文件路径校验
parts.some((part) => {
if (!/^[\u4e00-\u9fa5A-Za-z0-9.\-_#%,@^+=\\[\]{}]+$/.test(part)) {
if (!/^((?!\.{1,}$)[\u4e00-\u9fa5A-Za-z0-9.\-_#%,:?!@$^+=\\[\]{}]+)$/.test(part)) {
isValid = false;
return true;
}
Expand Down

0 comments on commit 487969e

Please sign in to comment.