'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var hooksCore = require('@midwayjs/hooks-core');
var groupBy = require('lodash.groupby');

function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }

var groupBy__default = /*#__PURE__*/_interopDefault(groupBy);

function useFiles() {
  const ctx = hooksCore.useContext();
  const files = ctx.files;
  return groupBy__default["default"](files, 'fieldName');
}

function useFields() {
  const ctx = hooksCore.useContext();
  return ctx.fields;
}





function Upload(path) {
  return {
    name: 'Upload',
    input: true,
    metadata({ setMetadata }) {
      setMetadata(hooksCore.OperatorType.Trigger, {
        type: hooksCore.HttpTriggerType,
        method: hooksCore.HttpMethod.POST,
        path,
        requestClient: {
          fetcher: 'upload',
          client: '@midwayjs/rpc' } });


    } };

}

exports.Upload = Upload;
exports.useFields = useFields;
exports.useFiles = useFiles;
