X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fexpress-utils.ts;h=003e028189fc41c6a8d7a50667cb5bb36255448f;hb=3b54e5902a54c99c2968383e967370ae17bbba03;hp=bca59a83c38984223989335f84afcf9550bcf2e0;hpb=1cfbdd30d9913bfaa0c7e54f82e5b953646bb0d1;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts index bca59a83c..003e02818 100644 --- a/server/helpers/express-utils.ts +++ b/server/helpers/express-utils.ts @@ -1,14 +1,13 @@ import * as express from 'express' import * as multer from 'multer' -import { extname } from 'path' import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' import { CONFIG } from '../initializers/config' import { REMOTE_SCHEME } from '../initializers/constants' +import { getLowercaseExtension } from './core-utils' import { isArray } from './custom-validators/misc' import { logger } from './logger' import { deleteFileAndCatch, generateRandomString } from './utils' import { getExtFromMimetype } from './video' -import { ProblemDocument, ProblemDocumentExtension } from 'http-problem-details' function buildNSFWFilter (res?: express.Response, paramNSFW?: string) { if (paramNSFW === 'true') return true @@ -80,7 +79,7 @@ function createReqFiles ( filename: async (req, file, cb) => { let extension: string - const fileExtension = extname(file.originalname) + const fileExtension = getLowercaseExtension(file.originalname) const extensionFromMimetype = getExtFromMimetype(mimeTypes, file.mimetype) // Take the file extension if we don't understand the mime type @@ -126,34 +125,6 @@ function getCountVideos (req: express.Request) { return req.query.skipCount !== true } -// helpers added in server.ts and used in subsequent controllers used -const apiResponseHelpers = (req, res: express.Response, next = null) => { - res.fail = (options) => { - const { data, status, message, title, type, docs, instance } = { - data: null, - ...options, - status: options.status || HttpStatusCode.BAD_REQUEST_400 - } - - const extension = new ProblemDocumentExtension({ - ...data, - docs: docs || res.docs - }) - - res.status(status) - res.setHeader('Content-Type', 'application/problem+json') - res.json(new ProblemDocument({ - status, - title, - instance, - type: type && '' + type, - detail: message - }, extension)) - } - - if (next !== null) next() -} - // --------------------------------------------------------------------------- export { @@ -163,6 +134,5 @@ export { badRequest, createReqFiles, cleanUpReqFiles, - getCountVideos, - apiResponseHelpers + getCountVideos }