2018-10-09 10:56:59 +08:00
|
|
|
import {siteRoot, historyRepoID, fileServerRoot } from './constants';
|
|
|
|
import { Utils } from './utils';
|
2018-09-12 17:01:48 +08:00
|
|
|
class URLDecorator {
|
|
|
|
|
|
|
|
static getUrl(options) {
|
|
|
|
let url = '';
|
|
|
|
let params = '';
|
|
|
|
switch (options.type) {
|
2019-01-31 17:37:02 +08:00
|
|
|
case 'download_historic_file':
|
|
|
|
params = 'p=' + options.filePath;
|
|
|
|
url = siteRoot + 'repo/' + historyRepoID + '/' + options.objID + '/download?' + params;
|
|
|
|
break;
|
|
|
|
case 'download_dir_zip_url':
|
|
|
|
url = fileServerRoot + 'zip/' + options.token;
|
|
|
|
break;
|
|
|
|
case 'download_file_url':
|
|
|
|
url = siteRoot + 'lib/' + options.repoID + '/file' + Utils.encodePath(options.filePath) + '?dl=1';
|
|
|
|
break;
|
|
|
|
case 'file_revisions':
|
|
|
|
params = 'p=' + Utils.encodePath(options.filePath) + '&referer=' + Utils.encodePath(options.referer);
|
|
|
|
url = siteRoot + 'repo/file_revisions/' + options.repoID + '/?' + params;
|
|
|
|
break;
|
|
|
|
case 'open_via_client':
|
|
|
|
url = 'seafile://openfile?repo_id=' + options.repoID + '&path=' + Utils.encodePath(options.filePath);
|
|
|
|
break;
|
|
|
|
case 'draft_view':
|
|
|
|
url = siteRoot + 'lib/' + options.repoID + '/file' + options.filePath + '?mode=edit&draft_id=' + options.draftId;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
url = '';
|
|
|
|
break;
|
2018-09-12 17:01:48 +08:00
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default URLDecorator;
|