14 } from 'sequelize-typescript'
15 import { CONSTRAINTS_FIELDS } from '../../initializers'
16 import { throwIfNotValid } from '../utils'
17 import { VideoModel } from './video'
18 import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
19 import { VideoImport, VideoImportState } from '../../../shared'
20 import { VideoChannelModel } from './video-channel'
21 import { AccountModel } from '../account/account'
26 model: () => VideoModel,
30 model: () => VideoChannelModel,
34 model: () => AccountModel,
45 tableName: 'videoImport',
48 fields: [ 'videoId' ],
53 export class VideoImportModel extends Model<VideoImportModel> {
61 @Is('VideoImportTargetUrl', value => throwIfNotValid(value, isVideoImportTargetUrlValid, 'targetUrl'))
62 @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEO_IMPORTS.URL.max))
67 @Is('VideoImportState', value => throwIfNotValid(value, isVideoImportStateValid, 'state'))
69 state: VideoImportState
73 @Column(DataType.TEXT)
76 @ForeignKey(() => VideoModel)
80 @BelongsTo(() => VideoModel, {
88 static loadAndPopulateVideo (id: number) {
89 return VideoImportModel.findById(id)
92 toFormattedJSON (): VideoImport {
93 const videoFormatOptions = {
94 additionalAttributes: { state: true, waitTranscoding: true, scheduledUpdate: true }
96 const video = Object.assign(this.Video.toFormattedJSON(videoFormatOptions), {
97 tags: this.Video.Tags.map(t => t.name)
101 targetUrl: this.targetUrl,