1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

optimized path check method (#2846)

This commit is contained in:
杨顺强
2019-01-17 16:33:27 +08:00
committed by Daniel Pan
parent c21fdf8ebf
commit 4444a4120a
3 changed files with 38 additions and 90 deletions

View File

@@ -1,4 +1,4 @@
import { mediaUrl, gettext } from './constants';
import { mediaUrl, gettext, siteRoot } from './constants';
import { strChineseFirstPY } from './pinyin-by-unicode';
export const Utils = {
@@ -389,6 +389,31 @@ export const Utils = {
}
},
isInternalMarkdownLink: function(url, repoID) {
var re = new RegExp(siteRoot + 'lib/' + repoID + '.*\.md$');
return re.test(url);
},
isInternalDirLink: function(url, repoID) {
var re = new RegExp(siteRoot + 'library/' + repoID + '.*');
return re.test(url);
},
getPathFromInternalMarkdownLink: function(url, repoID) {
var re = new RegExp(siteRoot + 'lib/' + repoID + '/file' + '(.*\.md)');
var array = re.exec(url);
var path = decodeURIComponent(array[1]);
return path;
},
getPathFromInternalDirLink: function(url, repoID, repoName) {
var re = new RegExp(siteRoot + 'library/' + repoID + '/' + repoName + '(/.*)');
var array = re.exec(url);
var path = decodeURIComponent(array[1]);
return path;
},
compareTwoWord: function(wordA, wordB) {
// compare wordA and wordB at lower case
// if wordA >= wordB, return 1