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
return null
}
-function cleanUpReqFiles (
- req: { files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[] }
-) {
+function cleanUpReqFiles (req: express.Request) {
const filesObject = req.files
if (!filesObject) return
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
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 {
badRequest,
createReqFiles,
cleanUpReqFiles,
- getCountVideos,
- apiResponseHelpers
+ getCountVideos
}