
const parsers = [
    require ('./filetype/sharp.js'),
    require ('./filetype/imagemagick.js'),
    require ('./filetype/meta.js')
];

module.exports.createThumbnail = async function(fileObj, w, h, quality) {
    for (let i of parsers)
    {
        let result = await i.createThumbnail(fileObj, w, h, quality, false);
        if (result)
            return result;
    }
    return null;
}

module.exports.createMeta = async function(fileObj) {
    let result = {};
    for (let i of parsers)
    {
        let data = await i.parse(fileObj, Object.assign({}, result));
        data.value && Object.assign(result, data.value);
        data.reason && console.error("Failed to parse file ", fileObj.path, data.reason);
    }
    for (let i of Object.keys(result))
        if (result[i] === undefined)
            delete result[i];
    delete result["exifParsed"];
    return result;
}

