aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-23 17:36:15 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:53 +0100
commit39445ead45aaaea801ec09991b8dd2464f722e47 (patch)
tree9306c6b89115dabdd4a7c31a59784134a0e1c804 /server
parent16b90975941b78d01d7202d441bf731a10048c16 (diff)
downloadPeerTube-39445ead45aaaea801ec09991b8dd2464f722e47.tar.gz
PeerTube-39445ead45aaaea801ec09991b8dd2464f722e47.tar.zst
PeerTube-39445ead45aaaea801ec09991b8dd2464f722e47.zip
Cleanup models
Diffstat (limited to 'server')
-rw-r--r--server/lib/video-channel.ts16
-rw-r--r--server/models/account/account-interface.ts4
-rw-r--r--server/models/account/account.ts28
-rw-r--r--server/models/oauth/oauth-token-interface.ts5
-rw-r--r--server/models/oauth/oauth-token.ts22
-rw-r--r--server/models/server/server-interface.ts38
-rw-r--r--server/models/server/server.ts181
-rw-r--r--server/models/video/video-blacklist-interface.ts11
-rw-r--r--server/models/video/video-blacklist.ts18
-rw-r--r--server/models/video/video-channel-interface.ts12
-rw-r--r--server/models/video/video-channel.ts13
-rw-r--r--server/models/video/video-interface.ts17
-rw-r--r--server/models/video/video.ts137
13 files changed, 51 insertions, 451 deletions
diff --git a/server/lib/video-channel.ts b/server/lib/video-channel.ts
index a939a23d5..beb01da9b 100644
--- a/server/lib/video-channel.ts
+++ b/server/lib/video-channel.ts
@@ -1,6 +1,5 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2import { VideoChannelCreate } from '../../shared/models' 2import { VideoChannelCreate } from '../../shared/models'
3import { logger } from '../helpers'
4import { database as db } from '../initializers' 3import { database as db } from '../initializers'
5import { AccountInstance } from '../models' 4import { AccountInstance } from '../models'
6import { getVideoChannelActivityPubUrl } from './activitypub/url' 5import { getVideoChannelActivityPubUrl } from './activitypub/url'
@@ -27,21 +26,8 @@ async function createVideoChannel (videoChannelInfo: VideoChannelCreate, account
27 return videoChannelCreated 26 return videoChannelCreated
28} 27}
29 28
30async function fetchVideoChannelByHostAndUUID (serverHost: string, uuid: string, t: Sequelize.Transaction) {
31 try {
32 const videoChannel = await db.VideoChannel.loadByHostAndUUID(serverHost, uuid, t)
33 if (!videoChannel) throw new Error('Video channel not found')
34
35 return videoChannel
36 } catch (err) {
37 logger.error('Cannot load video channel from host and uuid.', { error: err.stack, serverHost, uuid })
38 throw err
39 }
40}
41
42// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
43 30
44export { 31export {
45 createVideoChannel, 32 createVideoChannel
46 fetchVideoChannelByHostAndUUID
47} 33}
diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts
index e30260f76..2e4b0382d 100644
--- a/server/models/account/account-interface.ts
+++ b/server/models/account/account-interface.ts
@@ -10,10 +10,8 @@ export namespace AccountMethods {
10 export type Load = (id: number) => Bluebird<AccountInstance> 10 export type Load = (id: number) => Bluebird<AccountInstance>
11 export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance> 11 export type LoadByUUID = (uuid: string) => Bluebird<AccountInstance>
12 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance> 12 export type LoadByUrl = (url: string, transaction?: Sequelize.Transaction) => Bluebird<AccountInstance>
13 export type LoadAccountByServerAndUUID = (uuid: string, serverId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
14 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance> 13 export type LoadLocalByName = (name: string) => Bluebird<AccountInstance>
15 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance> 14 export type LoadByNameAndHost = (name: string, host: string) => Bluebird<AccountInstance>
16 export type ListOwned = () => Bluebird<AccountInstance[]>
17 15
18 export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor 16 export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
19 export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount 17 export type ToFormattedJSON = (this: AccountInstance) => FormattedAccount
@@ -26,13 +24,11 @@ export namespace AccountMethods {
26 24
27export interface AccountClass { 25export interface AccountClass {
28 loadApplication: AccountMethods.LoadApplication 26 loadApplication: AccountMethods.LoadApplication
29 loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID
30 load: AccountMethods.Load 27 load: AccountMethods.Load
31 loadByUUID: AccountMethods.LoadByUUID 28 loadByUUID: AccountMethods.LoadByUUID
32 loadByUrl: AccountMethods.LoadByUrl 29 loadByUrl: AccountMethods.LoadByUrl
33 loadLocalByName: AccountMethods.LoadLocalByName 30 loadLocalByName: AccountMethods.LoadLocalByName
34 loadByNameAndHost: AccountMethods.LoadByNameAndHost 31 loadByNameAndHost: AccountMethods.LoadByNameAndHost
35 listOwned: AccountMethods.ListOwned
36} 32}
37 33
38export interface AccountAttributes { 34export interface AccountAttributes {
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 9a2921501..f2bd325f3 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -20,14 +20,12 @@ import { addMethodsToModel } from '../utils'
20import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface' 20import { AccountAttributes, AccountInstance, AccountMethods } from './account-interface'
21 21
22let Account: Sequelize.Model<AccountInstance, AccountAttributes> 22let Account: Sequelize.Model<AccountInstance, AccountAttributes>
23let loadAccountByServerAndUUID: AccountMethods.LoadAccountByServerAndUUID
24let load: AccountMethods.Load 23let load: AccountMethods.Load
25let loadApplication: AccountMethods.LoadApplication 24let loadApplication: AccountMethods.LoadApplication
26let loadByUUID: AccountMethods.LoadByUUID 25let loadByUUID: AccountMethods.LoadByUUID
27let loadByUrl: AccountMethods.LoadByUrl 26let loadByUrl: AccountMethods.LoadByUrl
28let loadLocalByName: AccountMethods.LoadLocalByName 27let loadLocalByName: AccountMethods.LoadLocalByName
29let loadByNameAndHost: AccountMethods.LoadByNameAndHost 28let loadByNameAndHost: AccountMethods.LoadByNameAndHost
30let listOwned: AccountMethods.ListOwned
31let isOwned: AccountMethods.IsOwned 29let isOwned: AccountMethods.IsOwned
32let toActivityPubObject: AccountMethods.ToActivityPubObject 30let toActivityPubObject: AccountMethods.ToActivityPubObject
33let toFormattedJSON: AccountMethods.ToFormattedJSON 31let toFormattedJSON: AccountMethods.ToFormattedJSON
@@ -185,14 +183,12 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
185 183
186 const classMethods = [ 184 const classMethods = [
187 associate, 185 associate,
188 loadAccountByServerAndUUID,
189 loadApplication, 186 loadApplication,
190 load, 187 load,
191 loadByUUID, 188 loadByUUID,
192 loadByUrl, 189 loadByUrl,
193 loadLocalByName, 190 loadLocalByName,
194 loadByNameAndHost, 191 loadByNameAndHost
195 listOwned
196 ] 192 ]
197 const instanceMethods = [ 193 const instanceMethods = [
198 isOwned, 194 isOwned,
@@ -355,16 +351,6 @@ getPublicKeyUrl = function (this: AccountInstance) {
355 351
356// ------------------------------ STATICS ------------------------------ 352// ------------------------------ STATICS ------------------------------
357 353
358listOwned = function () {
359 const query: Sequelize.FindOptions<AccountAttributes> = {
360 where: {
361 serverId: null
362 }
363 }
364
365 return Account.findAll(query)
366}
367
368loadApplication = function () { 354loadApplication = function () {
369 return Account.findOne({ 355 return Account.findOne({
370 include: [ 356 include: [
@@ -441,15 +427,3 @@ loadByUrl = function (url: string, transaction?: Sequelize.Transaction) {
441 427
442 return Account.findOne(query) 428 return Account.findOne(query)
443} 429}
444
445loadAccountByServerAndUUID = function (uuid: string, serverId: number, transaction: Sequelize.Transaction) {
446 const query: Sequelize.FindOptions<AccountAttributes> = {
447 where: {
448 serverId,
449 uuid
450 },
451 transaction
452 }
453
454 return Account.find(query)
455}
diff --git a/server/models/oauth/oauth-token-interface.ts b/server/models/oauth/oauth-token-interface.ts
index ef97893c4..47d95d5fc 100644
--- a/server/models/oauth/oauth-token-interface.ts
+++ b/server/models/oauth/oauth-token-interface.ts
@@ -1,5 +1,5 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 1import * as Promise from 'bluebird'
2import * as Sequelize from 'sequelize'
3 3
4import { UserModel } from '../account/user-interface' 4import { UserModel } from '../account/user-interface'
5 5
@@ -18,15 +18,12 @@ export namespace OAuthTokenMethods {
18 export type GetByRefreshTokenAndPopulateClient = (refreshToken: string) => Promise<OAuthTokenInfo> 18 export type GetByRefreshTokenAndPopulateClient = (refreshToken: string) => Promise<OAuthTokenInfo>
19 export type GetByTokenAndPopulateUser = (bearerToken: string) => Promise<OAuthTokenInstance> 19 export type GetByTokenAndPopulateUser = (bearerToken: string) => Promise<OAuthTokenInstance>
20 export type GetByRefreshTokenAndPopulateUser = (refreshToken: string) => Promise<OAuthTokenInstance> 20 export type GetByRefreshTokenAndPopulateUser = (refreshToken: string) => Promise<OAuthTokenInstance>
21
22 export type RemoveByUserId = (userId) => Promise<number>
23} 21}
24 22
25export interface OAuthTokenClass { 23export interface OAuthTokenClass {
26 getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClient 24 getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClient
27 getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser 25 getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser
28 getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser 26 getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser
29 removeByUserId: OAuthTokenMethods.RemoveByUserId
30} 27}
31 28
32export interface OAuthTokenAttributes { 29export interface OAuthTokenAttributes {
diff --git a/server/models/oauth/oauth-token.ts b/server/models/oauth/oauth-token.ts
index c7afcc38c..a82bff130 100644
--- a/server/models/oauth/oauth-token.ts
+++ b/server/models/oauth/oauth-token.ts
@@ -3,19 +3,12 @@ import * as Sequelize from 'sequelize'
3import { logger } from '../../helpers' 3import { logger } from '../../helpers'
4 4
5import { addMethodsToModel } from '../utils' 5import { addMethodsToModel } from '../utils'
6import { 6import { OAuthTokenAttributes, OAuthTokenInfo, OAuthTokenInstance, OAuthTokenMethods } from './oauth-token-interface'
7 OAuthTokenInstance,
8 OAuthTokenAttributes,
9
10 OAuthTokenMethods,
11 OAuthTokenInfo
12} from './oauth-token-interface'
13 7
14let OAuthToken: Sequelize.Model<OAuthTokenInstance, OAuthTokenAttributes> 8let OAuthToken: Sequelize.Model<OAuthTokenInstance, OAuthTokenAttributes>
15let getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClient 9let getByRefreshTokenAndPopulateClient: OAuthTokenMethods.GetByRefreshTokenAndPopulateClient
16let getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser 10let getByTokenAndPopulateUser: OAuthTokenMethods.GetByTokenAndPopulateUser
17let getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser 11let getByRefreshTokenAndPopulateUser: OAuthTokenMethods.GetByRefreshTokenAndPopulateUser
18let removeByUserId: OAuthTokenMethods.RemoveByUserId
19 12
20export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 13export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
21 OAuthToken = sequelize.define<OAuthTokenInstance, OAuthTokenAttributes>('OAuthToken', 14 OAuthToken = sequelize.define<OAuthTokenInstance, OAuthTokenAttributes>('OAuthToken',
@@ -62,8 +55,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
62 55
63 getByRefreshTokenAndPopulateClient, 56 getByRefreshTokenAndPopulateClient,
64 getByTokenAndPopulateUser, 57 getByTokenAndPopulateUser,
65 getByRefreshTokenAndPopulateUser, 58 getByRefreshTokenAndPopulateUser
66 removeByUserId
67 ] 59 ]
68 addMethodsToModel(OAuthToken, classMethods) 60 addMethodsToModel(OAuthToken, classMethods)
69 61
@@ -170,13 +162,3 @@ getByRefreshTokenAndPopulateUser = function (refreshToken: string) {
170 return token 162 return token
171 }) 163 })
172} 164}
173
174removeByUserId = function (userId: number) {
175 const query = {
176 where: {
177 userId: userId
178 }
179 }
180
181 return OAuthToken.destroy(query)
182}
diff --git a/server/models/server/server-interface.ts b/server/models/server/server-interface.ts
index 806d052cb..be1a4917e 100644
--- a/server/models/server/server-interface.ts
+++ b/server/models/server/server-interface.ts
@@ -1,45 +1,13 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 1import * as Promise from 'bluebird'
3 2import * as Sequelize from 'sequelize'
4// Don't use barrel, import just what we need
5import { ResultList } from '../../../shared/models/result-list.model'
6 3
7export namespace ServerMethods { 4export namespace ServerMethods {
8 export type CountAll = () => Promise<number>
9
10 export type IncrementScores = (ids: number[], value: number) => Promise<[ number, ServerInstance[] ]>
11
12 export type List = () => Promise<ServerInstance[]>
13
14 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<ServerInstance> >
15
16 export type ListAllIds = (transaction: Sequelize.Transaction) => Promise<number[]>
17
18 export type ListRandomServerIdsWithRequest = (limit: number, tableWithServers: string, tableWithServersJoins: string) => Promise<number[]>
19
20 export type ListBadServers = () => Promise<ServerInstance[]> 5 export type ListBadServers = () => Promise<ServerInstance[]>
21 6 export type UpdateServersScoreAndRemoveBadOnes = (goodServers: number[], badServers: number[]) => void
22 export type Load = (id: number) => Promise<ServerInstance>
23
24 export type LoadByHost = (host: string) => Promise<ServerInstance>
25
26 export type RemoveAll = () => Promise<number>
27
28 export type UpdateServersScore = (goodServers: number[], badServers: number[]) => void
29} 7}
30 8
31export interface ServerClass { 9export interface ServerClass {
32 countAll: ServerMethods.CountAll 10 updateServersScoreAndRemoveBadOnes: ServerMethods.UpdateServersScoreAndRemoveBadOnes
33 incrementScores: ServerMethods.IncrementScores
34 list: ServerMethods.List
35 listForApi: ServerMethods.ListForApi
36 listAllIds: ServerMethods.ListAllIds
37 listRandomServerIdsWithRequest: ServerMethods.ListRandomServerIdsWithRequest
38 listBadServers: ServerMethods.ListBadServers
39 load: ServerMethods.Load
40 loadByHost: ServerMethods.LoadByHost
41 removeAll: ServerMethods.RemoveAll
42 updateServersScore: ServerMethods.UpdateServersScore
43} 11}
44 12
45export interface ServerAttributes { 13export interface ServerAttributes {
diff --git a/server/models/server/server.ts b/server/models/server/server.ts
index 26fa87550..75cd5f929 100644
--- a/server/models/server/server.ts
+++ b/server/models/server/server.ts
@@ -1,29 +1,11 @@
1import { map } from 'lodash'
2import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
3 2import { isHostValid, logger } from '../../helpers'
4import { FRIEND_SCORE, SERVERS_SCORE } from '../../initializers' 3import { FRIEND_SCORE, SERVERS_SCORE } from '../../initializers'
5import { logger, isHostValid } from '../../helpers' 4import { addMethodsToModel } from '../utils'
6 5import { ServerAttributes, ServerInstance, ServerMethods } from './server-interface'
7import { addMethodsToModel, getSort } from '../utils'
8import {
9 ServerInstance,
10 ServerAttributes,
11
12 ServerMethods
13} from './server-interface'
14 6
15let Server: Sequelize.Model<ServerInstance, ServerAttributes> 7let Server: Sequelize.Model<ServerInstance, ServerAttributes>
16let countAll: ServerMethods.CountAll 8let updateServersScoreAndRemoveBadOnes: ServerMethods.UpdateServersScoreAndRemoveBadOnes
17let incrementScores: ServerMethods.IncrementScores
18let list: ServerMethods.List
19let listForApi: ServerMethods.ListForApi
20let listAllIds: ServerMethods.ListAllIds
21let listRandomServerIdsWithRequest: ServerMethods.ListRandomServerIdsWithRequest
22let listBadServers: ServerMethods.ListBadServers
23let load: ServerMethods.Load
24let loadByHost: ServerMethods.LoadByHost
25let removeAll: ServerMethods.RemoveAll
26let updateServersScore: ServerMethods.UpdateServersScore
27 9
28export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 10export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
29 Server = sequelize.define<ServerInstance, ServerAttributes>('Server', 11 Server = sequelize.define<ServerInstance, ServerAttributes>('Server',
@@ -62,17 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
62 ) 44 )
63 45
64 const classMethods = [ 46 const classMethods = [
65 countAll, 47 listBadServers
66 incrementScores,
67 list,
68 listForApi,
69 listAllIds,
70 listRandomServerIdsWithRequest,
71 listBadServers,
72 load,
73 loadByHost,
74 updateServersScore,
75 removeAll
76 ] 48 ]
77 addMethodsToModel(Server, classMethods) 49 addMethodsToModel(Server, classMethods)
78 50
@@ -81,118 +53,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
81 53
82// ------------------------------ Statics ------------------------------ 54// ------------------------------ Statics ------------------------------
83 55
84countAll = function () { 56updateServersScoreAndRemoveBadOnes = function (goodServers: number[], badServers: number[]) {
85 return Server.count()
86}
87
88incrementScores = function (ids: number[], value: number) {
89 const update = {
90 score: Sequelize.literal('score +' + value)
91 }
92
93 const options = {
94 where: {
95 id: {
96 [Sequelize.Op.in]: ids
97 }
98 },
99 // In this case score is a literal and not an integer so we do not validate it
100 validate: false
101 }
102
103 return Server.update(update, options)
104}
105
106list = function () {
107 return Server.findAll()
108}
109
110listForApi = function (start: number, count: number, sort: string) {
111 const query = {
112 offset: start,
113 limit: count,
114 order: [ getSort(sort) ]
115 }
116
117 return Server.findAndCountAll(query).then(({ rows, count }) => {
118 return {
119 data: rows,
120 total: count
121 }
122 })
123}
124
125listAllIds = function (transaction: Sequelize.Transaction) {
126 const query = {
127 attributes: [ 'id' ],
128 transaction
129 }
130
131 return Server.findAll(query).then(servers => {
132 return map(servers, 'id')
133 })
134}
135
136listRandomServerIdsWithRequest = function (limit: number, tableWithServers: string, tableWithServersJoins: string) {
137 return Server.count().then(count => {
138 // Optimization...
139 if (count === 0) return []
140
141 let start = Math.floor(Math.random() * count) - limit
142 if (start < 0) start = 0
143
144 const subQuery = `(SELECT DISTINCT "${tableWithServers}"."serverId" FROM "${tableWithServers}" ${tableWithServersJoins})`
145 const query = {
146 attributes: [ 'id' ],
147 order: [
148 [ 'id', 'ASC' ]
149 ],
150 offset: start,
151 limit: limit,
152 where: {
153 id: {
154 [Sequelize.Op.in]: Sequelize.literal(subQuery)
155 }
156 }
157 }
158
159 return Server.findAll(query).then(servers => {
160 return map(servers, 'id')
161 })
162 })
163}
164
165listBadServers = function () {
166 const query = {
167 where: {
168 score: {
169 [Sequelize.Op.lte]: 0
170 }
171 }
172 }
173
174 return Server.findAll(query)
175}
176
177load = function (id: number) {
178 return Server.findById(id)
179}
180
181loadByHost = function (host: string) {
182 const query = {
183 where: {
184 host: host
185 }
186 }
187
188 return Server.findOne(query)
189}
190
191removeAll = function () {
192 return Server.destroy()
193}
194
195updateServersScore = function (goodServers: number[], badServers: number[]) {
196 logger.info('Updating %d good servers and %d bad servers scores.', goodServers.length, badServers.length) 57 logger.info('Updating %d good servers and %d bad servers scores.', goodServers.length, badServers.length)
197 58
198 if (goodServers.length !== 0) { 59 if (goodServers.length !== 0) {
@@ -231,3 +92,33 @@ async function removeBadServers () {
231 logger.error('Cannot remove bad servers.', err) 92 logger.error('Cannot remove bad servers.', err)
232 } 93 }
233} 94}
95
96function incrementScores (ids: number[], value: number) {
97 const update = {
98 score: Sequelize.literal('score +' + value)
99 }
100
101 const options = {
102 where: {
103 id: {
104 [Sequelize.Op.in]: ids
105 }
106 },
107 // In this case score is a literal and not an integer so we do not validate it
108 validate: false
109 }
110
111 return Server.update(update, options)
112}
113
114function listBadServers () {
115 const query = {
116 where: {
117 score: {
118 [Sequelize.Op.lte]: 0
119 }
120 }
121 }
122
123 return Server.findAll(query)
124}
diff --git a/server/models/video/video-blacklist-interface.ts b/server/models/video/video-blacklist-interface.ts
index 9d167c037..be2483d4c 100644
--- a/server/models/video/video-blacklist-interface.ts
+++ b/server/models/video/video-blacklist-interface.ts
@@ -10,24 +10,13 @@ import { BlacklistedVideo as FormattedBlacklistedVideo } from '../../../shared/m
10 10
11export namespace BlacklistedVideoMethods { 11export namespace BlacklistedVideoMethods {
12 export type ToFormattedJSON = (this: BlacklistedVideoInstance) => FormattedBlacklistedVideo 12 export type ToFormattedJSON = (this: BlacklistedVideoInstance) => FormattedBlacklistedVideo
13
14 export type CountTotal = () => Promise<number>
15
16 export type List = () => Promise<BlacklistedVideoInstance[]>
17
18 export type ListForApi = (start: number, count: number, sort: SortType) => Promise< ResultList<BlacklistedVideoInstance> > 13 export type ListForApi = (start: number, count: number, sort: SortType) => Promise< ResultList<BlacklistedVideoInstance> >
19
20 export type LoadById = (id: number) => Promise<BlacklistedVideoInstance>
21
22 export type LoadByVideoId = (id: number) => Promise<BlacklistedVideoInstance> 14 export type LoadByVideoId = (id: number) => Promise<BlacklistedVideoInstance>
23} 15}
24 16
25export interface BlacklistedVideoClass { 17export interface BlacklistedVideoClass {
26 toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON 18 toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON
27 countTotal: BlacklistedVideoMethods.CountTotal
28 list: BlacklistedVideoMethods.List
29 listForApi: BlacklistedVideoMethods.ListForApi 19 listForApi: BlacklistedVideoMethods.ListForApi
30 loadById: BlacklistedVideoMethods.LoadById
31 loadByVideoId: BlacklistedVideoMethods.LoadByVideoId 20 loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
32} 21}
33 22
diff --git a/server/models/video/video-blacklist.ts b/server/models/video/video-blacklist.ts
index 1c279b1ba..ae8286285 100644
--- a/server/models/video/video-blacklist.ts
+++ b/server/models/video/video-blacklist.ts
@@ -12,10 +12,7 @@ import {
12 12
13let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes> 13let BlacklistedVideo: Sequelize.Model<BlacklistedVideoInstance, BlacklistedVideoAttributes>
14let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON 14let toFormattedJSON: BlacklistedVideoMethods.ToFormattedJSON
15let countTotal: BlacklistedVideoMethods.CountTotal
16let list: BlacklistedVideoMethods.List
17let listForApi: BlacklistedVideoMethods.ListForApi 15let listForApi: BlacklistedVideoMethods.ListForApi
18let loadById: BlacklistedVideoMethods.LoadById
19let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId 16let loadByVideoId: BlacklistedVideoMethods.LoadByVideoId
20 17
21export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { 18export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) {
@@ -34,10 +31,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
34 const classMethods = [ 31 const classMethods = [
35 associate, 32 associate,
36 33
37 countTotal,
38 list,
39 listForApi, 34 listForApi,
40 loadById,
41 loadByVideoId 35 loadByVideoId
42 ] 36 ]
43 const instanceMethods = [ 37 const instanceMethods = [
@@ -83,14 +77,6 @@ function associate (models) {
83 }) 77 })
84} 78}
85 79
86countTotal = function () {
87 return BlacklistedVideo.count()
88}
89
90list = function () {
91 return BlacklistedVideo.findAll()
92}
93
94listForApi = function (start: number, count: number, sort: SortType) { 80listForApi = function (start: number, count: number, sort: SortType) {
95 const query = { 81 const query = {
96 offset: start, 82 offset: start,
@@ -107,10 +93,6 @@ listForApi = function (start: number, count: number, sort: SortType) {
107 }) 93 })
108} 94}
109 95
110loadById = function (id: number) {
111 return BlacklistedVideo.findById(id)
112}
113
114loadByVideoId = function (id: number) { 96loadByVideoId = function (id: number) {
115 const query = { 97 const query = {
116 where: { 98 where: {
diff --git a/server/models/video/video-channel-interface.ts b/server/models/video/video-channel-interface.ts
index 8ad3e5cb7..b409d1db3 100644
--- a/server/models/video/video-channel-interface.ts
+++ b/server/models/video/video-channel-interface.ts
@@ -1,13 +1,11 @@
1import * as Sequelize from 'sequelize'
2import * as Promise from 'bluebird' 1import * as Promise from 'bluebird'
2import * as Sequelize from 'sequelize'
3 3
4import { ResultList } from '../../../shared' 4import { ResultList } from '../../../shared'
5 5import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object'
6// Don't use barrel, import just what we need
7import { VideoChannel as FormattedVideoChannel } from '../../../shared/models/videos/video-channel.model' 6import { VideoChannel as FormattedVideoChannel } from '../../../shared/models/videos/video-channel.model'
8import { VideoInstance } from './video-interface'
9import { AccountInstance } from '../account/account-interface' 7import { AccountInstance } from '../account/account-interface'
10import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' 8import { VideoInstance } from './video-interface'
11 9
12export namespace VideoChannelMethods { 10export namespace VideoChannelMethods {
13 export type ToFormattedJSON = (this: VideoChannelInstance) => FormattedVideoChannel 11 export type ToFormattedJSON = (this: VideoChannelInstance) => FormattedVideoChannel
@@ -15,7 +13,6 @@ export namespace VideoChannelMethods {
15 export type IsOwned = (this: VideoChannelInstance) => boolean 13 export type IsOwned = (this: VideoChannelInstance) => boolean
16 14
17 export type CountByAccount = (accountId: number) => Promise<number> 15 export type CountByAccount = (accountId: number) => Promise<number>
18 export type ListOwned = () => Promise<VideoChannelInstance[]>
19 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoChannelInstance> > 16 export type ListForApi = (start: number, count: number, sort: string) => Promise< ResultList<VideoChannelInstance> >
20 export type LoadByIdAndAccount = (id: number, accountId: number) => Promise<VideoChannelInstance> 17 export type LoadByIdAndAccount = (id: number, accountId: number) => Promise<VideoChannelInstance>
21 export type ListByAccount = (accountId: number) => Promise< ResultList<VideoChannelInstance> > 18 export type ListByAccount = (accountId: number) => Promise< ResultList<VideoChannelInstance> >
@@ -32,10 +29,7 @@ export interface VideoChannelClass {
32 countByAccount: VideoChannelMethods.CountByAccount 29 countByAccount: VideoChannelMethods.CountByAccount
33 listForApi: VideoChannelMethods.ListForApi 30 listForApi: VideoChannelMethods.ListForApi
34 listByAccount: VideoChannelMethods.ListByAccount 31 listByAccount: VideoChannelMethods.ListByAccount
35 listOwned: VideoChannelMethods.ListOwned
36 loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount 32 loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
37 loadByUUID: VideoChannelMethods.LoadByUUID
38 loadByHostAndUUID: VideoChannelMethods.LoadByHostAndUUID
39 loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount 33 loadAndPopulateAccount: VideoChannelMethods.LoadAndPopulateAccount
40 loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount 34 loadByUUIDAndPopulateAccount: VideoChannelMethods.LoadByUUIDAndPopulateAccount
41 loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos 35 loadAndPopulateAccountAndVideos: VideoChannelMethods.LoadAndPopulateAccountAndVideos
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 93566a5c6..64130310d 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -12,7 +12,6 @@ let toFormattedJSON: VideoChannelMethods.ToFormattedJSON
12let toActivityPubObject: VideoChannelMethods.ToActivityPubObject 12let toActivityPubObject: VideoChannelMethods.ToActivityPubObject
13let isOwned: VideoChannelMethods.IsOwned 13let isOwned: VideoChannelMethods.IsOwned
14let countByAccount: VideoChannelMethods.CountByAccount 14let countByAccount: VideoChannelMethods.CountByAccount
15let listOwned: VideoChannelMethods.ListOwned
16let listForApi: VideoChannelMethods.ListForApi 15let listForApi: VideoChannelMethods.ListForApi
17let listByAccount: VideoChannelMethods.ListByAccount 16let listByAccount: VideoChannelMethods.ListByAccount
18let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount 17let loadByIdAndAccount: VideoChannelMethods.LoadByIdAndAccount
@@ -88,7 +87,6 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
88 87
89 listForApi, 88 listForApi,
90 listByAccount, 89 listByAccount,
91 listOwned,
92 loadByIdAndAccount, 90 loadByIdAndAccount,
93 loadAndPopulateAccount, 91 loadAndPopulateAccount,
94 loadByUUIDAndPopulateAccount, 92 loadByUUIDAndPopulateAccount,
@@ -192,17 +190,6 @@ countByAccount = function (accountId: number) {
192 return VideoChannel.count(query) 190 return VideoChannel.count(query)
193} 191}
194 192
195listOwned = function () {
196 const query = {
197 where: {
198 remote: false
199 },
200 include: [ VideoChannel['sequelize'].models.Account ]
201 }
202
203 return VideoChannel.findAll(query)
204}
205
206listForApi = function (start: number, count: number, sort: string) { 193listForApi = function (start: number, count: number, sort: string) {
207 const query = { 194 const query = {
208 offset: start, 195 offset: start,
diff --git a/server/models/video/video-interface.ts b/server/models/video/video-interface.ts
index 89e528acf..be140de86 100644
--- a/server/models/video/video-interface.ts
+++ b/server/models/video/video-interface.ts
@@ -3,13 +3,12 @@ import * as Sequelize from 'sequelize'
3import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' 3import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
4import { ResultList } from '../../../shared/models/result-list.model' 4import { ResultList } from '../../../shared/models/result-list.model'
5import { Video as FormattedVideo, VideoDetails as FormattedDetailsVideo } from '../../../shared/models/videos/video.model' 5import { Video as FormattedVideo, VideoDetails as FormattedDetailsVideo } from '../../../shared/models/videos/video.model'
6import { AccountVideoRateInstance } from '../account/account-video-rate-interface'
6 7
7import { TagAttributes, TagInstance } from './tag-interface' 8import { TagAttributes, TagInstance } from './tag-interface'
8import { VideoChannelInstance } from './video-channel-interface' 9import { VideoChannelInstance } from './video-channel-interface'
9import { VideoFileAttributes, VideoFileInstance } from './video-file-interface' 10import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
10import { VideoShareInstance } from './video-share-interface' 11import { VideoShareInstance } from './video-share-interface'
11import { UserVideoRate } from '../../../shared/models/videos/user-video-rate.model'
12import { AccountVideoRateInstance } from '../account/account-video-rate-interface'
13 12
14export namespace VideoMethods { 13export namespace VideoMethods {
15 export type GetThumbnailName = (this: VideoInstance) => string 14 export type GetThumbnailName = (this: VideoInstance) => string
@@ -40,12 +39,7 @@ export namespace VideoMethods {
40 export type GetLicenceLabel = (this: VideoInstance) => string 39 export type GetLicenceLabel = (this: VideoInstance) => string
41 export type GetLanguageLabel = (this: VideoInstance) => string 40 export type GetLanguageLabel = (this: VideoInstance) => string
42 41
43 // Return thumbnail name
44 export type GenerateThumbnailFromData = (video: VideoInstance, thumbnailData: string) => Promise<string>
45
46 export type List = () => Bluebird<VideoInstance[]> 42 export type List = () => Bluebird<VideoInstance[]>
47 export type ListOwnedAndPopulateAccountAndTags = () => Bluebird<VideoInstance[]>
48 export type ListOwnedByAccount = (account: string) => Bluebird<VideoInstance[]>
49 43
50 export type ListAllAndSharedByAccountForOutbox = ( 44 export type ListAllAndSharedByAccountForOutbox = (
51 accountId: number, 45 accountId: number,
@@ -65,9 +59,6 @@ export namespace VideoMethods {
65 export type Load = (id: number) => Bluebird<VideoInstance> 59 export type Load = (id: number) => Bluebird<VideoInstance>
66 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> 60 export type LoadByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
67 export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> 61 export type LoadByUrlAndPopulateAccount = (url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
68 export type LoadLocalVideoByUUID = (uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
69 export type LoadByHostAndUUID = (fromHost: string, uuid: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
70 export type LoadAndPopulateAccount = (id: number) => Bluebird<VideoInstance>
71 export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird<VideoInstance> 62 export type LoadAndPopulateAccountAndServerAndTags = (id: number) => Bluebird<VideoInstance>
72 export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird<VideoInstance> 63 export type LoadByUUIDAndPopulateAccountAndServerAndTags = (uuid: string) => Bluebird<VideoInstance>
73 export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance> 64 export type LoadByUUIDOrURL = (uuid: string, url: string, t?: Sequelize.Transaction) => Bluebird<VideoInstance>
@@ -79,21 +70,15 @@ export namespace VideoMethods {
79} 70}
80 71
81export interface VideoClass { 72export interface VideoClass {
82 generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
83 list: VideoMethods.List 73 list: VideoMethods.List
84 listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox 74 listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
85 listForApi: VideoMethods.ListForApi 75 listForApi: VideoMethods.ListForApi
86 listUserVideosForApi: VideoMethods.ListUserVideosForApi 76 listUserVideosForApi: VideoMethods.ListUserVideosForApi
87 listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
88 listOwnedByAccount: VideoMethods.ListOwnedByAccount
89 load: VideoMethods.Load 77 load: VideoMethods.Load
90 loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
91 loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags 78 loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
92 loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
93 loadByUUID: VideoMethods.LoadByUUID 79 loadByUUID: VideoMethods.LoadByUUID
94 loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount 80 loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
95 loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL 81 loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
96 loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
97 loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags 82 loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
98 searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags 83 searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
99} 84}
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 592fc2d59..e5fd92549 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1,8 +1,8 @@
1import * as Bluebird from 'bluebird'
1import { map, maxBy, truncate } from 'lodash' 2import { map, maxBy, truncate } from 'lodash'
2import * as magnetUtil from 'magnet-uri' 3import * as magnetUtil from 'magnet-uri'
3import * as parseTorrent from 'parse-torrent' 4import * as parseTorrent from 'parse-torrent'
4import { join } from 'path' 5import { join } from 'path'
5import * as safeBuffer from 'safe-buffer'
6import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
7import { VideoPrivacy, VideoResolution } from '../../../shared' 7import { VideoPrivacy, VideoResolution } from '../../../shared'
8import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' 8import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
@@ -25,6 +25,7 @@ import {
25 unlinkPromise, 25 unlinkPromise,
26 writeFilePromise 26 writeFilePromise
27} from '../../helpers' 27} from '../../helpers'
28import { activityPubCollection } from '../../helpers/activitypub'
28import { isVideoUrlValid } from '../../helpers/custom-validators/videos' 29import { isVideoUrlValid } from '../../helpers/custom-validators/videos'
29import { 30import {
30 API_VERSION, 31 API_VERSION,
@@ -39,17 +40,13 @@ import {
39 VIDEO_LICENCES, 40 VIDEO_LICENCES,
40 VIDEO_PRIVACIES 41 VIDEO_PRIVACIES
41} from '../../initializers' 42} from '../../initializers'
43import { sendDeleteVideo } from '../../lib/index'
42 44
43import { addMethodsToModel, getSort } from '../utils' 45import { addMethodsToModel, getSort } from '../utils'
44 46
45import { TagInstance } from './tag-interface' 47import { TagInstance } from './tag-interface'
46import { VideoFileInstance, VideoFileModel } from './video-file-interface' 48import { VideoFileInstance, VideoFileModel } from './video-file-interface'
47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface' 49import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'
48import { sendDeleteVideo } from '../../lib/index'
49import * as Bluebird from 'bluebird'
50import { activityPubCollection } from '../../helpers/activitypub'
51
52const Buffer = safeBuffer.Buffer
53 50
54let Video: Sequelize.Model<VideoInstance, VideoAttributes> 51let Video: Sequelize.Model<VideoInstance, VideoAttributes>
55let getOriginalFile: VideoMethods.GetOriginalFile 52let getOriginalFile: VideoMethods.GetOriginalFile
@@ -77,20 +74,14 @@ let getCategoryLabel: VideoMethods.GetCategoryLabel
77let getLicenceLabel: VideoMethods.GetLicenceLabel 74let getLicenceLabel: VideoMethods.GetLicenceLabel
78let getLanguageLabel: VideoMethods.GetLanguageLabel 75let getLanguageLabel: VideoMethods.GetLanguageLabel
79 76
80let generateThumbnailFromData: VideoMethods.GenerateThumbnailFromData
81let list: VideoMethods.List 77let list: VideoMethods.List
82let listForApi: VideoMethods.ListForApi 78let listForApi: VideoMethods.ListForApi
83let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox 79let listAllAndSharedByAccountForOutbox: VideoMethods.ListAllAndSharedByAccountForOutbox
84let listUserVideosForApi: VideoMethods.ListUserVideosForApi 80let listUserVideosForApi: VideoMethods.ListUserVideosForApi
85let loadByHostAndUUID: VideoMethods.LoadByHostAndUUID
86let listOwnedAndPopulateAccountAndTags: VideoMethods.ListOwnedAndPopulateAccountAndTags
87let listOwnedByAccount: VideoMethods.ListOwnedByAccount
88let load: VideoMethods.Load 81let load: VideoMethods.Load
89let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount 82let loadByUrlAndPopulateAccount: VideoMethods.LoadByUrlAndPopulateAccount
90let loadByUUID: VideoMethods.LoadByUUID 83let loadByUUID: VideoMethods.LoadByUUID
91let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL 84let loadByUUIDOrURL: VideoMethods.LoadByUUIDOrURL
92let loadLocalVideoByUUID: VideoMethods.LoadLocalVideoByUUID
93let loadAndPopulateAccount: VideoMethods.LoadAndPopulateAccount
94let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags 85let loadAndPopulateAccountAndServerAndTags: VideoMethods.LoadAndPopulateAccountAndServerAndTags
95let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags 86let loadByUUIDAndPopulateAccountAndServerAndTags: VideoMethods.LoadByUUIDAndPopulateAccountAndServerAndTags
96let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags 87let searchAndPopulateAccountAndServerAndTags: VideoMethods.SearchAndPopulateAccountAndServerAndTags
@@ -267,21 +258,15 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
267 const classMethods = [ 258 const classMethods = [
268 associate, 259 associate,
269 260
270 generateThumbnailFromData,
271 list, 261 list,
272 listAllAndSharedByAccountForOutbox, 262 listAllAndSharedByAccountForOutbox,
273 listForApi, 263 listForApi,
274 listUserVideosForApi, 264 listUserVideosForApi,
275 listOwnedAndPopulateAccountAndTags,
276 listOwnedByAccount,
277 load, 265 load,
278 loadByUrlAndPopulateAccount, 266 loadByUrlAndPopulateAccount,
279 loadAndPopulateAccount,
280 loadAndPopulateAccountAndServerAndTags, 267 loadAndPopulateAccountAndServerAndTags,
281 loadByHostAndUUID,
282 loadByUUIDOrURL, 268 loadByUUIDOrURL,
283 loadByUUID, 269 loadByUUID,
284 loadLocalVideoByUUID,
285 loadByUUIDAndPopulateAccountAndServerAndTags, 270 loadByUUIDAndPopulateAccountAndServerAndTags,
286 searchAndPopulateAccountAndServerAndTags 271 searchAndPopulateAccountAndServerAndTags
287 ] 272 ]
@@ -803,16 +788,6 @@ removeTorrent = function (this: VideoInstance, videoFile: VideoFileInstance) {
803 788
804// ------------------------------ STATICS ------------------------------ 789// ------------------------------ STATICS ------------------------------
805 790
806generateThumbnailFromData = function (video: VideoInstance, thumbnailData: string) {
807 // Creating the thumbnail for a remote video
808
809 const thumbnailName = video.getThumbnailName()
810 const thumbnailPath = join(CONFIG.STORAGE.THUMBNAILS_DIR, thumbnailName)
811 return writeFilePromise(thumbnailPath, Buffer.from(thumbnailData, 'binary')).then(() => {
812 return thumbnailName
813 })
814}
815
816list = function () { 791list = function () {
817 const query = { 792 const query = {
818 include: [ Video['sequelize'].models.VideoFile ] 793 include: [ Video['sequelize'].models.VideoFile ]
@@ -970,84 +945,6 @@ listForApi = function (start: number, count: number, sort: string) {
970 }) 945 })
971} 946}
972 947
973loadByHostAndUUID = function (fromHost: string, uuid: string, t?: Sequelize.Transaction) {
974 const query: Sequelize.FindOptions<VideoAttributes> = {
975 where: {
976 uuid
977 },
978 include: [
979 {
980 model: Video['sequelize'].models.VideoFile
981 },
982 {
983 model: Video['sequelize'].models.VideoChannel,
984 include: [
985 {
986 model: Video['sequelize'].models.Account,
987 include: [
988 {
989 model: Video['sequelize'].models.Server,
990 required: true,
991 where: {
992 host: fromHost
993 }
994 }
995 ]
996 }
997 ]
998 }
999 ]
1000 }
1001
1002 if (t !== undefined) query.transaction = t
1003
1004 return Video.findOne(query)
1005}
1006
1007listOwnedAndPopulateAccountAndTags = function () {
1008 const query = {
1009 where: {
1010 remote: false
1011 },
1012 include: [
1013 Video['sequelize'].models.VideoFile,
1014 {
1015 model: Video['sequelize'].models.VideoChannel,
1016 include: [ Video['sequelize'].models.Account ]
1017 },
1018 Video['sequelize'].models.Tag
1019 ]
1020 }
1021
1022 return Video.findAll(query)
1023}
1024
1025listOwnedByAccount = function (account: string) {
1026 const query = {
1027 where: {
1028 remote: false
1029 },
1030 include: [
1031 {
1032 model: Video['sequelize'].models.VideoFile
1033 },
1034 {
1035 model: Video['sequelize'].models.VideoChannel,
1036 include: [
1037 {
1038 model: Video['sequelize'].models.Account,
1039 where: {
1040 name: account
1041 }
1042 }
1043 ]
1044 }
1045 ]
1046 }
1047
1048 return Video.findAll(query)
1049}
1050
1051load = function (id: number) { 948load = function (id: number) {
1052 return Video.findById(id) 949 return Video.findById(id)
1053} 950}
@@ -1100,34 +997,6 @@ loadByUUIDOrURL = function (uuid: string, url: string, t?: Sequelize.Transaction
1100 return Video.findOne(query) 997 return Video.findOne(query)
1101} 998}
1102 999
1103loadLocalVideoByUUID = function (uuid: string, t?: Sequelize.Transaction) {
1104 const query: Sequelize.FindOptions<VideoAttributes> = {
1105 where: {
1106 uuid,
1107 remote: false
1108 },
1109 include: [ Video['sequelize'].models.VideoFile ]
1110 }
1111
1112 if (t !== undefined) query.transaction = t
1113
1114 return Video.findOne(query)
1115}
1116
1117loadAndPopulateAccount = function (id: number) {
1118 const options = {
1119 include: [
1120 Video['sequelize'].models.VideoFile,
1121 {
1122 model: Video['sequelize'].models.VideoChannel,
1123 include: [ Video['sequelize'].models.Account ]
1124 }
1125 ]
1126 }
1127
1128 return Video.findById(id, options)
1129}
1130
1131loadAndPopulateAccountAndServerAndTags = function (id: number) { 1000loadAndPopulateAccountAndServerAndTags = function (id: number) {
1132 const options = { 1001 const options = {
1133 include: [ 1002 include: [