]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Cleanup utils helper
authorChocobozzz <me@florianbigard.com>
Tue, 14 Aug 2018 13:28:30 +0000 (15:28 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 14 Aug 2018 13:28:30 +0000 (15:28 +0200)
20 files changed:
server/controllers/api/config.ts
server/controllers/api/video-channel.ts
server/controllers/api/videos/index.ts
server/helpers/core-utils.ts
server/helpers/database-utils.ts
server/helpers/express-utils.ts
server/helpers/ffmpeg-utils.ts
server/helpers/signup.ts [new file with mode: 0644]
server/helpers/utils.ts
server/lib/activitypub/process/process-update.ts
server/lib/job-queue/handlers/video-file.ts
server/middlewares/cache.ts
server/middlewares/sort.ts
server/middlewares/validators/avatar.ts
server/middlewares/validators/users.ts
server/middlewares/validators/video-captions.ts
server/middlewares/validators/video-imports.ts
server/middlewares/validators/videos.ts
server/models/utils.ts
server/models/video/video-blacklist.ts

index 6f05c33dbbb27207d47d287284ee07cd4f0d5192..e0539c414fe2a39ddf5c76c98ebeefd3501f57ce 100644 (file)
@@ -4,7 +4,7 @@ import { ServerConfig, UserRight } from '../../../shared'
 import { About } from '../../../shared/models/server/about.model'
 import { CustomConfig } from '../../../shared/models/server/custom-config.model'
 import { unlinkPromise, writeFilePromise } from '../../helpers/core-utils'
-import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils'
+import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
 import { CONFIG, CONSTRAINTS_FIELDS, reloadConfig } from '../../initializers'
 import { asyncMiddleware, authenticate, ensureUserHasRight } from '../../middlewares'
 import { customConfigUpdateValidator } from '../../middlewares/validators/config'
index 3a444547b66666c96437c47e884a185760905437..023ebbedfabf8e3e7090b48ecb949950a9e97325 100644 (file)
@@ -1,9 +1,10 @@
 import * as express from 'express'
-import { getFormattedObjects, resetSequelizeInstance } from '../../helpers/utils'
+import { getFormattedObjects } from '../../helpers/utils'
 import {
   asyncMiddleware,
   asyncRetryTransactionMiddleware,
-  authenticate, commonVideosFiltersValidator,
+  authenticate,
+  commonVideosFiltersValidator,
   optionalAuthenticate,
   paginationValidator,
   setDefaultPagination,
@@ -19,7 +20,7 @@ import { videosSortValidator } from '../../middlewares/validators'
 import { sendUpdateActor } from '../../lib/activitypub/send'
 import { VideoChannelCreate, VideoChannelUpdate } from '../../../shared'
 import { createVideoChannel } from '../../lib/video-channel'
-import { createReqFiles, buildNSFWFilter } from '../../helpers/express-utils'
+import { buildNSFWFilter, createReqFiles } from '../../helpers/express-utils'
 import { setAsyncActorKeys } from '../../lib/activitypub'
 import { AccountModel } from '../../models/account/account'
 import { CONFIG, IMAGE_MIMETYPE_EXT, sequelizeTypescript } from '../../initializers'
@@ -28,6 +29,7 @@ import { VideoModel } from '../../models/video/video'
 import { updateAvatarValidator } from '../../middlewares/validators/avatar'
 import { updateActorAvatarFile } from '../../lib/avatar'
 import { auditLoggerFactory, VideoChannelAuditView } from '../../helpers/audit-logger'
+import { resetSequelizeInstance } from '../../helpers/database-utils'
 
 const auditLogger = auditLoggerFactory('channels')
 const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR })
index c9365da08f33065658b22e4582cbd3212f643536..92c6ee697b77cd206001115e952afefff4f5f2e8 100644 (file)
@@ -6,7 +6,7 @@ import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffmpeg
 import { processImage } from '../../../helpers/image-utils'
 import { logger } from '../../../helpers/logger'
 import { auditLoggerFactory, VideoAuditView } from '../../../helpers/audit-logger'
