Renamed media import handler to file handler

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

- We need to process generic files like .pdf, .md, etc. on the importer "handler" stage.
- The media handler can process more than just media files after few refactorings. Renaming it to a generic content file handler indicates it can process any type of content file.
- In future we can substitute the built-in "images" import handler with this generic content file handler.
This commit is contained in:
Naz 2023-03-02 15:05:22 +08:00
parent caac055bdc
commit bf215be0f8
No known key found for this signature in database
10 changed files with 21 additions and 21 deletions

View File

@ -11,7 +11,7 @@ const debug = require('@tryghost/debug')('import-manager');
const logging = require('@tryghost/logging');
const errors = require('@tryghost/errors');
const ImageHandler = require('./handlers/image');
const MediaHandler = require('@tryghost/importer-handler-media');
const MediaHandler = require('@tryghost/importer-handler-content-files');
const RevueHandler = require('./handlers/revue');
const JSONHandler = require('./handlers/json');
const MarkdownHandler = require('./handlers/markdown');

View File

@ -88,7 +88,7 @@
"@tryghost/html-to-plaintext": "0.0.0",
"@tryghost/http-cache-utils": "0.1.7",
"@tryghost/image-transform": "1.2.3",
"@tryghost/importer-handler-media": "0.0.0",
"@tryghost/importer-handler-content-files": "0.0.0",
"@tryghost/importer-revue": "0.0.0",
"@tryghost/job-manager": "0.0.0",
"@tryghost/kg-card-factory": "4.0.4",

View File

@ -1,6 +1,6 @@
# Importer Media
Media content importer
Importer content file handler
## Usage

View File

@ -0,0 +1 @@
module.exports = require('./lib/ImporterContentFileHandler');

View File

@ -1,7 +1,7 @@
const _ = require('lodash');
const path = require('path');
class ImporterMediaHandler {
class ImporterContentFileHandler {
/**
*
* @param {Object} deps dependencies
@ -69,4 +69,4 @@ class ImporterMediaHandler {
}
}
module.exports = ImporterMediaHandler;
module.exports = ImporterContentFileHandler;

View File

@ -1,7 +1,7 @@
{
"name": "@tryghost/importer-handler-media",
"name": "@tryghost/importer-handler-content-files",
"version": "0.0.0",
"repository": "https://github.com/TryGhost/Ghost/tree/main/packages/importer-handler-media",
"repository": "https://github.com/TryGhost/Ghost/tree/main/packages/importer-handler-content-files",
"author": "Ghost Foundation",
"private": true,
"main": "index.js",

View File

@ -1,21 +1,21 @@
const assert = require('assert');
const sinon = require('sinon');
const ImporterMedia = require('../index');
const ImporterContentFileHandler = require('../index');
describe('ImporterMediaHandler', function () {
describe('ImporterContentFileHandler', function () {
it('creates an instance', function () {
const mediaImporter = new ImporterMedia({
const contentFileImporter = new ImporterContentFileHandler({
storage: {},
config: {},
urlUtils: {}
});
assert.ok(mediaImporter);
assert.equal(mediaImporter.type, 'media');
assert.ok(contentFileImporter);
assert.equal(contentFileImporter.type, 'media');
});
it('returns configured extensions', function () {
const mediaImporter = new ImporterMedia({
const contentFileImporter = new ImporterContentFileHandler({
storage: {},
config: {
get: () => ({
@ -27,11 +27,11 @@ describe('ImporterMediaHandler', function () {
urlUtils: {}
});
assert.deepEqual(mediaImporter.extensions, ['mp4']);
assert.deepEqual(contentFileImporter.extensions, ['mp4']);
});
it('returns configured contentTypes', function () {
const mediaImporter = new ImporterMedia({
const contentFileImporter = new ImporterContentFileHandler({
storage: {},
config: {
get: () => ({
@ -43,7 +43,7 @@ describe('ImporterMediaHandler', function () {
urlUtils: {}
});
assert.deepEqual(mediaImporter.contentTypes, ['video/mp4']);
assert.deepEqual(contentFileImporter.contentTypes, ['video/mp4']);
});
// @NOTE: below tests need more work, they are just covering the basics
@ -51,7 +51,7 @@ describe('ImporterMediaHandler', function () {
// from the image importer and the tests were adapted to the media importer
describe('loadFile', function () {
it('loads files and decorates them with newPath with subdirectory', async function () {
const mediaImporter = new ImporterMedia({
const contentFileImporter = new ImporterContentFileHandler({
storage: {
staticFileURLPrefix: 'content/media',
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
@ -72,7 +72,7 @@ describe('ImporterMediaHandler', function () {
}];
const subDir = 'blog';
await mediaImporter.loadFile(files, subDir);
await contentFileImporter.loadFile(files, subDir);
assert.equal(files[0].name, '1.mp4');
assert.equal(files[0].originalPath, 'content/media/1.mp4');
@ -81,7 +81,7 @@ describe('ImporterMediaHandler', function () {
});
it('loads files and decorates them with newPath with NO subdirectory', async function () {
const mediaImporter = new ImporterMedia({
const contentFileImporter = new ImporterContentFileHandler({
storage: {
staticFileURLPrefix: 'content/media',
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
@ -101,7 +101,7 @@ describe('ImporterMediaHandler', function () {
name: 'content/media/1.mp4'
}];
await mediaImporter.loadFile(files);
await contentFileImporter.loadFile(files);
assert.equal(files[0].name, '1.mp4');
assert.equal(files[0].originalPath, 'content/media/1.mp4');

View File

@ -1 +0,0 @@
module.exports = require('./lib/ImporterMediaHandler');