|
|
@@ -9,7 +9,6 @@ import { EditorOptions, PreviewOptions } from './PageEditor/OptionsSelector';
|
|
|
import Editor from './PageEditor/Editor';
|
|
|
import Preview from './PageEditor/Preview';
|
|
|
import scrollSyncHelper from './PageEditor/ScrollSyncHelper';
|
|
|
-import { promise } from 'when';
|
|
|
import * as toastr from 'toastr';
|
|
|
|
|
|
|
|
|
@@ -118,8 +117,8 @@ export default class PageEditor extends React.Component {
|
|
|
* @param {any} files
|
|
|
*/
|
|
|
async onUpload(file) {
|
|
|
- const res = await this.props.crowi.apiGet('/attachments.limit', {_csrf: this.props.crowi.csrfToken});
|
|
|
- if (res.usableCapacity && file.size > res.usableCapacity) {
|
|
|
+ const res = await this.props.crowi.apiGet('/attachments.limit', {_csrf: this.props.crowi.csrfToken, fileSize: file.size});
|
|
|
+ if (!res.isUploadable) {
|
|
|
toastr.error(undefined, 'MongoDB for uploading files reaches limit', {
|
|
|
closeButton: true,
|
|
|
progressBar: true,
|
|
|
@@ -130,42 +129,40 @@ export default class PageEditor extends React.Component {
|
|
|
});
|
|
|
throw new Error('MongoDB for uploading files reaches limit');
|
|
|
}
|
|
|
- else {
|
|
|
- const endpoint = '/attachments.add';
|
|
|
-
|
|
|
- // create a FromData instance
|
|
|
- const formData = new FormData();
|
|
|
- formData.append('_csrf', this.props.crowi.csrfToken);
|
|
|
- formData.append('file', file);
|
|
|
- formData.append('path', this.props.pagePath);
|
|
|
- formData.append('page_id', this.state.pageId || 0);
|
|
|
-
|
|
|
- // post
|
|
|
- this.props.crowi.apiPost(endpoint, formData)
|
|
|
- .then((res) => {
|
|
|
- const url = res.url;
|
|
|
- const attachment = res.attachment;
|
|
|
- const fileName = attachment.originalName;
|
|
|
-
|
|
|
- let insertText = `[${fileName}](${url})`;
|
|
|
- // when image
|
|
|
- if (attachment.fileFormat.startsWith('image/')) {
|
|
|
- // modify to "" syntax
|
|
|
- insertText = '!' + insertText;
|
|
|
- }
|
|
|
- this.refs.editor.insertText(insertText);
|
|
|
-
|
|
|
- // when if created newly
|
|
|
- if (res.pageCreated) {
|
|
|
- // do nothing
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(this.apiErrorHandler)
|
|
|
- // finally
|
|
|
- .then(() => {
|
|
|
- this.refs.editor.terminateUploadingState();
|
|
|
- });
|
|
|
- }
|
|
|
+ const endpoint = '/attachments.add';
|
|
|
+
|
|
|
+ // create a FromData instance
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('_csrf', this.props.crowi.csrfToken);
|
|
|
+ formData.append('file', file);
|
|
|
+ formData.append('path', this.props.pagePath);
|
|
|
+ formData.append('page_id', this.state.pageId || 0);
|
|
|
+
|
|
|
+ // post
|
|
|
+ this.props.crowi.apiPost(endpoint, formData)
|
|
|
+ .then((res) => {
|
|
|
+ const url = res.url;
|
|
|
+ const attachment = res.attachment;
|
|
|
+ const fileName = attachment.originalName;
|
|
|
+
|
|
|
+ let insertText = `[${fileName}](${url})`;
|
|
|
+ // when image
|
|
|
+ if (attachment.fileFormat.startsWith('image/')) {
|
|
|
+ // modify to "" syntax
|
|
|
+ insertText = '!' + insertText;
|
|
|
+ }
|
|
|
+ this.refs.editor.insertText(insertText);
|
|
|
+
|
|
|
+ // when if created newly
|
|
|
+ if (res.pageCreated) {
|
|
|
+ // do nothing
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(this.apiErrorHandler)
|
|
|
+ // finally
|
|
|
+ .then(() => {
|
|
|
+ this.refs.editor.terminateUploadingState();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|