-import { getFormattedObjects, getServerActor, resetSequelizeInstance } from '../../../helpers/utils'
+import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
 import {
   CONFIG,
   IMAGE_MIMETYPE_EXT,
@@ -51,10 +51,11 @@ import { blacklistRouter } from './blacklist'
 import { videoCommentRouter } from './comment'
 import { rateVideoRouter } from './rate'
 import { VideoFilter } from '../../../../shared/models/videos/video-query.type'
-import { createReqFiles, buildNSFWFilter } from '../../../helpers/express-utils'
+import { buildNSFWFilter, createReqFiles } from '../../../helpers/express-utils'
 import { ScheduleVideoUpdateModel } from '../../../models/video/schedule-video-update'
 import { videoCaptionsRouter } from './captions'
 import { videoImportsRouter } from './import'
+import { resetSequelizeInstance } from '../../../helpers/database-utils'
 
 const auditLogger = auditLoggerFactory('videos')
 const videosRouter = express.Router()
index 3b38da66cd6e34a994e6ce8dcbc8bc42d71af5b7..90d2cd9b3c2fd01038b92ccf2cc1c53d247e327b 100644 (file)
@@ -14,6 +14,35 @@ import * as rimraf from 'rimraf'
 import { URL } from 'url'
 import { truncate } from 'lodash'
 
+const timeTable = {
+  ms:           1,
+  second:       1000,
+  minute:       60000,
+  hour:         3600000,
+  day:          3600000 * 24,
+  week:         3600000 * 24 * 7,
+  month:        3600000 * 24 * 30
+}
+export function parseDuration (duration: number | string): number {
+  if (typeof duration === 'number') return duration
+
+  if (typeof duration === 'string') {
+    const split = duration.match(/^([\d\.,]+)\s?(\w+)$/)
+
+    if (split.length === 3) {
+      const len = parseFloat(split[1])
+      let unit = split[2].replace(/s$/i,'').toLowerCase()
+      if (unit === 'm') {
+        unit = 'ms'
+      }
+
+      return (len || 1) * (timeTable[unit] || 0)
+    }
+  }
+
+  throw new Error('Duration could not be properly parsed')
+}
+
 function sanitizeUrl (url: string) {
   const urlObject = new URL(url)
 
index 53f881fb36a4a5fe8a5106bf6783169c2a194cd9..1005d2cf19694f16e3f0cf1f000834a9c3a83972 100644 (file)
@@ -1,6 +1,6 @@
 import * as retry from 'async/retry'
 import * as Bluebird from 'bluebird'
-import { Model, Sequelize } from 'sequelize-typescript'
+import { Model } from 'sequelize-typescript'
 import { logger } from './logger'
 
 function retryTransactionWrapper <T, A, B, C> (
@@ -66,9 +66,17 @@ function updateInstanceWithAnother <T extends Model<T>> (instanceToUpdate: Model
   }
 }
 
+function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
+  Object.keys(savedFields).forEach(key => {
+    const value = savedFields[key]
+    instance.set(key, value)
+  })
+}
+
 // ---------------------------------------------------------------------------
 
 export {
+  resetSequelizeInstance,
   retryTransactionWrapper,
   transactionRetryer,
   updateInstanceWithAnother
index b3cc4084892402dcb2883177092a000f55c1e57d..1d7bee87edfe424557cdc42c62983c17b428f4fc 100644 (file)
@@ -3,8 +3,9 @@ import * as multer from 'multer'
 import { CONFIG, REMOTE_SCHEME } from '../initializers'
 import { logger } from './logger'
 import { User } from '../../shared/models/users'
-import { generateRandomString } from './utils'
+import { deleteFileAsync, generateRandomString } from './utils'
 import { extname } from 'path'
+import { isArray } from './custom-validators/misc'
 
 function buildNSFWFilter (res: express.Response, paramNSFW?: string) {
   if (paramNSFW === 'true') return true
@@ -23,6 +24,24 @@ 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
+
+  if (!files) return
+
+  if (isArray(files)) {
+    (files as Express.Multer.File[]).forEach(f => deleteFileAsync(f.path))
+    return
+  }
+
+  for (const key of Object.keys(files)) {
+    const file = files[ key ]
+
+    if (isArray(file)) file.forEach(f => deleteFileAsync(f.path))
+    else deleteFileAsync(file.path)
+  }
+}
+
 function getHostWithPort (host: string) {
   const splitted = host.split(':')
 
@@ -82,5 +101,6 @@ export {
   buildNSFWFilter,
   getHostWithPort,
   badRequest,
-  createReqFiles
+  createReqFiles,
+  cleanUpReqFiles
 }
index ced56b82daf6babfd7db43646ce72181ea029a7d..f8299c36f0b907809243a3a732d0c6ded293f3da 100644 (file)
@@ -7,6 +7,28 @@ import { processImage } from './image-utils'
 import { logger } from './logger'
 import { checkFFmpegEncoders } from '../initializers/checker'
 
+function computeResolutionsToTranscode (videoFileHeight: number) {
+  const resolutionsEnabled: number[] = []
+  const configResolutions = CONFIG.TRANSCODING.RESOLUTIONS
+
+  // Put in the order we want to proceed jobs
+  const resolutions = [
+    VideoResolution.H_480P,
+    VideoResolution.H_360P,
+    VideoResolution.H_720P,
+    VideoResolution.H_240P,
+    VideoResolution.H_1080P
+  ]
+
+  for (const resolution of resolutions) {
+    if (configResolutions[ resolution + 'p' ] === true && videoFileHeight > resolution) {
+      resolutionsEnabled.push(resolution)
+    }
+  }
+
+  return resolutionsEnabled
+}
+
 async function getVideoFileResolution (path: string) {
   const videoStream = await getVideoFileStream(path)
 
@@ -134,6 +156,7 @@ export {
   generateImageFromVideoFile,
   transcode,
   getVideoFileFPS,
+  computeResolutionsToTranscode,
   audio
 }
 
diff --git a/server/helpers/signup.ts b/server/helpers/signup.ts
new file mode 100644 (file)
index 0000000..cdce798
--- /dev/null
@@ -0,0 +1,59 @@
+import { CONFIG } from '../initializers'
+import { UserModel } from '../models/account/user'
+import * as ipaddr from 'ipaddr.js'
+const isCidr = require('is-cidr')
+
+async function isSignupAllowed () {
+  if (CONFIG.SIGNUP.ENABLED === false) {
+    return false
+  }
+
+  // No limit and signup is enabled
+  if (CONFIG.SIGNUP.LIMIT === -1) {
+    return true
+  }
+
+  const totalUsers = await UserModel.countTotal()
+
+  return totalUsers < CONFIG.SIGNUP.LIMIT
+}
+
+function isSignupAllowedForCurrentIP (ip: string) {
+  const addr = ipaddr.parse(ip)
+  let excludeList = [ 'blacklist' ]
+  let matched = ''
+
+  // if there is a valid, non-empty whitelist, we exclude all unknown adresses too
+  if (CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr(cidr)).length > 0) {
+    excludeList.push('unknown')
+  }
+
+  if (addr.kind() === 'ipv4') {
+    const addrV4 = ipaddr.IPv4.parse(ip)
+    const rangeList = {
+      whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr))
+                       .map(cidr => ipaddr.IPv4.parseCIDR(cidr)),
+      blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr))
+                       .map(cidr => ipaddr.IPv4.parseCIDR(cidr))
+    }
+    matched = ipaddr.subnetMatch(addrV4, rangeList, 'unknown')
+  } else if (addr.kind() === 'ipv6') {
+    const addrV6 = ipaddr.IPv6.parse(ip)
+    const rangeList = {
+      whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr))
+                       .map(cidr => ipaddr.IPv6.parseCIDR(cidr)),
+      blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr))
+                       .map(cidr => ipaddr.IPv6.parseCIDR(cidr))
+    }
+    matched = ipaddr.subnetMatch(addrV6, rangeList, 'unknown')
+  }
+
+  return !excludeList.includes(matched)
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+  isSignupAllowed,
+  isSignupAllowedForCurrentIP
+}
index eaad555553527b98549e69580203f0357063b0ee..703e5788744889c74315e3646c626672ab14736b 100644 (file)
@@ -1,37 +1,12 @@
-import { Model } from 'sequelize-typescript'
-import * as ipaddr from 'ipaddr.js'
 import { ResultList } from '../../shared'
