mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 01:42:29 +03:00
4d54880113
fixes https://github.com/TryGhost/Team/issues/2200 When zipping a folder that contains files with UTF-8 characters in the filename, using the MacOS Archive Utility, the resulting zip will be missing some UTF-8 configuration bit. This breaks the unzipper, causing it to decode the filenames using the wrong encodign. When the file names are long, and become longer than the length allowed by the OS, an ENAMETOOLONG error is thrown. This error is not handled by the importer, and causes the import to fail. This adds a specific check for this error so we can show a clear error message to the user, that helps them to resolve the issue. We are currently unable to fix the issue on our side, because of a lack of well supported zip libraries for node.
109 lines
3.2 KiB
JavaScript
109 lines
3.2 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import ghostPaths from 'ghost-admin/utils/ghost-paths';
|
|
import {GENERIC_ERROR_MESSAGE} from 'ghost-admin/services/notifications';
|
|
import {computed} from '@ember/object';
|
|
import {getErrorCode} from '../services/ajax';
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
|
import {
|
|
isRequestEntityTooLargeError,
|
|
isUnsupportedMediaTypeError,
|
|
isVersionMismatchError
|
|
} from 'ghost-admin/services/ajax';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default ModalComponent.extend({
|
|
ajax: service(),
|
|
notifications: service(),
|
|
store: service(),
|
|
|
|
state: 'INIT',
|
|
|
|
file: null,
|
|
paramName: 'importfile',
|
|
importResponse: null,
|
|
errorMessage: null,
|
|
errorHeader: null,
|
|
showTryAgainButton: true,
|
|
|
|
// Allowed actions
|
|
confirm: () => {},
|
|
|
|
config: inject(),
|
|
|
|
uploadUrl: computed(function () {
|
|
return `${ghostPaths().apiRoot}/db`;
|
|
}),
|
|
|
|
formData: computed('file', function () {
|
|
let formData = new FormData();
|
|
formData.append(this.paramName, this.file);
|
|
return formData;
|
|
}),
|
|
|
|
actions: {
|
|
setFile(file) {
|
|
this.set('file', file);
|
|
this.generateRequest();
|
|
},
|
|
|
|
reset() {
|
|
this.set('errorMessage', null);
|
|
this.set('errorHeader', null);
|
|
this.set('file', null);
|
|
this.set('state', 'INIT');
|
|
this.set('showTryAgainButton', true);
|
|
},
|
|
|
|
closeModal() {
|
|
if (this.state !== 'UPLOADING') {
|
|
this._super(...arguments);
|
|
}
|
|
},
|
|
|
|
// noop - we don't want the enter key doing anything
|
|
confirm() {}
|
|
},
|
|
|
|
generateRequest() {
|
|
let ajax = this.ajax;
|
|
let formData = this.formData;
|
|
let url = this.uploadUrl;
|
|
|
|
this.set('state', 'UPLOADING');
|
|
ajax.post(url, {
|
|
data: formData,
|
|
processData: false,
|
|
contentType: false,
|
|
dataType: 'text'
|
|
}).then(() => {
|
|
this.set('state', 'PROCESSING');
|
|
}).catch((error) => {
|
|
this._uploadError(error);
|
|
this.set('state', 'ERROR');
|
|
});
|
|
},
|
|
|
|
_uploadError(error) {
|
|
let message;
|
|
let header = 'Import error';
|
|
|
|
if (isVersionMismatchError(error)) {
|
|
this.notifications.showAPIError(error);
|
|
}
|
|
|
|
if (getErrorCode(error) === 'INVALID_ZIP_FILE_NAME_ENCODING') {
|
|
message = 'The uploaded zip could not be read due to a long or invalid file name. Please remove any special characters from the file name, or alternatively try another archiving tool if using MacOS Archive Utility.';
|
|
} else if (isUnsupportedMediaTypeError(error)) {
|
|
message = 'The file type you uploaded is not supported.';
|
|
} else if (isRequestEntityTooLargeError(error)) {
|
|
message = 'The file you uploaded was larger than the maximum file size your server allows.';
|
|
} else {
|
|
console.error(error); // eslint-disable-line
|
|
message = GENERIC_ERROR_MESSAGE;
|
|
}
|
|
|
|
this.set('errorMessage', message);
|
|
this.set('errorHeader', header);
|
|
}
|
|
});
|