Fixed root zip image/media/files copying during import

https://github.com/TryGhost/Toolbox/issues/523

- During import process of content files the files from the root directory were also copied over. This is causing chaos in the root of content folder with files that only needed for data import. For example, the csv files needed for Revue import were also copied over by "file importer" even though those do not belong to any content.
- Any content import files - images, media, files, should be in according folders in the imported zip file. The root files in the base zip directory are for data-related imports
This commit is contained in:
Naz 2023-03-08 11:03:34 +08:00
parent ec869cfa0d
commit 831a76505c
No known key found for this signature in database
4 changed files with 21 additions and 6 deletions

View File

@ -301,7 +301,14 @@ class ImportManager {
const baseDir = this.getBaseDirectory(zipDirectory);
for (const handler of this.handlers) {
const files = this.getFilesFromZip(handler, zipDirectory);
let files = [];
if (handler.directories?.length > 0) {
for (const dir of handler.directories) {
files.push(...this.getFilesFromZip(handler, path.join(zipDirectory, (baseDir || ''), dir)));
}
} else {
files.push(...this.getFilesFromZip(handler, zipDirectory));
}
debug('handler', handler.type, files);

View File

@ -228,7 +228,7 @@ describe('Importer', function () {
extractSpy.calledOnce.should.be.true();
validSpy.calledOnce.should.be.true();
baseDirSpy.calledOnce.should.be.true();
getFileSpy.callCount.should.eql(6);
getFileSpy.callCount.should.eql(9);
jsonSpy.calledOnce.should.be.true();
imageSpy.called.should.be.false();
mdSpy.called.should.be.false();

View File

@ -52,16 +52,24 @@ describe('ImporterContentFileHandler', function () {
});
const files = [{
name: 'content/media/1.mp4'
name: 'content/media/video-in-content-media.mp4'
}, {
name: 'media/video-in-media.mp4'
}];
const subDir = 'blog';
await contentFileImporter.loadFile(files, subDir);
assert.equal(files[0].name, '1.mp4');
assert.equal(files[0].originalPath, 'content/media/1.mp4');
assert.equal(files.length, 2);
assert.equal(files[0].name, 'video-in-content-media.mp4');
assert.equal(files[0].originalPath, 'content/media/video-in-content-media.mp4');
assert.equal(files[0].targetDir, '/var/www/ghost/content/media');
assert.equal(files[0].newPath, '//blog/content/media/1.mp4');
assert.equal(files[0].newPath, '//blog/content/media/video-in-content-media.mp4');
assert.equal(files[1].name, 'video-in-media.mp4');
assert.equal(files[1].originalPath, 'media/video-in-media.mp4');
assert.equal(files[1].targetDir, '/var/www/ghost/content/media');
assert.equal(files[1].newPath, '//blog/content/media/video-in-media.mp4');
});
it('loads files and decorates them with newPath with NO subdirectory', async function () {