1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-13 05:39:59 +00:00

optimize code

This commit is contained in:
shanshuirenjia
2021-04-19 17:23:26 +08:00
parent 25cb838d12
commit 03222a9fef
3 changed files with 21 additions and 23 deletions

View File

@@ -27,7 +27,7 @@ const propTypes = {
fileTypeErrorCallback: PropTypes.func, fileTypeErrorCallback: PropTypes.func,
dragAndDrop: PropTypes.bool.isRequired, dragAndDrop: PropTypes.bool.isRequired,
path: PropTypes.string.isRequired, path: PropTypes.string.isRequired,
uploadUrlPath: PropTypes.string.isRequired, relativePath: PropTypes.string.isRequired,
onFileUploadSuccess: PropTypes.func.isRequired onFileUploadSuccess: PropTypes.func.isRequired
}; };
@@ -204,8 +204,8 @@ class FileUploader extends React.Component {
}); });
} else { } else {
this.setUploadFileList(this.resumable.files); this.setUploadFileList(this.resumable.files);
let { token, uploadUrlPath } = this.props; let { token, relativePath } = this.props;
seafileAPI.sharedLinkGetFileUploadUrl(token, uploadUrlPath).then(res => { seafileAPI.sharedLinkGetFileUploadUrl(token, relativePath).then(res => {
this.resumable.opts.target = res.data.upload_link + '?ret-json=1'; this.resumable.opts.target = res.data.upload_link + '?ret-json=1';
this.resumableUpload(resumableFile); this.resumableUpload(resumableFile);
}).catch(error => { }).catch(error => {
@@ -217,8 +217,8 @@ class FileUploader extends React.Component {
this.setUploadFileList(this.resumable.files); this.setUploadFileList(this.resumable.files);
if (!this.isUploadLinkLoaded) { if (!this.isUploadLinkLoaded) {
this.isUploadLinkLoaded = true; this.isUploadLinkLoaded = true;
let { token, uploadUrlPath } = this.props; let { token, relativePath } = this.props;
seafileAPI.sharedLinkGetFileUploadUrl(token, uploadUrlPath).then(res => { seafileAPI.sharedLinkGetFileUploadUrl(token, relativePath).then(res => {
this.resumable.opts.target = res.data.upload_link + '?ret-json=1'; this.resumable.opts.target = res.data.upload_link + '?ret-json=1';
this.resumable.upload(); this.resumable.upload();
}).catch(error => { }).catch(error => {
@@ -564,8 +564,8 @@ class FileUploader extends React.Component {
onUploadRetry = (resumableFile) => { onUploadRetry = (resumableFile) => {
let { token, uploadUrlPath } = this.props; let { token, relativePath } = this.props;
seafileAPI.sharedLinkGetFileUploadUrl(token, uploadUrlPath).then(res => { seafileAPI.sharedLinkGetFileUploadUrl(token, relativePath).then(res => {
this.resumable.opts.target = res.data.upload_link + '?ret-json=1'; this.resumable.opts.target = res.data.upload_link + '?ret-json=1';
let retryFileList = this.state.retryFileList.filter(item => { let retryFileList = this.state.retryFileList.filter(item => {
@@ -591,8 +591,8 @@ class FileUploader extends React.Component {
onUploadRetryAll = () => { onUploadRetryAll = () => {
let { token, uploadUrlPath } = this.props; let { token, relativePath } = this.props;
seafileAPI.sharedLinkGetFileUploadUrl(token, uploadUrlPath).then(res => { seafileAPI.sharedLinkGetFileUploadUrl(token, relativePath).then(res => {
this.resumable.opts.target = res.data.upload_link + '?ret-json=1'; this.resumable.opts.target = res.data.upload_link + '?ret-json=1';
this.state.retryFileList.forEach(item => { this.state.retryFileList.forEach(item => {
item.error = false; item.error = false;
@@ -645,8 +645,8 @@ class FileUploader extends React.Component {
uploadFile = () => { uploadFile = () => {
let resumableFile = this.resumable.files[this.resumable.files.length - 1]; let resumableFile = this.resumable.files[this.resumable.files.length - 1];
let { token, uploadUrlPath } = this.props; let { token, relativePath } = this.props;
seafileAPI.sharedLinkGetFileUploadUrl(token, uploadUrlPath).then(res => { seafileAPI.sharedLinkGetFileUploadUrl(token, relativePath).then(res => {
this.resumable.opts.target = res.data.upload_link + '?ret-json=1'; this.resumable.opts.target = res.data.upload_link + '?ret-json=1';
this.setState({ this.setState({
isUploadRemindDialogShow: false, isUploadRemindDialogShow: false,

View File

@@ -21,14 +21,12 @@ moment.locale(window.app.config.lang);
let loginUser = window.app.pageOptions.name; let loginUser = window.app.pageOptions.name;
let { let {
token, dirName, dirPath, sharedBy, token, dirName, dirPath, sharedBy,
repoID, path, repoID, relativePath,
mode, thumbnailSize, zipped, mode, thumbnailSize, zipped,
trafficOverLimit, canDownload, trafficOverLimit, canDownload,
noQuota, canUpload noQuota, canUpload
} = window.shared.pageOptions; } = window.shared.pageOptions;
dirPath = dirPath.replace(/\/+$/, ""); // used for upload file
const uploadUrlPath = path.replace(/\/+$/, ""); // used for get dir upload link
const showDownloadIcon = !trafficOverLimit && canDownload; const showDownloadIcon = !trafficOverLimit && canDownload;
class SharedDirView extends React.Component { class SharedDirView extends React.Component {
@@ -62,7 +60,7 @@ class SharedDirView extends React.Component {
}); });
} }
seafileAPI.listSharedDir(token, path, thumbnailSize).then((res) => { seafileAPI.listSharedDir(token, relativePath, thumbnailSize).then((res) => {
const items = res.data['dirent_list'].map(item => { const items = res.data['dirent_list'].map(item => {
item.isSelected = false; item.isSelected = false;
return item; return item;
@@ -149,7 +147,7 @@ class SharedDirView extends React.Component {
zipDownloadSelectedItems = () => { zipDownloadSelectedItems = () => {
this.setState({ this.setState({
isZipDialogOpen: true, isZipDialogOpen: true,
zipFolderPath: path, zipFolderPath: relativePath,
selectedItems: this.state.items.filter(item => item.isSelected) selectedItems: this.state.items.filter(item => item.isSelected)
.map(item => item.file_name || item.folder_name) .map(item => item.file_name || item.folder_name)
}); });
@@ -254,7 +252,7 @@ class SharedDirView extends React.Component {
const newItem = { const newItem = {
isSelected: false, isSelected: false,
file_name: name, file_name: name,
file_path: Utils.joinPath(path, name), file_path: Utils.joinPath(relativePath, name),
is_dir: false, is_dir: false,
last_modified: moment().format(), last_modified: moment().format(),
size: size size: size
@@ -288,8 +286,8 @@ class SharedDirView extends React.Component {
<div> <div>
{isDesktop && {isDesktop &&
<div className="view-mode btn-group"> <div className="view-mode btn-group">
<a href={`?p=${encodeURIComponent(path)}&mode=list`} className={`${modeBaseClass} sf2-icon-list-view ${mode == 'list' ? 'current-mode' : ''}`} title={gettext('List')}></a> <a href={`?p=${encodeURIComponent(relativePath)}&mode=list`} className={`${modeBaseClass} sf2-icon-list-view ${mode == 'list' ? 'current-mode' : ''}`} title={gettext('List')}></a>
<a href={`?p=${encodeURIComponent(path)}&mode=grid`} className={`${modeBaseClass} sf2-icon-grid-view ${mode == 'grid' ? 'current-mode' : ''}`} title={gettext('Grid')}></a> <a href={`?p=${encodeURIComponent(relativePath)}&mode=grid`} className={`${modeBaseClass} sf2-icon-grid-view ${mode == 'grid' ? 'current-mode' : ''}`} title={gettext('Grid')}></a>
</div> </div>
} }
{canUpload && ( {canUpload && (
@@ -301,7 +299,7 @@ class SharedDirView extends React.Component {
<Fragment> <Fragment>
{this.state.items.some(item => item.isSelected) ? {this.state.items.some(item => item.isSelected) ?
<Button color="success" onClick={this.zipDownloadSelectedItems} className="ml-2 shared-dir-op-btn">{gettext('ZIP Selected Items')}</Button> : <Button color="success" onClick={this.zipDownloadSelectedItems} className="ml-2 shared-dir-op-btn">{gettext('ZIP Selected Items')}</Button> :
<Button color="success" onClick={this.zipDownloadFolder.bind(this, path)} className="ml-2 shared-dir-op-btn">{gettext('ZIP')}</Button> <Button color="success" onClick={this.zipDownloadFolder.bind(this, relativePath)} className="ml-2 shared-dir-op-btn">{gettext('ZIP')}</Button>
} }
</Fragment> </Fragment>
} }
@@ -312,8 +310,8 @@ class SharedDirView extends React.Component {
ref={uploader => this.uploader = uploader} ref={uploader => this.uploader = uploader}
dragAndDrop={false} dragAndDrop={false}
token={token} token={token}
path={dirPath} path={dirPath.replace(/\/+$/, "")}
uploadUrlPath={uploadUrlPath} relativePath={relativePath.replace(/\/+$/, "")}
repoID={repoID} repoID={repoID}
onFileUploadSuccess={this.onFileUploadSuccess} onFileUploadSuccess={this.onFileUploadSuccess}
/> />

View File

@@ -23,7 +23,7 @@
dirPath: '{{ dir_path|escapejs }}', dirPath: '{{ dir_path|escapejs }}',
sharedBy: '{{ username|email2nickname|escapejs }}', sharedBy: '{{ username|email2nickname|escapejs }}',
repoID: '{{repo.id}}', repoID: '{{repo.id}}',
path: '{{ path|escapejs }}', relativePath: '{{ path|escapejs }}',
zipped: (function() { zipped: (function() {
var list = []; var list = [];
{% for name, path in zipped %} {% for name, path in zipped %}