From 49553e59424e61ddd5be7926400561b6258340ea Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 2 Mar 2023 11:44:27 +0800 Subject: [PATCH] Renamed "image" importer to generic ContentFileImporter refs https://github.com/TryGhost/Toolbox/issues/523 - This is ground work before introducing a "media" content type importer - Previous "image" file name was not describing well what the importer was capable of doing --- ghost/core/core/server/data/importer/import-manager.js | 4 ++-- .../importers/{image.js => ContentFileImporter.js} | 6 +++--- .../unit/server/data/importer/importers/image.test.js | 10 +++++----- .../core/test/unit/server/data/importer/index.test.js | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) rename ghost/core/core/server/data/importer/importers/{image.js => ContentFileImporter.js} (95%) diff --git a/ghost/core/core/server/data/importer/import-manager.js b/ghost/core/core/server/data/importer/import-manager.js index 3cab7b4c9f..afb00c8080 100644 --- a/ghost/core/core/server/data/importer/import-manager.js +++ b/ghost/core/core/server/data/importer/import-manager.js @@ -15,7 +15,7 @@ const MediaHandler = require('@tryghost/importer-handler-media'); const RevueHandler = require('./handlers/revue'); const JSONHandler = require('./handlers/json'); const MarkdownHandler = require('./handlers/markdown'); -const ImageImporter = require('./importers/image'); +const ContentFileImporter = require('./importers/ContentFileImporter'); const RevueImporter = require('@tryghost/importer-revue'); const DataImporter = require('./importers/data'); const urlUtils = require('../../../shared/url-utils'); @@ -60,7 +60,7 @@ class ImportManager { storage: mediaStorage }); - const imageImporter = new ImageImporter({ + const imageImporter = new ContentFileImporter({ type: 'images', store: imageStorage }); diff --git a/ghost/core/core/server/data/importer/importers/image.js b/ghost/core/core/server/data/importer/importers/ContentFileImporter.js similarity index 95% rename from ghost/core/core/server/data/importer/importers/image.js rename to ghost/core/core/server/data/importer/importers/ContentFileImporter.js index 9f1bf0fb27..a690930dc0 100644 --- a/ghost/core/core/server/data/importer/importers/image.js +++ b/ghost/core/core/server/data/importer/importers/ContentFileImporter.js @@ -46,7 +46,7 @@ preProcessUsers = function (data, image) { }); }; -class ImageImporter { +class ContentFileImporter { /** @property {string} */ type; @@ -56,7 +56,7 @@ class ImageImporter { /** * * @param {Object} deps - * @param {string} deps.type - importer type + * @param {'images'} deps.type - importer type * @param {import('ghost-storage-base')} deps.store */ constructor(deps) { @@ -88,4 +88,4 @@ class ImageImporter { } } -module.exports = ImageImporter; +module.exports = ContentFileImporter; diff --git a/ghost/core/test/unit/server/data/importer/importers/image.test.js b/ghost/core/test/unit/server/data/importer/importers/image.test.js index 151eb87fd1..d0bb580205 100644 --- a/ghost/core/test/unit/server/data/importer/importers/image.test.js +++ b/ghost/core/test/unit/server/data/importer/importers/image.test.js @@ -1,12 +1,11 @@ const _ = require('lodash'); const sinon = require('sinon'); -const storage = require('../../../../../../core/server/adapters/storage'); -const ImageImporter = require('../../../../../../core/server/data/importer/importers/image'); +const ContentFileImporter = require('../../../../../../core/server/data/importer/importers/ContentFileImporter'); describe('ImageImporter', function () { it('has the correct interface', function () { - const imageImporter = new ImageImporter({ + const imageImporter = new ContentFileImporter({ type: 'images', store: {} }); @@ -17,7 +16,8 @@ describe('ImageImporter', function () { it('does preprocess posts, users and tags correctly', function () { let inputData = require('../../../../../utils/fixtures/import/import-data-1.json'); - const imageImporter = new ImageImporter({ + const imageImporter = new ContentFileImporter({ + type: 'images', store: {} }); let outputData = imageImporter.preProcess(_.cloneDeep(inputData)); @@ -52,7 +52,7 @@ describe('ImageImporter', function () { const storageApi = { save: sinon.stub().returns(Promise.resolve()) }; - const imageImporter = new ImageImporter({ + const imageImporter = new ContentFileImporter({ store: storageApi }); diff --git a/ghost/core/test/unit/server/data/importer/index.test.js b/ghost/core/test/unit/server/data/importer/index.test.js index 73ed616187..3ed7f657b1 100644 --- a/ghost/core/test/unit/server/data/importer/index.test.js +++ b/ghost/core/test/unit/server/data/importer/index.test.js @@ -16,7 +16,6 @@ let ImageHandler = rewire('../../../../../core/server/data/importer/handlers/ima const MarkdownHandler = require('../../../../../core/server/data/importer/handlers/markdown'); const RevueHandler = require('../../../../../core/server/data/importer/handlers/revue'); const DataImporter = require('../../../../../core/server/data/importer/importers/data'); -const ImageImporter = require('../../../../../core/server/data/importer/importers/image'); const RevueImporter = require('@tryghost/importer-revue'); const configUtils = require('../../../../utils/configUtils'); const logging = require('@tryghost/logging');