import * as fs from 'fs'
import { join } from 'path'
import * as Sequelize from 'sequelize'
+import { each } from 'async'
import { CONFIG } from './constants'
// Do not use barrel, we need to load database first
database.sequelize = sequelize
database.init = function (silent: boolean, callback: (err: Error) => void) {
-
const modelDirectory = join(__dirname, '..', 'models')
- fs.readdir(modelDirectory, function (err, files) {
- if (err) throw err
- files.filter(function (file) {
- // For all models but not utils.js
- if (
- file === 'index.js' || file === 'index.ts' ||
- file === 'utils.js' || file === 'utils.ts' ||
- file.endsWith('-interface.js') || file.endsWith('-interface.ts') ||
- file.endsWith('.js.map')
- ) return false
+ getModelFiles(modelDirectory, function (err, filePaths) {
+ if (err) throw err
- return true
- })
- .forEach(function (file) {
- const model = sequelize.import(join(modelDirectory, file))
+ filePaths.forEach(function (filePath) {
+ const model = sequelize.import(filePath)
database[model['name']] = model
})
export {
database
}
+
+// ---------------------------------------------------------------------------
+
+function getModelFiles (modelDirectory: string, callback: (err: Error, filePaths: string[]) => void) {
+ fs.readdir(modelDirectory, function (err, files) {
+ if (err) throw err
+
+ const directories = files.filter(function (directory) {
+ // For all models but not utils.js
+ if (
+ directory === 'index.js' || directory === 'index.ts' ||
+ directory === 'utils.js' || directory === 'utils.ts'
+ ) return false
+
+ return true
+ })
+
+ let modelFilePaths: string[] = []
+
+ // For each directory we read it and append model in the modelFilePaths array
+ each(directories, function (directory: string, eachCallback: ErrorCallback<Error>) {
+ const modelDirectoryPath = join(modelDirectory, directory)
+
+ fs.readdir(modelDirectoryPath, function (err, files) {
+ if (err) return eachCallback(err)
+
+ const filteredFiles = files.filter(file => {
+ if (
+ file === 'index.js' || file === 'index.ts' ||
+ file === 'utils.js' || file === 'utils.ts' ||
+ file.endsWith('-interface.js') || file.endsWith('-interface.ts') ||
+ file.endsWith('.js.map')
+ ) return false
+
+ return true
+ }).map(file => {
+ return join(modelDirectoryPath, file)
+ })
+
+ modelFilePaths = modelFilePaths.concat(filteredFiles)
+
+ return eachCallback(null)
+ })
+ }, function(err: Error) {
+ return callback(err, modelFilePaths)
+ })
+ })
+}
import * as Sequelize from 'sequelize'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
ApplicationClass,
ApplicationAttributes,
--- /dev/null
+export * from './application-interface'
-export * from './application-interface'
-export * from './author-interface'
-export * from './job-interface'
-export * from './oauth-client-interface'
-export * from './oauth-token-interface'
-export * from './pod-interface'
-export * from './request-interface'
-export * from './request-to-pod-interface'
-export * from './request-video-event-interface'
-export * from './request-video-qadu-interface'
-export * from './tag-interface'
-export * from './user-video-rate-interface'
-export * from './user-interface'
-export * from './video-abuse-interface'
-export * from './video-blacklist-interface'
-export * from './video-tag-interface'
-export * from './video-interface'
+export * from './application'
+export * from './job'
+export * from './oauth'
+export * from './pod'
+export * from './request'
+export * from './user'
+export * from './video'
--- /dev/null
+export * from './job-interface'
import { values } from 'lodash'
import * as Sequelize from 'sequelize'
-import { JOB_STATES } from '../initializers'
+import { JOB_STATES } from '../../initializers'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
JobClass,
JobInstance,
--- /dev/null
+export * from './oauth-client-interface'
+export * from './oauth-token-interface'
import * as Sequelize from 'sequelize'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
OAuthClientClass,
OAuthClientInstance,
import * as Sequelize from 'sequelize'
import * as Bluebird from 'bluebird'
-import { UserModel } from './user-interface'
+import { UserModel } from '../user'
export type OAuthTokenInfo = {
refreshToken: string
import * as Sequelize from 'sequelize'
-import { logger } from '../helpers'
+import { logger } from '../../helpers'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
OAuthTokenClass,
OAuthTokenInstance,
--- /dev/null
+export * from './pod-interface'
import * as Sequelize from 'sequelize'
// Don't use barrel, import just what we need
-import { Pod as FormatedPod } from '../../shared/models/pod.model'
+import { Pod as FormatedPod } from '../../../shared/models/pod.model'
export namespace PodMethods {
export type ToFormatedJSON = () => FormatedPod
import { map } from 'lodash'
import * as Sequelize from 'sequelize'
-import { FRIEND_SCORE, PODS_SCORE } from '../initializers'
-import { logger, isHostValid } from '../helpers'
+import { FRIEND_SCORE, PODS_SCORE } from '../../initializers'
+import { logger, isHostValid } from '../../helpers'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
PodClass,
PodInstance,
--- /dev/null
+export * from './request-interface'
+export * from './request-to-pod-interface'
+export * from './request-video-event-interface'
+export * from './request-video-qadu-interface'
import * as Sequelize from 'sequelize'
-import { PodInstance, PodAttributes } from './pod-interface'
+import { PodInstance, PodAttributes } from '../pod'
export type RequestsGrouped = {
[ podId: number ]: {
import * as Sequelize from 'sequelize'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
RequestToPodClass,
RequestToPodInstance,
import * as Sequelize from 'sequelize'
-import { VideoInstance } from './video-interface'
-import { PodInstance } from './pod-interface'
+import { VideoInstance } from '../video'
+import { PodInstance } from '../pod'
export type RequestsVideoEventGrouped = {
[ podId: number ]: {
import { values } from 'lodash'
import * as Sequelize from 'sequelize'
-import { database as db } from '../initializers/database'
-import { REQUEST_VIDEO_EVENT_TYPES } from '../initializers'
-import { isVideoEventCountValid } from '../helpers'
-import { addMethodsToModel } from './utils'
+import { database as db } from '../../initializers/database'
+import { REQUEST_VIDEO_EVENT_TYPES } from '../../initializers'
+import { isVideoEventCountValid } from '../../helpers'
+import { addMethodsToModel } from '../utils'
import {
RequestVideoEventClass,
RequestVideoEventInstance,
import * as Sequelize from 'sequelize'
-import { VideoInstance } from './video-interface'
-import { PodInstance } from './pod-interface'
+import { VideoInstance } from '../video'
+import { PodInstance } from '../pod'
export type RequestsVideoQaduGrouped = {
[ podId: number ]: {
import { values } from 'lodash'
import * as Sequelize from 'sequelize'
-import { database as db } from '../initializers/database'
-import { REQUEST_VIDEO_QADU_TYPES } from '../initializers'
-import { addMethodsToModel } from './utils'
+import { database as db } from '../../initializers/database'
+import { REQUEST_VIDEO_QADU_TYPES } from '../../initializers'
+import { addMethodsToModel } from '../utils'
import {
RequestVideoQaduClass,
RequestVideoQaduInstance,
import { values } from 'lodash'
import * as Sequelize from 'sequelize'
-import { database as db } from '../initializers/database'
-import { REQUEST_ENDPOINTS } from '../initializers'
-import { addMethodsToModel } from './utils'
+import { database as db } from '../../initializers/database'
+import { REQUEST_ENDPOINTS } from '../../initializers'
+import { addMethodsToModel } from '../utils'
import {
RequestClass,
RequestInstance,
--- /dev/null
+export * from './user-video-rate-interface'
+export * from './user-interface'
import * as Bluebird from 'bluebird'
// Don't use barrel, import just what we need
-import { User as FormatedUser } from '../../shared/models/user.model'
+import { User as FormatedUser } from '../../../shared/models/user.model'
export namespace UserMethods {
export type IsPasswordMatchCallback = (err: Error, same: boolean) => void
import { values } from 'lodash'
import * as Sequelize from 'sequelize'
-import { VIDEO_RATE_TYPES } from '../initializers'
+import { VIDEO_RATE_TYPES } from '../../initializers'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
UserVideoRateClass,
UserVideoRateInstance,
import { values } from 'lodash'
import * as Sequelize from 'sequelize'
-import { getSort } from './utils'
-import { USER_ROLES } from '../initializers'
+import { getSort } from '../utils'
+import { USER_ROLES } from '../../initializers'
import {
cryptPassword,
comparePassword,
isUserPasswordValid,
isUserUsernameValid,
isUserDisplayNSFWValid
-} from '../helpers'
+} from '../../helpers'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
UserClass,
UserInstance,
import * as Sequelize from 'sequelize'
-import { PodInstance } from './pod-interface'
+import { PodInstance } from '../pod'
export namespace AuthorMethods {
export type FindOrCreateAuthorCallback = (err: Error, authorInstance?: AuthorInstance) => void
import * as Sequelize from 'sequelize'
-import { isUserUsernameValid } from '../helpers'
+import { isUserUsernameValid } from '../../helpers'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
AuthorClass,
AuthorInstance,
--- /dev/null
+export * from './author-interface'
+export * from './tag-interface'
+export * from './video-abuse-interface'
+export * from './video-blacklist-interface'
+export * from './video-tag-interface'
+export * from './video-interface'
import { each } from 'async'
import * as Sequelize from 'sequelize'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
TagClass,
TagInstance,
import * as Sequelize from 'sequelize'
// Don't use barrel, import just what we need
-import { VideoAbuse as FormatedVideoAbuse } from '../../shared/models/video-abuse.model'
+import { VideoAbuse as FormatedVideoAbuse } from '../../../shared/models/video-abuse.model'
export namespace VideoAbuseMethods {
export type toFormatedJSON = () => FormatedVideoAbuse
import * as Sequelize from 'sequelize'
-import { CONFIG } from '../initializers'
-import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../helpers'
+import { CONFIG } from '../../initializers'
+import { isVideoAbuseReporterUsernameValid, isVideoAbuseReasonValid } from '../../helpers'
-import { addMethodsToModel, getSort } from './utils'
+import { addMethodsToModel, getSort } from '../utils'
import {
VideoAbuseClass,
VideoAbuseInstance,
import * as Sequelize from 'sequelize'
// Don't use barrel, import just what we need
-import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../shared/models/video-blacklist.model'
+import { BlacklistedVideo as FormatedBlacklistedVideo } from '../../../shared/models/video-blacklist.model'
export namespace BlacklistedVideoMethods {
export type ToFormatedJSON = () => FormatedBlacklistedVideo
import * as Sequelize from 'sequelize'
-import { addMethodsToModel, getSort } from './utils'
+import { addMethodsToModel, getSort } from '../utils'
import {
BlacklistedVideoClass,
BlacklistedVideoInstance,
import { VideoTagInstance } from './video-tag-interface'
// Don't use barrel, import just what we need
-import { Video as FormatedVideo } from '../../shared/models/video.model'
+import { Video as FormatedVideo } from '../../../shared/models/video.model'
export type FormatedAddRemoteVideo = {
name: string
import * as Sequelize from 'sequelize'
-import { addMethodsToModel } from './utils'
+import { addMethodsToModel } from '../utils'
import {
VideoTagClass,
VideoTagInstance,
import { join } from 'path'
import * as Sequelize from 'sequelize'
-import { database as db } from '../initializers/database'
+import { database as db } from '../../initializers/database'
import { VideoTagInstance } from './video-tag-interface'
import {
logger,
isVideoDescriptionValid,
isVideoInfoHashValid,
isVideoDurationValid
-} from '../helpers'
+} from '../../helpers'
import {
CONSTRAINTS_FIELDS,
CONFIG,
VIDEO_LICENCES,
VIDEO_LANGUAGES,
THUMBNAILS_SIZE
-} from '../initializers'
-import { JobScheduler, removeVideoToFriends } from '../lib'
+} from '../../initializers'
+import { JobScheduler, removeVideoToFriends } from '../../lib'
-import { addMethodsToModel, getSort } from './utils'
+import { addMethodsToModel, getSort } from '../utils'
import {
VideoClass,
VideoInstance,