-import { VideoResolution } from '../../shared/models/videos'
 import { CONFIG } from '../initializers'
-import { UserModel } from '../models/account/user'
 import { ActorModel } from '../models/activitypub/actor'
 import { ApplicationModel } from '../models/application/application'
 import { pseudoRandomBytesPromise, sha256, unlinkPromise } from './core-utils'
 import { logger } from './logger'
-import { isArray } from './custom-validators/misc'
 import { join } from 'path'
 import { Instance as ParseTorrent } from 'parse-torrent'
 
-const isCidr = require('is-cidr')
-
-function cleanUpReqFiles (req: { files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[] }) {
-  const files = req.files
-
-  if (!files) return
-
-  if (isArray(files)) {
-    (files as Express.Multer.File[]).forEach(f => deleteFileAsync(f.path))
-    return
-  }
-
-  for (const key of Object.keys(files)) {
-    const file = files[key]
-
-    if (isArray(file)) file.forEach(f => deleteFileAsync(f.path))
-    else deleteFileAsync(file.path)
-  }
-}
-
 function deleteFileAsync (path: string) {
   unlinkPromise(path)
     .catch(err => logger.error('Cannot delete the file %s asynchronously.', path, { err }))
@@ -60,127 +35,23 @@ function getFormattedObjects<U, T extends FormattableToJSON> (objects: T[], obje
   } as ResultList<U>
 }
 
