@sugarcube/plugin-tika
Version:
Parse files and metadata using Tika.
40 lines (29 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _fp = require("lodash/fp");
var _dashp = require("dashp");
var _core = require("@sugarcube/core");
var _utils = require("../utils");
const querySource = "tika_location_field";
const plugin = (envelope, {
log
}) => {
const fields = _core.envelope.queriesByType(querySource, envelope);
return _core.envelope.fmapDataAsync(unit => (0, _dashp.foldP)((memo, field) => {
const value = (0, _fp.get)(field, unit);
if (!value) {
log.debug(`There is no value for ${field} on the unit.`);
return memo;
}
return (0, _dashp.flowP)([(0, _dashp.tapP)(url => log.debug(`Parse ${field}: ${url}.`)), _utils.safeExtract, ([text, meta]) => (0, _fp.merge)(memo, {
[`${field}_text`]: text,
[`${field}_meta`]: meta
})], value);
}, unit, fields), envelope);
};
plugin.desc = "Extract the data and meta data from a given location.";
var _default = plugin;
exports.default = _default;