From 94c92ad22bef03f7b80ce1da0a1a6761ab1e49e6 Mon Sep 17 00:00:00 2001 From: Michael An <2331806369@qq.com> Date: Wed, 29 May 2024 15:19:42 +0800 Subject: [PATCH 1/2] remove wiki2 markdown viewer and apis --- .../src/pages/wiki2/index-md-viewer/index.js | 114 ----- .../pages/wiki2/index-md-viewer/nav-item.js | 91 ---- .../src/pages/wiki2/index-md-viewer/style.css | 37 -- frontend/src/pages/wiki2/index.js | 465 +----------------- frontend/src/pages/wiki2/main-panel.js | 63 +-- frontend/src/pages/wiki2/side-panel.js | 97 +--- frontend/src/utils/wiki-api.js | 18 - 7 files changed, 36 insertions(+), 849 deletions(-) delete mode 100644 frontend/src/pages/wiki2/index-md-viewer/index.js delete mode 100644 frontend/src/pages/wiki2/index-md-viewer/nav-item.js delete mode 100644 frontend/src/pages/wiki2/index-md-viewer/style.css diff --git a/frontend/src/pages/wiki2/index-md-viewer/index.js b/frontend/src/pages/wiki2/index-md-viewer/index.js deleted file mode 100644 index e7dfdfa934e..00000000000 --- a/frontend/src/pages/wiki2/index-md-viewer/index.js +++ /dev/null @@ -1,114 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import { mdStringToSlate } from '@seafile/seafile-editor'; -import { isPublicWiki, repoID, serviceURL, slug } from '../../../utils/constants'; -import { Utils } from '../../../utils/utils'; -import { generateNavItems } from '../utils/generate-navs'; -import NavItem from './nav-item'; - -import'./style.css'; - -const viewerPropTypes = { - indexContent: PropTypes.string.isRequired, - onLinkClick: PropTypes.func.isRequired, -}; - -class IndexMdViewer extends React.Component { - - constructor(props) { - super(props); - this.links = []; - this.state = { - currentPath: '', - treeRoot: { name: '', href: '', children: [], isRoot: true }, - }; - } - - componentDidMount() { - const { indexContent } = this.props; - const slateNodes = mdStringToSlate(indexContent); - const newSlateNodes = Utils.changeMarkdownNodes(slateNodes, this.changeInlineNode); - const treeRoot = generateNavItems(newSlateNodes); - this.setState({ - treeRoot: treeRoot, - }); - } - - onLinkClick = (node) => { - const { currentPath } = this.state; - if (node.path === currentPath) return; - if (node.path) { - this.setState({ currentPath: node.path }); - } - if (node.href) this.props.onLinkClick(node.href); - }; - - changeInlineNode = (item) => { - if (item.type == 'link' || item.type === 'image') { - let url; - - // change image url - if (item.type == 'image' && isPublicWiki) { - url = item.data.src; - const re = new RegExp(serviceURL + '/lib/' + repoID +'/file.*raw=1'); - // different repo - if (!re.test(url)) { - return; - } - // get image path - let index = url.indexOf('/file'); - let index2 = url.indexOf('?'); - const imagePath = url.substring(index + 5, index2); - // replace url - item.data.src = serviceURL + '/view-image-via-public-wiki/?slug=' + slug + '&path=' + imagePath; - } - - else if (item.type == 'link') { - url = item.url; - /* eslint-disable */ - let expression = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/ - /* eslint-enable */ - let re = new RegExp(expression); - - // Solving relative paths - if (!re.test(url)) { - if (url.startsWith('./')) { - url = url.slice(2); - } - item.url = serviceURL + '/published/' + slug + '/' + url; - } - // change file url - else if (Utils.isInternalMarkdownLink(url, repoID)) { - let path = Utils.getPathFromInternalMarkdownLink(url, repoID); - // replace url - item.url = serviceURL + '/published/' + slug + path; - } - // change dir url - else if (Utils.isInternalDirLink(url, repoID)) { - let path = Utils.getPathFromInternalDirLink(url, repoID); - // replace url - item.url = serviceURL + '/published/' + slug + path; - } - } - } - - return item; - }; - - render() { - const { treeRoot, currentPath } = this.state; - return ( -
- {treeRoot.children.map(node => { - return ( - - ); - })} -
- ); - } -} - -IndexMdViewer.propTypes = viewerPropTypes; - -export default IndexMdViewer; diff --git a/frontend/src/pages/wiki2/index-md-viewer/nav-item.js b/frontend/src/pages/wiki2/index-md-viewer/nav-item.js deleted file mode 100644 index 3bfdd0064eb..00000000000 --- a/frontend/src/pages/wiki2/index-md-viewer/nav-item.js +++ /dev/null @@ -1,91 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import classNames from 'classnames'; - -const propTypes = { - node: PropTypes.object.isRequired, - currentPath: PropTypes.string, - onLinkClick: PropTypes.func.isRequired, -}; - -class NavItem extends React.Component { - - constructor(props) { - super(props); - this.state = { - expanded: false - }; - } - - toggleExpanded = () => { - const { expanded } = this.state; - this.setState({ expanded: !expanded }); - }; - - onLinkClick = (event) => { - event.preventDefault(); - const { node } = this.props; - const { expanded } = this.state; - if (node.children && node.children.length > 0 && !expanded) { - this.setState({expanded: !expanded}); - return; - } - this.props.onLinkClick(node); - }; - - itemClick = () => { - const { node } = this.props; - const { expanded } = this.state; - if (node.children && node.children.length > 0) { - this.setState({expanded: !expanded}); - return; - } - }; - - renderLink = ({ href, name, path, children }) => { - const { currentPath } = this.props; - const className = classNames('wiki-nav-content', { - 'no-children': !children || children.length === 0, - 'wiki-nav-content-highlight': currentPath === path, - }); - if (href && name) { - return ( -
- {name} -
- ); - } - - if (name) { - return
{name}
; - } - - return null; - }; - - render() { - const { node } = this.props; - const { expanded } = this.state; - if (node.children.length > 0) { - return ( -
- - {} - - {this.renderLink(node)} - {expanded && node.children.map((child, index) => { - return ( - - ); - })} -
- ); - } - - return this.renderLink(node); - } -} - -NavItem.propTypes = propTypes; - -export default NavItem; diff --git a/frontend/src/pages/wiki2/index-md-viewer/style.css b/frontend/src/pages/wiki2/index-md-viewer/style.css deleted file mode 100644 index cc49daacc41..00000000000 --- a/frontend/src/pages/wiki2/index-md-viewer/style.css +++ /dev/null @@ -1,37 +0,0 @@ -.wiki-nav-content { - margin-top: 18px; -} - -.wiki-nav-content.no-children { - margin-left: 1rem; -} - -.wiki-nav-content a, -.wiki-nav-content span { - color: #4d5156; - font-size: 14px; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - display: block; -} - -.wiki-nav-content a:hover { - text-decoration: none; - color: #eb8205; -} - -.wiki-nav-content-highlight a { - text-decoration: none; - color: #eb8205; -} - -.switch-btn { - position: absolute; - left: 0; - top: 2px; - color: #c0c0c0; - cursor: pointer; - font-size: 12px; - padding-right: 10px; -} diff --git a/frontend/src/pages/wiki2/index.js b/frontend/src/pages/wiki2/index.js index a7cdf66df0f..bab8c0256da 100644 --- a/frontend/src/pages/wiki2/index.js +++ b/frontend/src/pages/wiki2/index.js @@ -5,15 +5,11 @@ import { Modal } from 'reactstrap'; import { Utils } from '../../utils/utils'; import wikiAPI from '../../utils/wiki-api'; import SDocServerApi from '../../utils/sdoc-server-api'; -import { slug, wikiId, siteRoot, initialPath, isDir, sharedToken, hasIndex, lang, isWiki2, seadocServerUrl } from '../../utils/constants'; -import Dirent from '../../models/dirent'; +import { wikiId, siteRoot, lang, isWiki2, seadocServerUrl } from '../../utils/constants'; import WikiConfig from './models/wiki-config'; -import TreeNode from '../../components/tree-view/tree-node'; -import treeHelper from '../../components/tree-view/tree-helper'; import toaster from '../../components/toast'; import SidePanel from './side-panel'; import MainPanel from './main-panel'; -// import WikiLeftBar from './wiki-left-bar/wiki-left-bar'; import PageUtils from './view-structure/page-utils'; import '../../css/layout.css'; @@ -33,17 +29,9 @@ class Wiki extends Component { closeSideBar: false, isViewFile: true, isDataLoading: false, - direntList: [], editorContent: {}, permission: '', - lastModified: '', - latestContributor: '', - isTreeDataLoading: true, isConfigLoading: true, - treeData: treeHelper.buildTree(), - currentNode: null, - indexNode: null, - indexContent: '', currentPageId: '', config: new WikiConfig({}), repoId: '', @@ -51,9 +39,6 @@ class Wiki extends Component { assets_url: '', }; - window.onpopstate = this.onpopstate; - this.indexPath = '/index.md'; - this.homePath = '/home.md'; this.pythonWrapper = null; } @@ -65,15 +50,6 @@ class Wiki extends Component { componentDidMount() { this.getWikiConfig(); - this.loadSidePanel(initialPath); - this.loadWikiData(initialPath); - - this.links = document.querySelectorAll('#wiki-file-content a'); - this.links.forEach(link => link.addEventListener('click', this.onConentLinkClick)); - } - - componentWillUnmount() { - this.links.forEach(link => link.removeEventListener('click', this.onConentLinkClick)); } handlePath = () => { @@ -129,77 +105,6 @@ class Wiki extends Component { } }; - loadSidePanel = (initialPath) => { - if (hasIndex) { - this.loadIndexNode(); - return; - } - - // load dir list - initialPath = (isDir === 'None' || Utils.isSdocFile(initialPath)) ? '/' : initialPath; - this.loadNodeAndParentsByPath(initialPath); - }; - - loadWikiData = (initialPath) => { - this.pythonWrapper = document.getElementById('wiki-file-content'); - if (isDir === 'False' && Utils.isSdocFile(initialPath)) { - this.showDir('/'); - return; - } - - if (isDir === 'False') { - // this.showFile(initialPath); - this.setState({ path: initialPath }); - return; - } - - // if it is a file list, remove the template content provided by python - this.removePythonWrapper(); - - if (isDir === 'True') { - this.showDir(initialPath); - return; - } - - if (isDir === 'None' && initialPath === '/home.md') { - this.showDir('/'); - return; - } - - if (isDir === 'None') { - this.setState({ pathExist: false }); - let fileUrl = siteRoot + this.handlePath() + wikiId + Utils.encodePath(initialPath); - window.history.pushState({ url: fileUrl, path: initialPath }, initialPath, fileUrl); - } - }; - - loadIndexNode = () => { - wikiAPI.listWiki2Dir(wikiId, '/').then(res => { - let tree = this.state.treeData; - this.addFirstResponseListToNode(res.data.dirent_list, tree.root); - let indexNode = tree.getNodeByPath(this.indexPath); - wikiAPI.getWiki2FileContent(wikiId, indexNode.path).then(res => { - this.setState({ - treeData: tree, - indexNode: indexNode, - indexContent: res.data.content, - isTreeDataLoading: false, - }); - }); - }).catch(() => { - this.setState({ isLoadFailed: true }); - }); - }; - - showDir = (dirPath) => { - this.removePythonWrapper(); - this.loadDirentList(dirPath); - - // update location url - let fileUrl = siteRoot + this.handlePath() + wikiId + Utils.encodePath(dirPath); - window.history.pushState({ url: fileUrl, path: dirPath }, dirPath, fileUrl); - }; - getSdocFileContent = (docUuid, accessToken) => { const config = { docUuid, @@ -218,118 +123,6 @@ class Wiki extends Component { }); }; - showFile = (filePath) => { - this.setState({ - isDataLoading: true, - }); - wikiAPI.getWiki2FileContent(wikiId, filePath).then(res => { - const { permission, last_modified, latest_contributor, seadoc_access_token, assets_url } = res.data; - this.setState({ - permission, - lastModified: moment.unix(last_modified).fromNow(), - latestContributor: latest_contributor, - seadoc_access_token, - assets_url, - isViewFile: true, - path: filePath, - }); - const docUuid = assets_url.slice(assets_url.lastIndexOf('/') + 1); - this.getSdocFileContent(docUuid, seadoc_access_token); - }).catch(error => { - let errorMsg = Utils.getErrorMsg(error); - toaster.danger(errorMsg); - }); - - const hash = window.location.hash; - let fileUrl = `${siteRoot}${this.handlePath()}${wikiId}${Utils.encodePath(filePath)}${hash}`; - if (filePath === '/home.md') { - window.history.replaceState({ url: fileUrl, path: filePath }, filePath, fileUrl); - } else { - window.history.pushState({ url: fileUrl, path: filePath }, filePath, fileUrl); - } - }; - - loadDirentList = (dirPath) => { - this.setState({ isDataLoading: true }); - wikiAPI.listWiki2Dir(wikiId, dirPath).then(res => { - let direntList = res.data.dirent_list.map(item => { - let dirent = new Dirent(item); - return dirent; - }); - if (dirPath === '/') { - direntList = direntList.filter(item => { - if (item.type === 'dir') { - let name = item.name.toLowerCase(); - return name !== 'drafts' && name !== 'images' && name !== 'downloads'; - } - return true; - }); - } - direntList = Utils.sortDirents(direntList, 'name', 'asc'); - this.setState({ - path: dirPath, - isViewFile: false, - direntList: direntList, - isDataLoading: false, - }); - }).catch(() => { - this.setState({ isLoadFailed: true }); - }); - }; - - loadTreeNodeByPath = (path) => { - let tree = this.state.treeData.clone(); - let node = tree.getNodeByPath(path); - if (!node.isLoaded) { - wikiAPI.listWiki2Dir(wikiId, node.path).then(res => { - this.addResponseListToNode(res.data.dirent_list, node); - let parentNode = tree.getNodeByPath(node.parentNode.path); - parentNode.isExpanded = true; - this.setState({ - treeData: tree, - currentNode: node - }); - }); - } else { - let parentNode = tree.getNodeByPath(node.parentNode.path); - parentNode.isExpanded = true; - this.setState({ treeData: tree, currentNode: node }); //tree - } - }; - - loadNodeAndParentsByPath = (path) => { - let tree = this.state.treeData.clone(); - if (Utils.isMarkdownFile(path)) { - path = Utils.getDirName(path); - } - wikiAPI.listWiki2Dir(wikiId, path, true).then(res => { - let direntList = res.data.dirent_list; - let results = {}; - for (let i = 0; i < direntList.length; i++) { - let object = direntList[i]; - let key = object.parent_dir; - if (!results[key]) { - results[key] = []; - } - results[key].push(object); - } - for (let key in results) { - let node = tree.getNodeByPath(key); - if (!node.isLoaded && node.path === '/') { - this.addFirstResponseListToNode(results[key], node); - } else if (!node.isLoaded) { - this.addResponseListToNode(results[key], node); - } - } - this.setState({ - isTreeDataLoading: false, - treeData: tree - }); - }).catch(() => { - this.setState({ isLoadFailed: true }); - }); - }; - removePythonWrapper = () => { if (this.pythonWrapper) { document.body.removeChild(this.pythonWrapper); @@ -337,227 +130,10 @@ class Wiki extends Component { } }; - onConentLinkClick = (event) => { - event.preventDefault(); - event.stopPropagation(); - let link = ''; - if (event.target.tagName !== 'A') { - let target = event.target.parentNode; - while (target.tagName !== 'A') { - target = target.parentNode; - } - link = target.href; - } else { - link = event.target.href; - } - this.onLinkClick(link); - }; - - onLinkClick = (link) => { - const url = link; - if (Utils.isWikiInternalMarkdownLink(url, slug)) { - let path = Utils.getPathFromWikiInternalMarkdownLink(url, slug); - this.showFile(path); - } else if (Utils.isWikiInternalDirLink(url, slug)) { - let path = Utils.getPathFromWikiInternalDirLink(url, slug); - this.showDir(path); - } else { - window.location.href = url; - } - if (!this.state.closeSideBar) { - this.setState({ closeSideBar: true }); - } - }; - - onpopstate = (event) => { - if (event.state && event.state.path) { - let path = event.state.path; - if (Utils.isMarkdownFile(path)) { - this.showFile(path); - } else { - this.loadDirentList(path); - this.setState({ - path: path, - isViewFile: false - }); - } - } - }; - - onSearchedClick = (item) => { - let path = item.is_dir ? item.path.slice(0, item.path.length - 1) : item.path; - if (this.state.currentPath === path) { - return; - } - - // load sidePanel - let index = -1; - let paths = Utils.getPaths(path); - for (let i = 0; i < paths.length; i++) { - // eslint-disable-next-line no-use-before-define - let node = this.state.treeData.getNodeByPath(node); - if (!node) { - index = i; - break; - } - } - if (index === -1) { // all the data has been loaded already. - let tree = this.state.treeData.clone(); - let node = tree.getNodeByPath(item.path); - treeHelper.expandNode(node); - this.setState({ treeData: tree }); - } else { - this.loadNodeAndParentsByPath(path); - } - - // load mainPanel - if (item.is_dir) { - this.showDir(path); - } else { - if (Utils.isMarkdownFile(path)) { - this.showFile(path); - } else { - let url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(path); - let newWindow = window.open('about:blank'); - newWindow.location.href = url; - } - } - }; - - onMenuClick = () => { - this.setState({ closeSideBar: !this.state.closeSideBar }); - }; - - onMainNavBarClick = (nodePath) => { - let tree = this.state.treeData.clone(); - let node = tree.getNodeByPath(nodePath); - tree.expandNode(node); - this.setState({ treeData: tree, currentNode: node }); - this.showDir(node.path); - }; - - onDirentClick = (dirent) => { - let direntPath = Utils.joinPath(this.state.path, dirent.name); - if (dirent.isDir()) { // is dir - this.loadTreeNodeByPath(direntPath); - this.showDir(direntPath); - } else { // is file - if (Utils.isMarkdownFile(direntPath)) { - this.showFile(direntPath); - } else { - const w = window.open('about:blank'); - const url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(direntPath); - w.location.href = url; - } - } - }; - onCloseSide = () => { this.setState({ closeSideBar: !this.state.closeSideBar }); }; - onNodeClick = (node) => { - if (!this.state.pathExist) { - this.setState({ pathExist: true }); - } - - if (node.object.isDir()) { - if (!node.isLoaded) { - let tree = this.state.treeData.clone(); - node = tree.getNodeByPath(node.path); - wikiAPI.listWiki2Dir(wikiId, node.path).then(res => { - this.addResponseListToNode(res.data.dirent_list, node); - tree.collapseNode(node); - this.setState({ treeData: tree }); - }); - } - if (node.path === this.state.path) { - if (node.isExpanded) { - let tree = treeHelper.collapseNode(this.state.treeData, node); - this.setState({ treeData: tree }); - } else { - let tree = this.state.treeData.clone(); - node = tree.getNodeByPath(node.path); - tree.expandNode(node); - this.setState({ treeData: tree }); - } - } - } - - if (node.path === this.state.path) { - return; - } - - if (node.object.isDir()) { // isDir - this.showDir(node.path); - } else { - if (Utils.isMarkdownFile(node.path) || Utils.isSdocFile(node.path)) { - if (node.path !== this.state.path) { - this.showFile(node.path); - } - this.onCloseSide(); - } else { - const w = window.open('about:blank'); - const url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(node.path); - w.location.href = url; - } - } - }; - - onNodeCollapse = (node) => { - let tree = treeHelper.collapseNode(this.state.treeData, node); - this.setState({ treeData: tree }); - }; - - onNodeExpanded = (node) => { - let tree = this.state.treeData.clone(); - node = tree.getNodeByPath(node.path); - if (!node.isLoaded) { - wikiAPI.listWiki2Dir(wikiId, node.path).then(res => { - this.addResponseListToNode(res.data.dirent_list, node); - this.setState({ treeData: tree }); - }); - } else { - tree.expandNode(node); - this.setState({ treeData: tree }); - } - }; - - addFirstResponseListToNode = (list, node) => { - node.isLoaded = true; - node.isExpanded = true; - let direntList = list.map(item => { - return new Dirent(item); - }); - direntList = direntList.filter(item => { - if (item.type === 'dir') { - let name = item.name.toLowerCase(); - return name !== 'drafts' && name !== 'images' && name !== 'downloads'; - } - return true; - }); - direntList = Utils.sortDirents(direntList, 'name', 'asc'); - - let nodeList = direntList.map(object => { - return new TreeNode({ object }); - }); - node.addChildren(nodeList); - }; - - addResponseListToNode = (list, node) => { - node.isLoaded = true; - node.isExpanded = true; - let direntList = list.map(item => { - return new Dirent(item); - }); - direntList = Utils.sortDirents(direntList, 'name', 'asc'); - - let nodeList = direntList.map(object => { - return new TreeNode({ object }); - }); - node.addChildren(nodeList); - }; - showPage = (pageId, filePath) => { this.setState({ isDataLoading: true, @@ -565,11 +141,9 @@ class Wiki extends Component { this.removePythonWrapper(); wikiAPI.getWiki2Page(wikiId, pageId).then(res => { - const { permission, last_modified, latest_contributor, seadoc_access_token, assets_url } = res.data; + const { permission, seadoc_access_token, assets_url } = res.data; this.setState({ permission, - lastModified: moment.unix(last_modified).fromNow(), - latestContributor: latest_contributor, seadoc_access_token, assets_url, isViewFile: true, @@ -597,16 +171,10 @@ class Wiki extends Component { const { pages } = config; const currentPage = PageUtils.getPageById(pages, pageId); const path = currentPage.path; - if (Utils.isMarkdownFile(path) || Utils.isSdocFile(path)) { - if (path !== this.state.path) { - this.showPage(pageId, path); - } - this.onCloseSide(); - } else { - const w = window.open('about:blank'); - const url = siteRoot + 'd/' + sharedToken + '/files/?p=' + Utils.encodePath(path); - w.location.href = url; + if (path !== this.state.path) { + this.showPage(pageId, path); } + this.onCloseSide(); this.setState({ currentPageId: pageId, path: path, @@ -618,25 +186,10 @@ class Wiki extends Component { render() { return (
- {/* {isWiki2 && - this.saveWikiConfig(Object.assign({}, this.state.config, data))} - /> - } */} diff --git a/frontend/src/pages/wiki2/main-panel.js b/frontend/src/pages/wiki2/main-panel.js index 72628f11116..1fbe42881f2 100644 --- a/frontend/src/pages/wiki2/main-panel.js +++ b/frontend/src/pages/wiki2/main-panel.js @@ -1,7 +1,7 @@ -import React, { Component, Fragment } from 'react'; +import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { SdocWikiViewer } from '@seafile/sdoc-editor'; -import { gettext, repoID, siteRoot, username } from '../../utils/constants'; +import { gettext, username } from '../../utils/constants'; import Loading from '../../components/loading'; import { Utils } from '../../utils/utils'; import Account from '../../components/common/account'; @@ -14,12 +14,6 @@ const propTypes = { isDataLoading: PropTypes.bool.isRequired, editorContent: PropTypes.object, permission: PropTypes.string, - lastModified: PropTypes.string, - latestContributor: PropTypes.string, - onMenuClick: PropTypes.func.isRequired, - onSearchedClick: PropTypes.func.isRequired, - onMainNavBarClick: PropTypes.func.isRequired, - onLinkClick: PropTypes.func.isRequired, seadoc_access_token: PropTypes.string, assets_url: PropTypes.string, config: PropTypes.object, @@ -30,59 +24,11 @@ class MainPanel extends Component { constructor(props) { super(props); - this.state = { docUuid: '', }; } - onMenuClick = () => { - this.props.onMenuClick(); - }; - - onEditClick = (e) => { - e.preventDefault(); - let url = siteRoot + 'lib/' + repoID + '/file' + this.props.path + '?mode=edit'; - window.open(url); - }; - - onMainNavBarClick = (e) => { - let path = Utils.getEventData(e, 'path'); - this.props.onMainNavBarClick(path); - }; - - renderNavPath = () => { - let paths = this.props.path.split('/'); - let nodePath = ''; - let pathElem = paths.map((item, index) => { - if (item === '') { - return null; - } - if (index === (paths.length - 1)) { - return ( - - / - {item} - - ); - } else { - nodePath += '/' + item; - return ( - - / - - {item} - - - ); - } - }); - return pathElem; - }; - static getDerivedStateFromProps(props, state) { const { seadoc_access_token } = props; const config = window.app.config; @@ -102,7 +48,6 @@ class MainPanel extends Component { } render() { - const errMessage = (
{gettext('Folder does not exist.')}
); const { permission, pathExist, isDataLoading, isViewFile } = this.props; const isViewingFile = pathExist && !isDataLoading && isViewFile; const isReadOnly = !(permission === 'rw'); @@ -119,7 +64,9 @@ class MainPanel extends Component {
- {!this.props.pathExist && errMessage} + {!this.props.pathExist && +
{gettext('Folder does not exist.')}
+ } {this.props.pathExist && this.props.isDataLoading && } {isViewingFile && Utils.isSdocFile(this.props.path) && ( { - return ( -
-
- -
- ); - }; - - renderTreeView = () => { - return ( -
- {/* {this.props.treeData && ( - - )} */} - {isWiki2 && - - } - {this.state.isShowNewFolderDialog && - - } - {this.state.isShowAddNewPageDialog && - - } -
- ); - }; - confirmDeletePage = (pageId) => { const config = deepCopy(this.props.config); const { pages, navigation } = config; @@ -373,28 +314,40 @@ class SidePanel extends Component { ); }; - renderContent = () => { - const { isLoading, indexNode, config } = this.props; - if (isLoading) { - return ; - } - if (indexNode) { - return this.renderIndexView(); - } - if (isObjectNotEmpty(config)) { - return this.renderFolderView(); - } - return this.renderTreeView(); + renderNoFolder = () => { + return ( +
+ {isWiki2 && + + } + {this.state.isShowNewFolderDialog && + + } + {this.state.isShowAddNewPageDialog && + + } +
+ ); }; render() { + const { isLoading, config } = this.props; return (

{repoName}

- {this.renderContent()} + {isLoading ? : (isObjectNotEmpty(config) ? this.renderFolderView() : this.renderNoFolder())}
); diff --git a/frontend/src/utils/wiki-api.js b/frontend/src/utils/wiki-api.js index fe258a45236..36980249311 100644 --- a/frontend/src/utils/wiki-api.js +++ b/frontend/src/utils/wiki-api.js @@ -106,24 +106,6 @@ class WikiAPI { // for wiki2 - listWiki2Dir(wikiId, dirPath, withParents) { - const path = encodeURIComponent(dirPath); - let url = this.server + '/api/v2.1/wiki2/' + wikiId + '/page-dir/?p=' + path; - if (withParents) { - url = this.server + '/api/v2.1/wiki2/' + wikiId + '/page-dir/?p=' + path + '&with_parents=' + withParents; - } - return this.req.get(url); - } - - - getWiki2FileContent(wikiId, filePath) { - const path = encodeURIComponent(filePath); - const time = new Date().getTime(); - const url = this.server + '/api/v2.1/wiki2/' + wikiId + '/content/' + '?p=' + path + '&_=' + time; - return this.req.get(url); - } - - listWikis2(options) { /* * options: `{type: 'shared'}`, `{type: ['mine', 'shared', ...]}` From c97224bf6218935b635b647d8813eb931a69dc95 Mon Sep 17 00:00:00 2001 From: Michael An <2331806369@qq.com> Date: Wed, 29 May 2024 15:32:56 +0800 Subject: [PATCH 2/2] remove wiki2 useless APIs --- seahub/api2/endpoints/wiki2.py | 149 --------------------------------- seahub/urls.py | 5 +- 2 files changed, 1 insertion(+), 153 deletions(-) diff --git a/seahub/api2/endpoints/wiki2.py b/seahub/api2/endpoints/wiki2.py index e60ec42885a..dc53e688a4c 100644 --- a/seahub/api2/endpoints/wiki2.py +++ b/seahub/api2/endpoints/wiki2.py @@ -316,155 +316,6 @@ def get(self, request, wiki_id): return Response({'wiki': wiki}) - -class Wiki2PagesDirView(APIView): - authentication_classes = (TokenAuthentication, SessionAuthentication) - permission_classes = (IsAuthenticatedOrReadOnly,) - throttle_classes = (UserRateThrottle,) - - def get(self, request, wiki_id): - """List all dir files in a wiki. - """ - try: - wiki = Wiki.objects.get(id=wiki_id) - except Wiki.DoesNotExist: - error_msg = "Wiki not found." - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - parent_dir = request.GET.get("p", '/') - parent_dir = normalize_dir_path(parent_dir) - permission = check_folder_permission(request, wiki.repo_id, parent_dir) - if not permission: - error_msg = 'Permission denied.' - return api_error(status.HTTP_403_FORBIDDEN, error_msg) - - try: - repo = seafile_api.get_repo(wiki.repo_id) - if not repo: - error_msg = "Wiki library not found." - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - except SearpcError: - error_msg = "Internal Server Error" - return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) - - with_parents = request.GET.get('with_parents', 'false') - if with_parents not in ('true', 'false'): - error_msg = 'with_parents invalid.' - return api_error(status.HTTP_400_BAD_REQUEST, error_msg) - - with_parents = to_python_boolean(with_parents) - dir_id = seafile_api.get_dir_id_by_path(repo.repo_id, parent_dir) - if not dir_id: - error_msg = 'Folder %s not found.' % parent_dir - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - parent_dir_list = [] - if not with_parents: - # only return dirent list in current parent folder - parent_dir_list.append(parent_dir) - else: - # if value of 'p' parameter is '/a/b/c' add with_parents's is 'true' - # then return dirent list in '/', '/a', '/a/b' and '/a/b/c'. - if parent_dir == '/': - parent_dir_list.append(parent_dir) - else: - tmp_parent_dir = '/' - parent_dir_list.append(tmp_parent_dir) - for folder_name in parent_dir.strip('/').split('/'): - tmp_parent_dir = posixpath.join(tmp_parent_dir, folder_name) - parent_dir_list.append(tmp_parent_dir) - - all_dirs_info = [] - for parent_dir in parent_dir_list: - all_dirs = get_wiki_dirs_by_path(repo.repo_id, parent_dir, []) - all_dirs_info += all_dirs - - return Response({ - "dirent_list": all_dirs_info - }) - - -class Wiki2PageContentView(APIView): - authentication_classes = (TokenAuthentication, SessionAuthentication) - permission_classes = (IsAuthenticatedOrReadOnly,) - throttle_classes = (UserRateThrottle,) - - def get(self, request, wiki_id): - """Get content of a wiki - """ - path = request.GET.get('p', '/') - try: - wiki = Wiki.objects.get(id=wiki_id) - except Wiki.DoesNotExist: - error_msg = "Wiki not found." - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - - if not check_wiki_permission(wiki, request.user.username): - error_msg = 'Permission denied.' - return api_error(status.HTTP_403_FORBIDDEN, error_msg) - - permission = check_folder_permission(request, wiki.repo_id, '/') - if not permission: - error_msg = 'Permission denied.' - return api_error(status.HTTP_403_FORBIDDEN, error_msg) - - try: - repo = seafile_api.get_repo(wiki.repo_id) - if not repo: - error_msg = "Wiki library not found." - return api_error(status.HTTP_404_NOT_FOUND, error_msg) - except SearpcError: - error_msg = _("Internal Server Error") - return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) - - try: - file_id = seafile_api.get_file_id_by_path(repo.repo_id, path) - except SearpcError as e: - logger.error(e) - return api_error(HTTP_520_OPERATION_FAILED, - "Failed to get file id by path.") - if not file_id: - return api_error(status.HTTP_404_NOT_FOUND, "File not found") - - # send stats message - send_file_access_msg(request, repo, path, 'api') - - file_uuid = get_seadoc_file_uuid(repo, path) - filename = os.path.basename(path) - - try: - sdoc_server_api = SdocServerAPI(file_uuid, filename, request.user.username) - res = sdoc_server_api.get_doc() - content = json.dumps(res) - except Exception as e: - logger.error(e) - error_msg = 'Internal Server Error' - return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg) - - try: - dirent = seafile_api.get_dirent_by_path(repo.repo_id, path) - if dirent: - latest_contributor, last_modified = dirent.modifier, dirent.mtime - else: - latest_contributor, last_modified = None, 0 - except SearpcError as e: - logger.error(e) - latest_contributor, last_modified = None, 0 - - assets_url = '/api/v2.1/seadoc/download-image/' + file_uuid - seadoc_access_token = gen_seadoc_access_token(file_uuid, filename, request.user.username, permission=permission) - - return Response({ - "content": content, - "latest_contributor": email2nickname(latest_contributor), - "last_modified": last_modified, - "permission": permission, - "seadoc_server_url": SEADOC_SERVER_URL, - "seadoc_access_token": seadoc_access_token, - "assets_url": assets_url, - }) - - class Wiki2PagesView(APIView): authentication_classes = (TokenAuthentication, SessionAuthentication) permission_classes = (IsAuthenticated, ) diff --git a/seahub/urls.py b/seahub/urls.py index d367e9ba496..cec0d30dca2 100644 --- a/seahub/urls.py +++ b/seahub/urls.py @@ -204,8 +204,7 @@ from seahub.ai.apis import LibrarySdocIndexes, Search, LibrarySdocIndex, TaskStatus, \ LibraryIndexState, QuestionAnsweringSearchInLibrary, FileDownloadToken from seahub.wiki2.views import wiki_view -from seahub.api2.endpoints.wiki2 import Wikis2View, Wiki2View, Wiki2ConfigView, Wiki2PagesDirView, Wiki2PageContentView,\ - Wiki2PagesView, Wiki2PageView +from seahub.api2.endpoints.wiki2 import Wikis2View, Wiki2View, Wiki2ConfigView, Wiki2PagesView, Wiki2PageView from seahub.api2.endpoints.subscription import SubscriptionView, SubscriptionPlansView, SubscriptionLogsView urlpatterns = [ @@ -523,9 +522,7 @@ ## user::wiki2 re_path(r'^api/v2.1/wikis2/$', Wikis2View.as_view(), name='api-v2.1-wikis2'), re_path(r'^api/v2.1/wiki2/(?P\d+)/$', Wiki2View.as_view(), name='api-v2.1-wiki2'), - re_path(r'^api/v2.1/wiki2/(?P\d+)/page-dir/$', Wiki2PagesDirView.as_view(), name='api-v2.1-wiki2-pages-dir'), re_path(r'^api/v2.1/wiki2/(?P\d+)/config/$', Wiki2ConfigView.as_view(), name='api-v2.1-wiki2-config'), - re_path(r'^api/v2.1/wiki2/(?P\d+)/content/$', Wiki2PageContentView.as_view(), name='api-v2.1-wiki2-pages-content'), re_path(r'^api/v2.1/wiki2/(?P\d+)/pages/$', Wiki2PagesView.as_view(), name='api-v2.1-wiki2-pages'), re_path(r'^api/v2.1/wiki2/(?P\d+)/page/(?P[-0-9a-zA-Z]{4})/$', Wiki2PageView.as_view(), name='api-v2.1-wiki2-page'),