multipart.js 407 B

12345678910111213141516
  1. 'use strict';
  2. const pathMatching = require('egg-path-matching');
  3. module.exports = options => {
  4. // normalize
  5. const matchFn = options.fileModeMatch && pathMatching({ match: options.fileModeMatch });
  6. return async function multipart(ctx, next) {
  7. if (!ctx.is('multipart')) return next();
  8. if (matchFn && !matchFn(ctx)) return next();
  9. await ctx.saveRequestFiles();
  10. return next();
  11. };
  12. };