-async function isSignupAllowed () {
-  if (CONFIG.SIGNUP.ENABLED === false) {
-    return false
-  }
-
-  // No limit and signup is enabled
-  if (CONFIG.SIGNUP.LIMIT === -1) {
-    return true
-  }
-
-  const totalUsers = await UserModel.countTotal()
-
-  return totalUsers < CONFIG.SIGNUP.LIMIT
-}
-
-function isSignupAllowedForCurrentIP (ip: string) {
-  const addr = ipaddr.parse(ip)
-  let excludeList = [ 'blacklist' ]
-  let matched = ''
-
-  // if there is a valid, non-empty whitelist, we exclude all unknown adresses too
-  if (CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr(cidr)).length > 0) {
-    excludeList.push('unknown')
-  }
-
-  if (addr.kind() === 'ipv4') {
-    const addrV4 = ipaddr.IPv4.parse(ip)
-    const rangeList = {
-      whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v4(cidr))
-                                                .map(cidr => ipaddr.IPv4.parseCIDR(cidr)),
-      blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v4(cidr))
-                                                .map(cidr => ipaddr.IPv4.parseCIDR(cidr))
-    }
-    matched = ipaddr.subnetMatch(addrV4, rangeList, 'unknown')
-  } else if (addr.kind() === 'ipv6') {
-    const addrV6 = ipaddr.IPv6.parse(ip)
-    const rangeList = {
-      whitelist: CONFIG.SIGNUP.FILTERS.CIDR.WHITELIST.filter(cidr => isCidr.v6(cidr))
-                                                .map(cidr => ipaddr.IPv6.parseCIDR(cidr)),
-      blacklist: CONFIG.SIGNUP.FILTERS.CIDR.BLACKLIST.filter(cidr => isCidr.v6(cidr))
-                                                .map(cidr => ipaddr.IPv6.parseCIDR(cidr))
-    }
-    matched = ipaddr.subnetMatch(addrV6, rangeList, 'unknown')
-  }
-
-  return !excludeList.includes(matched)
-}
-
-function computeResolutionsToTranscode (videoFileHeight: number) {
-  const resolutionsEnabled: number[] = []
-  const configResolutions = CONFIG.TRANSCODING.RESOLUTIONS
-
-  // Put in the order we want to proceed jobs
-  const resolutions = [
-    VideoResolution.H_480P,
-    VideoResolution.H_360P,
-    VideoResolution.H_720P,
-    VideoResolution.H_240P,
-    VideoResolution.H_1080P
-  ]
-
-  for (const resolution of resolutions) {
-    if (configResolutions[ resolution + 'p' ] === true && videoFileHeight > resolution) {
-      resolutionsEnabled.push(resolution)
-    }
-  }
-
-  return resolutionsEnabled
-}
-
-const timeTable = {
-  ms:           1,
-  second:       1000,
-  minute:       60000,
-  hour:         3600000,
-  day:          3600000 * 24,
-  week:         3600000 * 24 * 7,
-  month:        3600000 * 24 * 30
-}
-export function parseDuration (duration: number | string): number {
-  if (typeof duration === 'number') return duration
-
-  if (typeof duration === 'string') {
-    const split = duration.match(/^([\d\.,]+)\s?(\w+)$/)
-
-    if (split.length === 3) {
-      const len = parseFloat(split[1])
-      let unit = split[2].replace(/s$/i,'').toLowerCase()
-      if (unit === 'm') {
-        unit = 'ms'
-      }
-
-      return (len || 1) * (timeTable[unit] || 0)
-    }
-  }
-
-  throw new Error('Duration could not be properly parsed')
-}
-
-function resetSequelizeInstance (instance: Model<any>, savedFields: object) {
-  Object.keys(savedFields).forEach(key => {
-    const value = savedFields[key]
-    instance.set(key, value)
-  })
-}
-
-let serverActor: ActorModel
 async function getServerActor () {
-  if (serverActor === undefined) {
+  if (getServerActor.serverActor === undefined) {
     const application = await ApplicationModel.load()
     if (!application) throw Error('Could not load Application from database.')
 
-    serverActor = application.Account.Actor
+    getServerActor.serverActor = application.Account.Actor
   }
 
-  if (!serverActor) {
+  if (!getServerActor.serverActor) {
     logger.error('Cannot load server actor.')
     process.exit(0)
   }
 
-  return Promise.resolve(serverActor)
+  return Promise.resolve(getServerActor.serverActor)
+}
+namespace getServerActor {
+  export let serverActor: ActorModel
 }
 
 function generateVideoTmpPath (target: string | ParseTorrent) {
@@ -194,21 +65,13 @@ function getSecureTorrentName (originalName: string) {
   return sha256(originalName) + '.torrent'
 }
 
-type SortType = { sortModel: any, sortValue: string }
-
 // ---------------------------------------------------------------------------
 
 export {
-  cleanUpReqFiles,
   deleteFileAsync,
   generateRandomString,
   getFormattedObjects,
-  isSignupAllowed,
   getSecureTorrentName,
-  isSignupAllowedForCurrentIP,
-  computeResolutionsToTranscode,
-  resetSequelizeInstance,
   getServerActor,
-  SortType,
   generateVideoTmpPath
 }
index 82b661a0329dc6cc24802e1ed8a72630a5abe708..11226e2753661637ba9031c3fa352e2eb2abaa6d 100644 (file)
@@ -1,9 +1,8 @@
 import * as Bluebird from 'bluebird'
 import { ActivityUpdate, VideoTorrentObject } from '../../../../shared/models/activitypub'
 import { ActivityPubActor } from '../../../../shared/models/activitypub/activitypub-actor'
-import { retryTransactionWrapper } from '../../../helpers/database-utils'
+import { resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers/database-utils'
 import { logger } from '../../../helpers/logger'
-import { resetSequelizeInstance } from '../../../helpers/utils'
 import { sequelizeTypescript } from '../../../initializers'
 import { AccountModel } from '../../../models/account/account'
 import { ActorModel } from '../../../models/activitypub/actor'
index 6b1a8f1328a4cc04c541f1452e3e0c59f4c66e98..c6308f7a6cbb4740c486844a0975d02ef199b5b7 100644 (file)
@@ -1,13 +1,13 @@
 import * as Bull from 'bull'
 import { VideoResolution, VideoState } from '../../../../shared'
 import { logger } from '../../../helpers/logger'
-import { computeResolutionsToTranscode } from '../../../helpers/utils'
 import { VideoModel } from '../../../models/video/video'
 import { JobQueue } from '../job-queue'
 import { federateVideoIfNeeded } from '../../activitypub'
 import { retryTransactionWrapper } from '../../../helpers/database-utils'
 import { sequelizeTypescript } from '../../../initializers'
 import * as Bluebird from 'bluebird'
+import { computeResolutionsToTranscode } from '../../../helpers/ffmpeg-utils'
 
 export type VideoFilePayload = {
   videoUUID: string
index c671b88c954f74fbb06ca9f255e9da5b03d3e28d..b40486e4bf3b953f83e907d500e4c8117f8a40b9 100644 (file)
@@ -1,6 +1,6 @@
 import * as express from 'express'
 import * as AsyncLock from 'async-lock'
-import { parseDuration } from '../helpers/utils'
+import { parseDuration } from '../helpers/core-utils'
 import { Redis } from '../lib/redis'
 import { logger } from '../helpers/logger'
 
index 5120804b3a34b27dc88753ff86cffd5906062ff9..6507aa5b8b54a7396cb0d59dc149757f26d7ae62 100644 (file)
@@ -1,6 +1,6 @@
 import * as express from 'express'
 import 'express-validator'
-import { SortType } from '../helpers/utils'
+import { SortType } from '../models/utils'
 
 function setDefaultSort (req: express.Request, res: express.Response, next: express.NextFunction) {
   if (!req.query.sort) req.query.sort = '-createdAt'
index 5860735c6355c7b34ab3026b4b6588376c3d833d..ddc14f53165b4d4dd045e25d7a1d94522ea06213 100644 (file)
@@ -4,7 +4,7 @@ import { isAvatarFile } from '../../helpers/custom-validators/users'
 import { areValidationErrors } from './utils'
 import { CONSTRAINTS_FIELDS } from '../../initializers'
 import { logger } from '../../helpers/logger'
-import { cleanUpReqFiles } from '../../helpers/utils'
+import { cleanUpReqFiles } from '../../helpers/express-utils'
 
 const updateAvatarValidator = [
   body('avatarfile').custom((value, { req }) => isAvatarFile(req.files)).withMessage(
index 771c414a023d10e8b5403938e751247e72d497db..f47fa8b4893b81f940ed2b35475eeffa09f7d98b 100644 (file)
@@ -16,7 +16,7 @@ import {
 } from '../../helpers/custom-validators/users'
 import { isVideoExist } from '../../helpers/custom-validators/videos'
 import { logger } from '../../helpers/logger'
-import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/utils'
+import { isSignupAllowed, isSignupAllowedForCurrentIP } from '../../helpers/signup'
 import { Redis } from '../../lib/redis'
 import { UserModel } from '../../models/account/user'
 import { areValidationErrors } from './utils'
index 18d537bc473f35148d3e19fa7af2dc88ddca198c..4f393ea84e06f83aa018ad9f257a63327c3806b6 100644 (file)
@@ -7,7 +7,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers'
 import { UserRight } from '../../../shared'
 import { logger } from '../../helpers/logger'
 import { isVideoCaptionExist, isVideoCaptionFile, isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
-import { cleanUpReqFiles } from '../../helpers/utils'
+import { cleanUpReqFiles } from '../../helpers/express-utils'
 
 const addVideoCaptionValidator = [
   param('videoId').custom(isIdOrUUIDValid).not().isEmpty().withMessage('Should have a valid video id'),
index 9ac739101f2390ecb4a2984f35df9092a24d1d0e..b2063b8dac1a47561f543743b8ed5e38c27800c3 100644 (file)
@@ -5,7 +5,7 @@ import { logger } from '../../helpers/logger'
 import { areValidationErrors } from './utils'
 import { getCommonVideoAttributes } from './videos'
 import { isVideoImportTargetUrlValid, isVideoImportTorrentFile } from '../../helpers/custom-validators/video-imports'
-import { cleanUpReqFiles } from '../../helpers/utils'
+import { cleanUpReqFiles } from '../../helpers/express-utils'
 import { isVideoChannelOfAccountExist, isVideoMagnetUriValid, isVideoNameValid } from '../../helpers/custom-validators/videos'
 import { CONFIG } from '../../initializers/constants'
 import { CONSTRAINTS_FIELDS } from '../../initializers'
index 77d601a4df11246321b722307f42505fe1d3b25a..53c32abb86f15bc3016961ca0fae054d04bfbe51 100644 (file)
@@ -34,7 +34,7 @@ import { CONSTRAINTS_FIELDS } from '../../initializers'
 import { VideoShareModel } from '../../models/video/video-share'
 import { authenticate } from '../oauth'
 import { areValidationErrors } from './utils'
-import { cleanUpReqFiles } from '../../helpers/utils'
+import { cleanUpReqFiles } from '../../helpers/express-utils'
 import { VideoModel } from '../../models/video/video'
 import { UserModel } from '../../models/account/user'
 
index 58a18c97a9788a2aab814f19925f7acbf8b9d820..eb6653f3ddf24d906c4333a7856fd26d8923618c 100644 (file)
@@ -1,6 +1,8 @@
 // Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
 import { Sequelize } from 'sequelize-typescript'
 
+type SortType = { sortModel: any, sortValue: string }
+
 function getSort (value: string, lastSort: string[] = [ 'id', 'ASC' ]) {
   let field: any
   let direction: 'ASC' | 'DESC'
@@ -54,6 +56,7 @@ function createSimilarityAttribute (col: string, value: string) {
 // ---------------------------------------------------------------------------
 
 export {
+  SortType,
   getSort,
   getSortOnModel,
   createSimilarityAttribute,
index eabc37ef0e64d2d8cba9355ac36d25515b56898d..67f7cd4871c0aeef041996ff11f557002e26ebfd 100644 (file)
@@ -4,15 +4,15 @@ import {
   AllowNull,
   BelongsTo,
   Column,
-  CreatedAt, DataType,
+  CreatedAt,
+  DataType,
   ForeignKey,
   Is,
   Model,
   Table,
   UpdatedAt
 } from 'sequelize-typescript'
-import { SortType } from '../../helpers/utils'
-import { getSortOnModel, throwIfNotValid } from '../utils'
+import { getSortOnModel, SortType, throwIfNotValid } from '../utils'
 import { VideoModel } from './video'
 import { isVideoBlacklistReasonValid } from '../../helpers/custom-validators/video-blacklist'
 import { Emailer } from '../../lib/emailer'