1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 01:41:39 +00:00

update list wiki dir (#2909)

This commit is contained in:
C_Q
2019-01-30 11:48:15 +08:00
committed by Daniel Pan
parent 68ea300225
commit 362f673f35
10 changed files with 90 additions and 61 deletions

View File

@@ -94,7 +94,7 @@ class IndexContentViewer extends React.Component {
}
// change dir url
else if (Utils.isInternalDirLink(url, repoID)) {
let path = Utils.getPathFromInternalDirLink(url, repoID, slug);
let path = Utils.getPathFromInternalDirLink(url, repoID);
// replace url
item.data.href = serviceURL + '/wikis/' + slug + path;
}

View File

@@ -65,7 +65,7 @@ class DirOperationToolbar extends React.Component {
onEditClick = (e) => {
e.preventDefault();
let { path, repoID } = this.props;
let url = siteRoot + 'lib/' + repoID + '/file' + path + '?mode=edit';
let url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(path) + '?mode=edit';
window.open(url);
}

View File

@@ -134,7 +134,7 @@ class WikiMarkdownViewer extends React.Component {
}
// change dir url
else if (Utils.isInternalDirLink(url, repoID)) {
let path = Utils.getPathFromInternalDirLink(url, repoID, slug);
let path = Utils.getPathFromInternalDirLink(url, repoID);
// replace url
item.data.href = serviceURL + '/wikis/' + slug + path;
}

View File

@@ -183,6 +183,7 @@ class Wiki extends Component {
}
loadSidePanel = (initialPath) => {
if (initialPath === '/' || isDir === 'None') {
seafileAPI.listDir(repoID, '/').then(res => {
let tree = this.state.treeData;
@@ -207,7 +208,7 @@ class Wiki extends Component {
});
// update location url
let url = siteRoot + 'wiki/lib/' + repoID + path;
let url = siteRoot + 'wiki/lib/' + repoID + Utils.encodePath(path);
window.history.pushState({ url: url, path: path}, path, url);
}
@@ -239,7 +240,7 @@ class Wiki extends Component {
});
});
let fileUrl = siteRoot + 'wiki/lib/' + repoID + filePath;
let fileUrl = siteRoot + 'wiki/lib/' + repoID + Utils.encodePath(filePath);
window.history.pushState({url: fileUrl, path: filePath}, filePath, fileUrl);
}
@@ -317,7 +318,7 @@ class Wiki extends Component {
let path = Utils.getPathFromInternalMarkdownLink(url, repoID);
this.showFile(path);
} else if (Utils.isInternalDirLink(url, repoID)) {
let path = Utils.getPathFromInternalDirLink(url, repoID, slug);
let path = Utils.getPathFromInternalDirLink(url, repoID);
this.showDir(path);
} else {
window.open(url);
@@ -900,7 +901,7 @@ class Wiki extends Component {
}
} else {
const w = window.open('about:blank');
const url = siteRoot + 'lib/' + repoID + '/file' + node.path;
const url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(node.path);
w.location.href = url;
}
}

View File

