function validateMetadata(file, data, { addSuffix = false } = {}) {
  const validLicenses = File.getValidLicenses();
  const errors = [],
    processedFields = [];
  // For multiple uploads, we use the filename as a suffix for each file
  const field = key => addSuffix ? `${key}-${file.originalname}` : key;
  const ownWork = Boolean(data[field('ownwork')]);

  const required = ownWork ?
    ['description', 'license', 'ownwork', 'language'].map(field) :
    ['description', 'creator', 'source', 'license', 'language'].map(field);

  // We ignore presence/content of these conflicting fields if they are "falsy",
  // otherwise we report an error
  const conditionallyIgnored = ownWork ?
    ['creator', 'source'].map(field) :
    ['ownwork'].map(field);

  errors.push(...checkRequired(data, required, conditionallyIgnored));
  processedFields.push(...required, ...conditionallyIgnored);

  const language = data[field('language')];

  if (language && !languages.isValid(language))
    errors.push(new Error(`Language ${language} is not valid or recognized.`));

  const license = data[field('license')];
  if (license && !validLicenses.includes(license))
    errors.push(new Error(`License ${license} is not one of: ` +
      validLicenses.join(', ')));

  return { errors, processedFields };
}
/**
 * Check that required metadata fields are present for a given upload. Also
 * ensures that language is valid, and that license is one of the accepted
 * licenses.
 *
 * @param {Object} file
 *  File received from the upload middleware
 * @param {Object} data
 *  Request data that should contain the metadata we need
 * @param {Object} [options]
 *  Validation options
 * @param {Boolean} options.addSuffix=false
 *  Add a filename suffix to each field (used for requests with multiple files)
 * @returns {Error[]}
 *  Validation errors for this field, if any
 * @memberof APIUploadHandler
 */
Check that required metadata fields are present for a given upload. Also
ensures that language is valid, and that license is one of the accepted
licenses.


Check that required metadata fields are present for a given upload . Also ensures that language is valid and that license is one of the accepted licenses .
function validateMetadata(file, data, { addSuffix = false } = {}) {
  const validLicenses = File.getValidLicenses();
  const errors = [],
    processedFields = [];
  const field = key => addSuffix ? `${key}-${file.originalname}` : key;
  const ownWork = Boolean(data[field('ownwork')]);
  const required = ownWork ?
    ['description', 'license', 'ownwork', 'language'].map(field) :
    ['description', 'creator', 'source', 'license', 'language'].map(field);
  const conditionallyIgnored = ownWork ?
    ['creator', 'source'].map(field) :
    ['ownwork'].map(field);
  errors.push(...checkRequired(data, required, conditionallyIgnored));
  processedFields.push(...required, ...conditionallyIgnored);
  const language = data[field('language')];
  if (language && !languages.isValid(language))
    errors.push(new Error(`Language ${language} is not valid or recognized.`));
  const license = data[field('license')];
  if (license && !validLicenses.includes(license))
    errors.push(new Error(`License ${license} is not one of: ` +
      validLicenses.join(', ')));
  return { errors, processedFields };
}
function validateMetadata ( file , data , { addSuffix = false } = { } ) { const validLicenses = File . getValidLicenses ( ) ; const errors = [ ] , processedFields = [ ] ; const field = key => addSuffix ? ` ${ key } ${ file . originalname } ` : key ; const ownWork = Boolean ( data [ field ( 'ownwork' ) ] ) ; const required = ownWork ? [ 'description' , 'license' , 'ownwork' , 'language' ] . map ( field ) : [ 'description' , 'creator' , 'source' , 'license' , 'language' ] . map ( field ) ; const conditionallyIgnored = ownWork ? [ 'creator' , 'source' ] . map ( field ) : [ 'ownwork' ] . map ( field ) ; errors . push ( ... checkRequired ( data , required , conditionallyIgnored ) ) ; processedFields . push ( ... required , ... conditionallyIgnored ) ; const language = data [ field ( 'language' ) ] ; if ( language && ! languages . isValid ( language ) ) errors . push ( new Error ( ` ${ language } ` ) ) ; const license = data [ field ( 'license' ) ] ; if ( license && ! validLicenses . includes ( license ) ) errors . push ( new Error ( ` ${ license } ` + validLicenses . join ( ', ' ) ) ) ; return { errors , processedFields } ; }
Check that required metadata fields are present for a given upload.
Check that required metadata fields are present for a given upload .
// For multiple uploads, we use the filename as a suffix for each file // We ignore presence/content of these conflicting fields if they are "falsy", // otherwise we report an error