Reverted zip's root file copying fix

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

- The reverted fix did not take into account the "original path" of the
files would be truncated. This path has to be full relative to the root
of the zip to later be used during importer url substitution logic.
- This reverts commit 831a76505c.
This commit is contained in:
Naz 2023-03-16 21:52:24 +01:00
parent dda1d7cf26
commit c487b12518
4 changed files with 6 additions and 21 deletions

View File

@ -301,14 +301,7 @@ class ImportManager {
const baseDir = this.getBaseDirectory(zipDirectory); const baseDir = this.getBaseDirectory(zipDirectory);
for (const handler of this.handlers) { for (const handler of this.handlers) {
let files = []; const files = this.getFilesFromZip(handler, zipDirectory);
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); debug('handler', handler.type, files);

View File

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

View File

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