mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 17:59:37 +02:00
Refactor a little bit controllers
This commit is contained in:
parent
c00100b607
commit
c158a5faab
14 changed files with 625 additions and 504 deletions
|
@ -1,13 +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 { isArray } from './custom-validators/misc'
|
||||
import { logger } from './logger'
|
||||
import { deleteFileAndCatch, generateRandomString } from './utils'
|
||||
import { extname } from 'path'
|
||||
import { isArray } from './custom-validators/misc'
|
||||
import { CONFIG } from '../initializers/config'
|
||||
import { getExtFromMimetype } from './video'
|
||||
import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
|
||||
if (paramNSFW === 'true') return true
|
||||
|
@ -30,21 +30,21 @@ function buildNSFWFilter (res?: express.Response, paramNSFW?: string) {
|
|||
return null
|
||||
}
|
||||
|
||||
function cleanUpReqFiles (req: { files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[] }) {
|
||||
const files = req.files
|
||||
function cleanUpReqFiles (
|
||||
req: { files: { [fieldname: string]: Express.Multer.File[] } | Express.Multer.File[] }
|
||||
) {
|
||||
const filesObject = req.files
|
||||
if (!filesObject) return
|
||||
|
||||
if (!files) return
|
||||
|
||||
if (isArray(files)) {
|
||||
(files as Express.Multer.File[]).forEach(f => deleteFileAndCatch(f.path))
|
||||
if (isArray(filesObject)) {
|
||||
filesObject.forEach(f => deleteFileAndCatch(f.path))
|
||||
return
|
||||
}
|
||||
|
||||
for (const key of Object.keys(files)) {
|
||||
const file = files[key]
|
||||
for (const key of Object.keys(filesObject)) {
|
||||
const files = filesObject[key]
|
||||
|
||||
if (isArray(file)) file.forEach(f => deleteFileAndCatch(f.path))
|
||||
else deleteFileAndCatch(file.path)
|
||||
files.forEach(f => deleteFileAndCatch(f.path))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue