Skip to content

Commit

Permalink
rebase and optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
JoinTyang committed Aug 26, 2024
1 parent bf02cb5 commit 7a16d82
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const propTypes = {
loadDirentList: PropTypes.func.isRequired,
};

class UploadSdocDialog extends React.Component {
class ImportSdocDialog extends React.Component {
constructor(props) {
super(props);
this.state = {
Expand Down Expand Up @@ -48,9 +48,9 @@ class UploadSdocDialog extends React.Component {
}
// check file extension
let fileName = this.fileInputRef.current.files[0].name;
if (fileName.substr(fileName.lastIndexOf('.') + 1) != 'zsdoc') {
if (fileName.substr(fileName.lastIndexOf('.') + 1) != 'sdoczip') {
this.setState({
errorMsg: gettext('Please choose a .zsdoc file.')
errorMsg: gettext('Please choose a .zip file.')
});
return;
}
Expand All @@ -77,6 +77,6 @@ class UploadSdocDialog extends React.Component {
}
}

UploadSdocDialog.propTypes = propTypes;
ImportSdocDialog.propTypes = propTypes;

export default UploadSdocDialog;
export default ImportSdocDialog;
20 changes: 10 additions & 10 deletions frontend/src/components/toolbar/dir-operation-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ModalPortal from '../modal-portal';
import CreateFolder from '../../components/dialog/create-folder-dialog';
import CreateFile from '../../components/dialog/create-file-dialog';
import ShareDialog from '../../components/dialog/share-dialog';
import UploadSdocDialog from '../dialog/upload-sdoc-dialog';
import ImportSdocDialog from '../dialog/import-sdoc-dialog';

const propTypes = {
path: PropTypes.string.isRequired,
Expand Down Expand Up @@ -40,7 +40,7 @@ class DirOperationToolbar extends React.Component {
isDesktopMenuOpen: false,
isSubMenuShown: false,
isMobileOpMenuOpen: false,
isUploadSdocDialogOpen: false,
isImportSdocDialogOpen: false,
};
}

Expand Down Expand Up @@ -159,8 +159,8 @@ class DirOperationToolbar extends React.Component {
}
};

onToggleUploadSdoc = () => {
this.setState({ isUploadSdocDialogOpen: !this.state.isUploadSdocDialogOpen });
onToggleImportSdoc = () => {
this.setState({ isImportSdocDialogOpen: !this.state.isImportSdocDialogOpen });
};

render() {
Expand Down Expand Up @@ -193,9 +193,9 @@ class DirOperationToolbar extends React.Component {
'text': gettext('Upload Folder'),
'onClick': this.onUploadFolder
}, {
'icon': 'upload-sdoc',
'text': gettext('Upload Sdoc'),
'onClick': this.onToggleUploadSdoc
'icon': 'import-sdoc',
'text': gettext('Import Sdoc'),
'onClick': this.onToggleImportSdoc
});
} else {
opList.push({
Expand Down Expand Up @@ -366,9 +366,9 @@ class DirOperationToolbar extends React.Component {
/>
</ModalPortal>
}
{this.state.isUploadSdocDialogOpen &&
<UploadSdocDialog
toggle={this.onToggleUploadSdoc}
{this.state.isImportSdocDialogOpen &&
<ImportSdocDialog
toggle={this.onToggleImportSdoc}
repoID={this.props.repoID}
itemPath={this.props.path}
loadDirentList={this.props.loadDirentList}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/text-translation.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const TextTranslation = {
},
'EXPORT_SDOC': {
key: 'Export sdoc',
value: gettext('Export sdoc')
value: gettext('Export as zip')
},
};

Expand Down
9 changes: 5 additions & 4 deletions seahub/api2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
ENABLE_RESET_ENCRYPTED_REPO_PASSWORD, SHARE_LINK_EXPIRE_DAYS_MAX, \
SHARE_LINK_EXPIRE_DAYS_MIN, SHARE_LINK_EXPIRE_DAYS_DEFAULT
from seahub.subscription.utils import subscription_check
from seahub.seadoc.utils import get_seadoc_file_uuid, gen_seadoc_image_parent_path, get_seadoc_asset_upload_link
from seahub.seadoc.utils import get_seadoc_file_uuid, gen_seadoc_image_parent_path, get_seadoc_asset_upload_link, ZSDOC

try:
from seahub.settings import CLOUD_MODE
Expand Down Expand Up @@ -2085,7 +2085,7 @@ def post(self, request, repo_id):
uploaded_temp_path = file.temporary_file_path()
extension = filename.split('.')[-1].lower()

if not (extension == 'zsdoc' and is_zipfile(uploaded_temp_path)):
if not (extension == 'sdoczip' and is_zipfile(uploaded_temp_path)):
error_msg = 'file format not supported.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

Expand Down Expand Up @@ -2136,7 +2136,7 @@ def post(self, request, repo_id):
logger.error(e)
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, 'Internal Server Error')

sdoc_file_name = filename.replace('zsdoc', 'sdoc')
sdoc_file_name = filename.replace(ZSDOC, 'sdoc')
new_file_path = os.path.join(parent_dir, relative_path, sdoc_file_name)

data = {'parent_dir': parent_dir, 'target_file': new_file_path, 'relative_path': relative_path}
Expand All @@ -2158,7 +2158,8 @@ def post(self, request, repo_id):

# upload sdoc images
image_dir = os.path.join(tmp_extracted_path, 'images/')
batch_upload_sdoc_images(doc_uuid, repo_id, username, image_dir)
if os.path.exists(image_dir):
batch_upload_sdoc_images(doc_uuid, repo_id, username, image_dir)

# remove tmp file
if os.path.exists(tmp_extracted_path):
Expand Down
4 changes: 2 additions & 2 deletions seahub/seadoc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

logger = logging.getLogger(__name__)

ZSDOC = 'zsdoc'
ZSDOC = 'sdoczip'


def uuid_str_to_32_chars(file_uuid):
Expand Down Expand Up @@ -138,7 +138,7 @@ def get_seadoc_download_link(uuid_map, is_inner=False):
repo_id, obj_id, 'view', '', use_onetime=False)
if not token:
return None

if is_inner:
download_link = gen_inner_file_get_url(token, filename)
else:
Expand Down

0 comments on commit 7a16d82

Please sign in to comment.