mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-16 22:17:59 +00:00
optimize code
This commit is contained in:
parent
ff61c885fb
commit
d2a54afdba
6
frontend/package-lock.json
generated
6
frontend/package-lock.json
generated
@ -16854,9 +16854,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"seafile-js": {
|
"seafile-js": {
|
||||||
"version": "0.2.169",
|
"version": "0.2.170",
|
||||||
"resolved": "https://registry.npmjs.org/seafile-js/-/seafile-js-0.2.169.tgz",
|
"resolved": "https://registry.npmjs.org/seafile-js/-/seafile-js-0.2.170.tgz",
|
||||||
"integrity": "sha512-wi0ERmE29zatCyYSvHGrHEZlMvz87AKS+vr6+NQ29ewl9fL4uzlISC8+9GeFcgUvBD01E96MvW0j5tUBAbEKRw==",
|
"integrity": "sha512-V0u0wcdnmkiD4OV6O4b8hBJ6rOF/2mvcKlfOStJmx2ABDYGZquB9BxFHVw5thy4IUx4rl6AgQ2JAX30+i3qDsA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@babel/polyfill": "7.12.1",
|
"@babel/polyfill": "7.12.1",
|
||||||
"axios": "0.21.1",
|
"axios": "0.21.1",
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
"react-responsive": "^6.1.2",
|
"react-responsive": "^6.1.2",
|
||||||
"react-select": "^2.4.1",
|
"react-select": "^2.4.1",
|
||||||
"reactstrap": "^6.4.0",
|
"reactstrap": "^6.4.0",
|
||||||
"seafile-js": "0.2.169",
|
"seafile-js": "0.2.170",
|
||||||
"socket.io-client": "^2.2.0",
|
"socket.io-client": "^2.2.0",
|
||||||
"unified": "^7.0.0",
|
"unified": "^7.0.0",
|
||||||
"url-parse": "^1.4.3",
|
"url-parse": "^1.4.3",
|
||||||
|
@ -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,
|
||||||
|
@ -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
|
||||||
@ -287,8 +285,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 && (
|
||||||
@ -300,7 +298,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>
|
||||||
}
|
}
|
||||||
@ -311,8 +309,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}
|
||||||
/>
|
/>
|
||||||
|
@ -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 %}
|
||||||
|
Loading…
Reference in New Issue
Block a user