async parseRekogImageOutput()

in source/analysis-monitor/lib/indexer/index.js [177:234]


  async parseRekogImageOutput(type, key) {
    if (!key) {
      return undefined;
    }

    let name;
    let sub;
    let sub02;
    switch (type) {
      case 'celeb':
        name = 'CelebrityFaces';
        sub = 'Name';
        break;
      case 'faceMatch':
        name = 'FaceMatches';
        sub = 'Face';
        sub02 = 'ExternalImageId';
        break;
      case 'label':
        name = 'Labels';
        sub = 'Name';
        break;
      case 'moderation':
        name = 'ModerationLabels';
        sub = 'Name';
        break;
      case 'text':
        name = 'TextDetections';
        sub = 'DetectedText';
        break;
      case 'face':
      default:
        return undefined;
    }

    let result =
      await CommonUtils.download(Environment.Proxy.Bucket, key).catch(() => undefined);

    if (!result) {
      return undefined;
    }

    result = JSON.parse(result);

    if (type === 'text') {
      result.TextDetections = result.TextDetections.filter(x =>
        x.Type === 'WORD');
    }

    let keys = (!sub02)
      ? result[name].map(x => x[sub].toLowerCase())
      : result[name].map(x => x[sub][sub02].replace(/_/g, ' ').toLowerCase());
    keys = Array.from(new Set(keys));

    return (!keys.length) ? undefined : {
      [type]: keys,
    };
  }