mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Replace express-async-handler for a local function.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import asyncHandler from 'express-async-handler';
|
||||
import express, { NextFunction, Request, Response } from 'express';
|
||||
import asyncHandler from '../utils/async-handler';
|
||||
import Busboy from 'busboy';
|
||||
import { MetaService, FilesService } from '../services';
|
||||
import { File, PrimaryKey } from '../types';
|
||||
@@ -18,7 +18,7 @@ const router = express.Router();
|
||||
|
||||
router.use(useCollection('directus_files'));
|
||||
|
||||
const multipartHandler = asyncHandler(async (req, res, next) => {
|
||||
const multipartHandler = asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.is('multipart/form-data') === false) return next();
|
||||
|
||||
const busboy = new Busboy({ headers: req.headers });
|
||||
@@ -97,7 +97,7 @@ const multipartHandler = asyncHandler(async (req, res, next) => {
|
||||
router.post(
|
||||
'/',
|
||||
multipartHandler,
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
const service = new FilesService({
|
||||
accountability: req.accountability,
|
||||
schema: req.schema,
|
||||
@@ -137,7 +137,7 @@ const importSchema = Joi.object({
|
||||
|
||||
router.post(
|
||||
'/import',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
const { error } = importSchema.validate(req.body);
|
||||
|
||||
if (error) {
|
||||
@@ -184,7 +184,7 @@ router.post(
|
||||
|
||||
router.get(
|
||||
'/',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
const service = new FilesService({
|
||||
accountability: req.accountability,
|
||||
schema: req.schema,
|
||||
@@ -205,7 +205,7 @@ router.get(
|
||||
|
||||
router.get(
|
||||
'/:pk',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
const keys = req.params.pk.includes(',') ? req.params.pk.split(',') : req.params.pk;
|
||||
const service = new FilesService({
|
||||
accountability: req.accountability,
|
||||
@@ -221,7 +221,7 @@ router.get(
|
||||
router.patch(
|
||||
'/:pk',
|
||||
multipartHandler,
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
const service = new FilesService({
|
||||
accountability: req.accountability,
|
||||
schema: req.schema,
|
||||
@@ -253,7 +253,7 @@ router.patch(
|
||||
|
||||
router.delete(
|
||||
'/',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
if (!req.body || Array.isArray(req.body) === false) {
|
||||
throw new InvalidPayloadException(`Body has to be an array of primary keys`);
|
||||
}
|
||||
@@ -270,7 +270,7 @@ router.delete(
|
||||
|
||||
router.delete(
|
||||
'/:pk',
|
||||
asyncHandler(async (req, res, next) => {
|
||||
asyncHandler(async (req: Request, res: Response, next: NextFunction) => {
|
||||
const keys = req.params.pk.includes(',') ? req.params.pk.split(',') : req.params.pk;
|
||||
const service = new FilesService({
|
||||
accountability: req.accountability,
|
||||
|
||||
Reference in New Issue
Block a user