@@ -446,12 +446,12 @@ export const Utils = {
return path;
},
getPathFromInternalDirLink: function(url, repoID, repoName) {
var repoName = encodeURIComponent(repoName);
var re = new RegExp(serviceURL + '/library/' + repoID + '/' + repoName + '(/.*)');
getPathFromInternalDirLink: function(url, repoID) {
var re = new RegExp(serviceURL + '/library/' + repoID + '(/.*)');
var array = re.exec(url);
var path = decodeURIComponent(array[1]);
path = path.slice(1);
path = path.slice(path.indexOf('/'));
return path;
},
@@ -471,7 +471,13 @@ export const Utils = {
var slug = encodeURIComponent(slug);
var re = new RegExp(serviceURL + '/wikis/' + slug + '(.*\.md)');
var array = re.exec(url);
var path = decodeURIComponent(array[1]);
var path = array[1];
try {
path = decodeURIComponent(path);
} catch(err) {
path = path.replace(/%/g, '%25');
path = decodeURIComponent(path);
}
return path;
},
@@ -479,7 +485,13 @@ export const Utils = {
var slug = encodeURIComponent(slug);
var re = new RegExp(serviceURL + '/wikis/' + slug+ '(/.*)');
var array = re.exec(url);
var path = decodeURIComponent(array[1]);
var path = array[1];
try {
path = decodeURIComponent(path);
} catch(err) {
path = path.replace(/%/g, '%25');
path = decodeURIComponent(path);
}
return path;
},

View File

@@ -58,7 +58,7 @@ class Wiki extends Component {
this.showDir('/');
} else {
this.setState({pathExist: false});
let fileUrl = siteRoot + 'wikis/' + slug + initialPath;
let fileUrl = siteRoot + 'wikis/' + slug + Utils.encodePath(initialPath);
window.history.pushState({url: fileUrl, path: initialPath}, initialPath, fileUrl);
}
} else if (isDir === 'True') {
@@ -70,22 +70,20 @@ class Wiki extends Component {
loadSidePanel = (initialPath) => {
if (initialPath === this.homePath || isDir === 'None') {
seafileAPI.listDir(repoID, '/').then(res => {
seafileAPI.listWikiDir(slug, '/').then(res => {
let tree = this.state.treeData;
this.addFirstResponseListToNode(res.data.dirent_list, tree.root);
let indexNode = tree.getNodeByPath(this.indexPath);
let homeNode = tree.getNodeByPath(this.homePath);
if (homeNode && indexNode) {
seafileAPI.getFileDownloadLink(repoID, indexNode.path).then(res => {
seafileAPI.getFileContent(res.data).then(res => {
seafileAPI.getWikiFileContent(slug, indexNode.path).then(res => {
this.setState({
treeData: tree,
indexNode: indexNode,
indexContent: res.data,
indexContent: res.data.content,
isTreeDataLoading: false,
});
});
});
} else {
this.setState({
treeData: tree,
@@ -104,7 +102,7 @@ class Wiki extends Component {
this.loadDirentList(dirPath);
// update location url
let fileUrl = siteRoot + 'wikis/' + slug + dirPath;
let fileUrl = siteRoot + 'wikis/' + slug + Utils.encodePath(dirPath);
window.history.pushState({url: fileUrl, path: dirPath}, dirPath, fileUrl);
}
@@ -115,29 +113,25 @@ class Wiki extends Component {
path: filePath,
});
seafileAPI.getFileInfo(repoID, filePath).then(res => {
let { mtime, permission, last_modifier_name } = res.data;
seafileAPI.getFileDownloadLink(repoID, filePath).then(res => {
seafileAPI.getFileContent(res.data).then(res => {
seafileAPI.getWikiFileContent(slug, filePath).then(res => {
let data = res.data;
this.setState({
isDataLoading: false,
content: res.data,
permission: permission,
lastModified: moment.unix(mtime).fromNow(),
latestContributor: last_modifier_name,
});
});
content: data.content,
permission: data.permission,
lastModified: moment.unix(data.last_modified).fromNow(),
latestContributor: data.latest_contributor,
});
});
const hash = window.location.hash;
let fileUrl = siteRoot + 'wikis/' + slug + filePath + hash;
let fileUrl = siteRoot + 'wikis/' + slug + Utils.encodePath(filePath) + hash;
window.history.pushState({url: fileUrl, path: filePath}, filePath, fileUrl);
}
loadDirentList = (dirPath) => {
this.setState({isDataLoading: true});
seafileAPI.listDir(repoID, dirPath).then(res => {
seafileAPI.listWikiDir(slug, dirPath).then(res => {
let direntList = res.data.dirent_list.map(item => {
let dirent = new Dirent(item);
return dirent;
@@ -158,7 +152,7 @@ class Wiki extends Component {
let tree = this.state.treeData.clone();
let node = tree.getNodeByPath(path);
if (!node.isLoaded) {
seafileAPI.listDir(repoID, node.path).then(res => {
seafileAPI.listWikiDir(slug, node.path).then(res => {
this.addResponseListToNode(res.data.dirent_list, node);
let parentNode = tree.getNodeByPath(node.parentNode.path);
parentNode.isExpanded = true;
@@ -179,7 +173,7 @@ class Wiki extends Component {
if (Utils.isMarkdownFile(path)) {
path = Utils.getDirName(path);
}
seafileAPI.listDir(repoID, path, {with_parents: true}).then(res => {
seafileAPI.listWikiDir(slug, path, true).then(res => {
let direntList = res.data.dirent_list;
let results = {};
for (let i = 0; i < direntList.length; i++) {
@@ -314,7 +308,7 @@ class Wiki extends Component {
if (!node.isLoaded) {
let tree = this.state.treeData.clone();
node = tree.getNodeByPath(node.path);
seafileAPI.listDir(repoID, node.path).then(res => {
seafileAPI.listWikiDir(slug, node.path).then(res => {
this.addResponseListToNode(res.data.dirent_list, node);
tree.collapseNode(node);
this.setState({treeData: tree});
@@ -346,7 +340,7 @@ class Wiki extends Component {
}
} else {
const w = window.open('about:blank');
const url = siteRoot + 'lib/' + repoID + '/file' + node.path;
const url = siteRoot + 'lib/' + repoID + '/file' + Utils.encodePath(node.path);
w.location.href = url;
}
}
@@ -361,7 +355,7 @@ class Wiki extends Component {
let tree = this.state.treeData.clone();
node = tree.getNodeByPath(node.path);
if (!node.isLoaded) {
seafileAPI.listDir(repoID, node.path).then(res => {
seafileAPI.listWikiDir(slug, node.path).then(res => {
this.addResponseListToNode(res.data.dirent_list, node);
this.setState({treeData: tree});
});

View File

@@ -3,6 +3,7 @@
import os
import logging
import urllib2
import posixpath
from rest_framework import status
from rest_framework.authentication import SessionAuthentication
@@ -19,11 +20,11 @@ from seahub.views.file import send_file_access_msg
from seahub.api2.views import get_dir_file_recursively
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.throttling import UserRateThrottle
from seahub.api2.utils import api_error
from seahub.api2.utils import api_error, to_python_boolean
from seahub.wiki.models import Wiki, WikiPageMissing
from seahub.wiki.utils import (clean_page_name, get_wiki_pages, get_inner_file_url,
get_wiki_dirent, get_wiki_page_object, get_wiki_dirs_by_path)
from seahub.utils import gen_inner_file_get_url
from seahub.utils import gen_inner_file_get_url, normalize_dir_path
from seahub.base.templatetags.seahub_tags import email2contact_email, email2nickname
logger = logging.getLogger(__name__)
@@ -219,11 +220,6 @@ class WikiPagesDirView(APIView):
error_msg = "Wiki not found."
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
path = request.GET.get("p", '')
if not path:
error_msg = "Folder not found."
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
# perm check
if not wiki.has_read_perm(request):
error_msg = "Permission denied"
@@ -238,15 +234,44 @@ class WikiPagesDirView(APIView):
error_msg = "Internal Server Error"
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
dir_id = seafile_api.get_dir_id_by_path(repo.repo_id, path)
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)
parent_dir = request.GET.get("p", '/')
parent_dir = normalize_dir_path(parent_dir)
dir_id = seafile_api.get_dir_id_by_path(repo.repo_id, parent_dir)
if not dir_id:
error_msg = 'Folder %s not found.' % path
error_msg = 'Folder %s not found.' % parent_dir
return api_error(status.HTTP_404_NOT_FOUND, error_msg)
all_dirs = get_wiki_dirs_by_path(repo.repo_id, path, [])
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({
"dir_file_list": all_dirs
"dirent_list": all_dirs_info
})

View File

@@ -10,7 +10,7 @@
config: {
repoId: "{{ repo_id }}",
serviceUrl: "{{ service_url}}",
initial_path: "{{ initial_path }}",
initial_path: "{{ initial_path|escapejs }}",
slug: "{{ repo_name }}",
isDir: "{{ is_dir }}",
permission: "{{ permission }}"

View File

@@ -10,7 +10,7 @@
config: {
slug: "{{ wiki.slug }}",
repoId: "{{ wiki.repo_id }}",
initial_path: "{{ file_path }}",
initial_path: "{{ file_path|escapejs }}",
permission: "{{ user_can_write }}",
isPublicWiki: "{{ is_public_wiki }}",
isDir: "{{ is_dir }}",

View File

@@ -238,14 +238,11 @@ def get_wiki_dirs_by_path(repo_id, path, all_dirs):
entry["type"] = 'file'
entry["parent_dir"] = path
entry["id"] = dirent.obj_id
entry["name"] = dirent.obj_name
entry["size"] = dirent.size
entry["last_update_time"] = dirent.mtime
entry["mtime"] = dirent.mtime
all_dirs.append(entry)
if stat.S_ISDIR(dirent.mode):
sub_path = posixpath.join(path, dirent.obj_name)
get_wiki_dirs_by_path(repo_id, sub_path, all_dirs)
return all_dirs