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:
parent
caac055bdc
commit
bf215be0f8
@ -11,7 +11,7 @@ const debug = require('@tryghost/debug')('import-manager');
|
|||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const ImageHandler = require('./handlers/image');
|
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 RevueHandler = require('./handlers/revue');
|
||||||
const JSONHandler = require('./handlers/json');
|
const JSONHandler = require('./handlers/json');
|
||||||
const MarkdownHandler = require('./handlers/markdown');
|
const MarkdownHandler = require('./handlers/markdown');
|
||||||
|
@ -88,7 +88,7 @@
|
|||||||
"@tryghost/html-to-plaintext": "0.0.0",
|
"@tryghost/html-to-plaintext": "0.0.0",
|
||||||
"@tryghost/http-cache-utils": "0.1.7",
|
"@tryghost/http-cache-utils": "0.1.7",
|
||||||
"@tryghost/image-transform": "1.2.3",
|
"@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/importer-revue": "0.0.0",
|
||||||
"@tryghost/job-manager": "0.0.0",
|
"@tryghost/job-manager": "0.0.0",
|
||||||
"@tryghost/kg-card-factory": "4.0.4",
|
"@tryghost/kg-card-factory": "4.0.4",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Importer Media
|
# Importer Media
|
||||||
|
|
||||||
Media content importer
|
Importer content file handler
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
1
ghost/importer-handler-content-files/index.js
Normal file
1
ghost/importer-handler-content-files/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./lib/ImporterContentFileHandler');
|
@ -1,7 +1,7 @@
|
|||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
class ImporterMediaHandler {
|
class ImporterContentFileHandler {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Object} deps dependencies
|
* @param {Object} deps dependencies
|
||||||
@ -69,4 +69,4 @@ class ImporterMediaHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ImporterMediaHandler;
|
module.exports = ImporterContentFileHandler;
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@tryghost/importer-handler-media",
|
"name": "@tryghost/importer-handler-content-files",
|
||||||
"version": "0.0.0",
|
"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",
|
"author": "Ghost Foundation",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "index.js",
|
"main": "index.js",
|
@ -1,21 +1,21 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const ImporterMedia = require('../index');
|
const ImporterContentFileHandler = require('../index');
|
||||||
|
|
||||||
describe('ImporterMediaHandler', function () {
|
describe('ImporterContentFileHandler', function () {
|
||||||
it('creates an instance', function () {
|
it('creates an instance', function () {
|
||||||
const mediaImporter = new ImporterMedia({
|
const contentFileImporter = new ImporterContentFileHandler({
|
||||||
storage: {},
|
storage: {},
|
||||||
config: {},
|
config: {},
|
||||||
urlUtils: {}
|
urlUtils: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.ok(mediaImporter);
|
assert.ok(contentFileImporter);
|
||||||
assert.equal(mediaImporter.type, 'media');
|
assert.equal(contentFileImporter.type, 'media');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns configured extensions', function () {
|
it('returns configured extensions', function () {
|
||||||
const mediaImporter = new ImporterMedia({
|
const contentFileImporter = new ImporterContentFileHandler({
|
||||||
storage: {},
|
storage: {},
|
||||||
config: {
|
config: {
|
||||||
get: () => ({
|
get: () => ({
|
||||||
@ -27,11 +27,11 @@ describe('ImporterMediaHandler', function () {
|
|||||||
urlUtils: {}
|
urlUtils: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.deepEqual(mediaImporter.extensions, ['mp4']);
|
assert.deepEqual(contentFileImporter.extensions, ['mp4']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns configured contentTypes', function () {
|
it('returns configured contentTypes', function () {
|
||||||
const mediaImporter = new ImporterMedia({
|
const contentFileImporter = new ImporterContentFileHandler({
|
||||||
storage: {},
|
storage: {},
|
||||||
config: {
|
config: {
|
||||||
get: () => ({
|
get: () => ({
|
||||||
@ -43,7 +43,7 @@ describe('ImporterMediaHandler', function () {
|
|||||||
urlUtils: {}
|
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
|
// @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
|
// from the image importer and the tests were adapted to the media importer
|
||||||
describe('loadFile', function () {
|
describe('loadFile', function () {
|
||||||
it('loads files and decorates them with newPath with subdirectory', async function () {
|
it('loads files and decorates them with newPath with subdirectory', async function () {
|
||||||
const mediaImporter = new ImporterMedia({
|
const contentFileImporter = new ImporterContentFileHandler({
|
||||||
storage: {
|
storage: {
|
||||||
staticFileURLPrefix: 'content/media',
|
staticFileURLPrefix: 'content/media',
|
||||||
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
|
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
|
||||||
@ -72,7 +72,7 @@ describe('ImporterMediaHandler', function () {
|
|||||||
}];
|
}];
|
||||||
const subDir = 'blog';
|
const subDir = 'blog';
|
||||||
|
|
||||||
await mediaImporter.loadFile(files, subDir);
|
await contentFileImporter.loadFile(files, subDir);
|
||||||
|
|
||||||
assert.equal(files[0].name, '1.mp4');
|
assert.equal(files[0].name, '1.mp4');
|
||||||
assert.equal(files[0].originalPath, 'content/media/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 () {
|
it('loads files and decorates them with newPath with NO subdirectory', async function () {
|
||||||
const mediaImporter = new ImporterMedia({
|
const contentFileImporter = new ImporterContentFileHandler({
|
||||||
storage: {
|
storage: {
|
||||||
staticFileURLPrefix: 'content/media',
|
staticFileURLPrefix: 'content/media',
|
||||||
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
|
getUniqueFileName: (file, targetDir) => Promise.resolve(targetDir + '/' + file.name)
|
||||||
@ -101,7 +101,7 @@ describe('ImporterMediaHandler', function () {
|
|||||||
name: 'content/media/1.mp4'
|
name: 'content/media/1.mp4'
|
||||||
}];
|
}];
|
||||||
|
|
||||||
await mediaImporter.loadFile(files);
|
await contentFileImporter.loadFile(files);
|
||||||
|
|
||||||
assert.equal(files[0].name, '1.mp4');
|
assert.equal(files[0].name, '1.mp4');
|
||||||
assert.equal(files[0].originalPath, 'content/media/1.mp4');
|
assert.equal(files[0].originalPath, 'content/media/1.mp4');
|
@ -1 +0,0 @@
|
|||||||
module.exports = require('./lib/ImporterMediaHandler');
|
|
Loading…
Reference in New Issue
Block a user