aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-import.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-07 10:07:53 +0200
committerChocobozzz <me@florianbigard.com>2018-08-08 09:30:31 +0200
commita84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4 (patch)
treecf2feafcfadb5b6e9784c86d67e692db8d599b7d /server/models/video/video-import.ts
parent990b6a0b0c4fbebc165e5cf7cec8fbc1cbaa6c66 (diff)
downloadPeerTube-a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4.tar.gz
PeerTube-a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4.tar.zst
PeerTube-a84b8fa5cf6e4cafb841af3db9bdfcc9531c09a4.zip
Add import.video.torrent configuration
Diffstat (limited to 'server/models/video/video-import.ts')
-rw-r--r--server/models/video/video-import.ts83
1 files changed, 34 insertions, 49 deletions
diff --git a/server/models/video/video-import.ts b/server/models/video/video-import.ts
index d6c02e5ac..b794d8324 100644
--- a/server/models/video/video-import.ts
+++ b/server/models/video/video-import.ts
@@ -15,34 +15,21 @@ import {
15} from 'sequelize-typescript' 15} from 'sequelize-typescript'
16import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers' 16import { CONSTRAINTS_FIELDS, VIDEO_IMPORT_STATES } from '../../initializers'
17import { getSort, throwIfNotValid } from '../utils' 17import { getSort, throwIfNotValid } from '../utils'
18import { VideoModel } from './video' 18import { ScopeNames as VideoModelScopeNames, VideoModel } from './video'
19import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports' 19import { isVideoImportStateValid, isVideoImportTargetUrlValid } from '../../helpers/custom-validators/video-imports'
20import { VideoImport, VideoImportState } from '../../../shared' 20import { VideoImport, VideoImportState } from '../../../shared'
21import { VideoChannelModel } from './video-channel'
22import { AccountModel } from '../account/account'
23import { TagModel } from './tag'
24import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos' 21import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos'
22import { UserModel } from '../account/user'
25 23
26@DefaultScope({ 24@DefaultScope({
27 include: [ 25 include: [
28 { 26 {
29 model: () => VideoModel, 27 model: () => UserModel.unscoped(),
30 required: false, 28 required: true
31 include: [ 29 },
32 { 30 {
33 model: () => VideoChannelModel, 31 model: () => VideoModel.scope([ VideoModelScopeNames.WITH_ACCOUNT_DETAILS, VideoModelScopeNames.WITH_TAGS]),
34 required: true, 32 required: false
35 include: [
36 {
37 model: () => AccountModel,
38 required: true
39 }
40 ]
41 },
42 {
43 model: () => TagModel
44 }
45 ]
46 } 33 }
47 ] 34 ]
48}) 35})
@@ -53,6 +40,9 @@ import { isVideoMagnetUriValid } from '../../helpers/custom-validators/videos'
53 { 40 {
54 fields: [ 'videoId' ], 41 fields: [ 'videoId' ],
55 unique: true 42 unique: true
43 },
44 {
45 fields: [ 'userId' ]
56 } 46 }
57 ] 47 ]
58}) 48})
@@ -91,6 +81,18 @@ export class VideoImportModel extends Model<VideoImportModel> {
91 @Column(DataType.TEXT) 81 @Column(DataType.TEXT)
92 error: string 82 error: string
93 83
84 @ForeignKey(() => UserModel)
85 @Column
86 userId: number
87
88 @BelongsTo(() => UserModel, {
89 foreignKey: {
90 allowNull: false
91 },
92 onDelete: 'cascade'
93 })
94 User: UserModel
95
94 @ForeignKey(() => VideoModel) 96 @ForeignKey(() => VideoModel)
95 @Column 97 @Column
96 videoId: number 98 videoId: number
@@ -116,41 +118,24 @@ export class VideoImportModel extends Model<VideoImportModel> {
116 return VideoImportModel.findById(id) 118 return VideoImportModel.findById(id)
117 } 119 }
118 120
119 static listUserVideoImportsForApi (accountId: number, start: number, count: number, sort: string) { 121 static listUserVideoImportsForApi (userId: number, start: number, count: number, sort: string) {
120 const query = { 122 const query = {
121 distinct: true, 123 distinct: true,
122 offset: start,
123 limit: count,
124 order: getSort(sort),
125 include: [ 124 include: [
126 { 125 {
127 model: VideoModel, 126 model: UserModel.unscoped(), // FIXME: Without this, sequelize try to COUNT(DISTINCT(*)) which is an invalid SQL query
128 required: false, 127 required: true
129 include: [
130 {
131 model: VideoChannelModel,
132 required: true,
133 include: [
134 {
135 model: AccountModel,
136 required: true,
137 where: {
138 id: accountId
139 }
140 }
141 ]
142 },
143 {
144 model: TagModel,
145 required: false
146 }
147 ]
148 } 128 }
149 ] 129 ],
130 offset: start,
131 limit: count,
132 order: getSort(sort),
133 where: {
134 userId
135 }
150 } 136 }
151 137
152 return VideoImportModel.unscoped() 138 return VideoImportModel.findAndCountAll(query)
153 .findAndCountAll(query)
154 .then(({ rows, count }) => { 139 .then(({ rows, count }) => {
155 return { 140 return {
156 data: rows, 141 data: rows,