撤回wiki名称支持特殊字符修改

This commit is contained in:
黄心宇 2024-01-27 14:39:46 +08:00
parent c440b60d97
commit 88e2d00368
6 changed files with 41 additions and 28 deletions

View File

@ -18,7 +18,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
let wikiName = ''
let key = '';
if (!pathname.endsWith('/wiki/add')) {
wikiName = pathname.split('/')[4];
wikiName = decodeURI(pathname.split('/')[4]);
key = pathname.split('/')[5];
}else{
key = search.split('=').pop();
@ -116,6 +116,12 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
};
validateFields((err, values) => {
if (!err) {
let regEn = /[\\/:*?"<>|[\]-]/g;
if (regEn.test(values.title)) {
message.error('文件名不能有特殊字符: \\ / : * ? \" < > | [ \] -');
setOperateFlag(false);
return;
}
const {md_content, title} = values;
if (wikiName && search!== "?copy") {
updateWiki({
@ -124,7 +130,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
projectId: project.id,
pageName: wikiName,
title,
message: '',
commit_message: '',
content_base64: Base64.encode(md_content)
}).then(res => dealRes(res, title));
} else {
@ -217,7 +223,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
projectId: project.id,
pageName: '_Sidebar',
title: '_Sidebar',
message: '',
commit_message: '',
content_base64: Base64.encode(content)
}).then(res => {
if (res && res.message === "200") {
@ -327,7 +333,7 @@ export default Form.create()(({ form, history, showNotification, projectDetail,
"title",
[
{ required: true, message: "请输入标题" },
{ pattern: /^(?!-).*$/, message: '不能以-开头' }
// { pattern: /[^`\[\]\/:*?''<>|%-+_]/g, message: '' }
],
<Input
placeholder={"请输入标题"}

View File

@ -115,7 +115,7 @@ export default (props) => {
project && checkItem.name && getWiki({
owner: owner,
repo: projectsId,
pageName: checkItem.sub_url,
pageName: checkItem.name,
projectId: project.id
}).then(res => {
if (res && res.message === "200") {
@ -190,6 +190,11 @@ export default (props) => {
setAddMenuError("不能仅输入空格");
return;
}
const regEn = /[\\/:*?"<>|[\]-]/g;
if (regEn.test(menuName)) {
setAddMenuError("不能有特殊字符: \\ / : * ? \" < > | [ \] -");
return;
}
//
const oneMenuList = fileList.filter(item=>!item.title.trim().startsWith('[[')).map(i=>i.title.trim())
if(oneMenuList.includes(`- ${menuName}`)){
@ -210,7 +215,7 @@ export default (props) => {
projectId: project.id,
pageName: '_Sidebar',
title: '_Sidebar',
message: '',
commit_message: '',
content_base64: Base64.encode(treeToMd(sidebarList))
}).then(res => {
if (res && res.message === "200") {
@ -228,7 +233,7 @@ export default (props) => {
}
function goEdit(params) {
history.push(`/${owner}/${projectsId}/wiki/${encodeURI(checkItem.sub_url)}/${checkItem.key}/edit${params}`);
history.push(`/${owner}/${projectsId}/wiki/${encodeURI(checkItem.name)}/${checkItem.key}/edit${params}`);
}
function preview() {

View File

@ -63,7 +63,7 @@ export default (props) => {
projectsId && checkItem.name && getWiki({
owner: owner,
repo: projectsId,
pageName: checkItem.sub_url,
pageName: checkItem.name,
projectId: projectId,
}).then(res => {
if (res && res.message === "200") {

View File

@ -116,16 +116,13 @@ export function markdownToTree(markdownText){
lines.map((item, index) =>{
const title = item.trim();
const isFile = title.startsWith('[[') && title.endsWith(']]');
const titleStr = isFile ? title.substring(2, title.length - 2) : title.substring(2, title.length)
const node = {
// 带空格+[[]]或者- 标识
title: item,
children: [],
key: undefined,
// 纯内容
titleStr,
// 编码后的title,获取wiki内容用title_sub
title_sub: encodeURIComponent(titleStr),
titleStr: isFile ? title.substring(2, title.length - 2) : title.substring(2, title.length),
// 是否是wiki文件
isFile: isFile
}

View File

@ -163,7 +163,7 @@ export default function Sidebar(props) {
const {node, children, key} = item;
if(isFile){
//
deleteWiki({owner: owner, repo: projectsId, projectId: project.id, pageName: item.title_sub}).then(res => {
deleteWiki({owner: owner, repo: projectsId, projectId: project.id, pageName: title}).then(res => {
if(res && res.message === "204"){
// key
const menuListByDel = findSameKeyByDel(menuList, key);
@ -267,7 +267,7 @@ export default function Sidebar(props) {
projectId: project.id,
pageName: '_Sidebar',
title: '_Sidebar',
message: '',
commit_message: '',
content_base64: Base64.encode(content)
}).then(res => {
if (res && res.message === "200") {
@ -303,18 +303,20 @@ export default function Sidebar(props) {
e.stopPropagation();
setVisible(item);
setIsEditName(type);
const {titleStr, title_sub} = item;
let title = item.title.trim();
const isFile = title.startsWith('[[') && title.endsWith(']]');
title = isFile ? title.substring(2,title.length-2) : title.substring(2, title.length);
type === 2 && getWiki({
owner: owner,
repo: projectsId,
pageName: title_sub,
pageName: title,
projectId: project.id
}).then(res => {
if (res && res.message === "200") {
setWikiContent(res.data.md_content);
}
})
setMenuName(titleStr);
setMenuName(title);
}
//
@ -327,8 +329,9 @@ export default function Sidebar(props) {
setAddMenuError("不能仅输入空格");
return;
}
if (isEditName === 2 && /^-/.test(menuName)) {
setAddMenuError('不能以-开头');
const regEn = /[\\/:*?"<>|[\]-]/g;
if (regEn.test(menuName)) {
setAddMenuError('不能有特殊字符: \\ / : * ? \" < > | [ \] -');
return;
}
if(!isEditName){
@ -353,15 +356,14 @@ export default function Sidebar(props) {
}else{
// isEditName 1 2
const titleToJudge = isEditName === 2 ? `[[${menuName}]]` : `- ${menuName}`;
const {key, titleStr, title_sub} = visible;
//
if(titleStr === menuName){
const {title, key} = visible;
if(title.trim() === titleToJudge){
setAddMenuError("请修改名称");
return
}
//
const list = findBrotherNodesByKey(menuList, key) || [];
if(list.map(item=>item.titleStr).includes(menuName)){
if(list.map(item=>item.title.trim()).includes(titleToJudge)){
setAddMenuError("不能与同级目录名称相同");
return
}
@ -379,16 +381,17 @@ export default function Sidebar(props) {
})
if(isEditName === 2){
// -> wiki
const oldTitle = title.substring(title.indexOf('[[')+2, title.indexOf(']]'))
updateWiki({
owner,
repo: projectsId,
projectId: project.id,
//
pageName: title_sub,
pageName: oldTitle,
//
title: menuName,
content_base64: wikiContent,
message: '',
commit_message: '',
}).then(res=>{
if(res && res.message === '200'){
// wikisidebar

View File

@ -59,8 +59,10 @@ export default function UploadWiki(props) {
message.error('只能上传md、txt文件');
return false;
}
if (/^-/.test(file.name)) {
message.error('文件名不能以-开头');
let regEn = /[\\/:*?"<>|[\]-]/g;
if (regEn.test(file.name)) {
message.error('文件名不能有特殊字符: \\ / : * ? \" < > | [ \] -');
return false;
}
@ -84,7 +86,7 @@ export default function UploadWiki(props) {
projectId: project.id,
pageName: '_Sidebar',
title: '_Sidebar',
message: '',
commit_message: '',
content_base64: Base64.encode(treeToMd(sidebarList))
}).then(res => {
if (res && res.message === "200") {