aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/account/account-interface.ts4
-rw-r--r--server/models/account/account.ts17
-rw-r--r--server/models/job/job-interface.ts2
-rw-r--r--server/models/video/video-channel.ts14
-rw-r--r--server/models/video/video.ts72
5 files changed, 53 insertions, 56 deletions
diff --git a/server/models/account/account-interface.ts b/server/models/account/account-interface.ts
index 2ef3e2246..a662eb992 100644
--- a/server/models/account/account-interface.ts
+++ b/server/models/account/account-interface.ts
@@ -13,8 +13,8 @@ export namespace AccountMethods {
13 export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance> 13 export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
14 export type LoadLocalAccountByName = (name: string) => Bluebird<AccountInstance> 14 export type LoadLocalAccountByName = (name: string) => Bluebird<AccountInstance>
15 export type ListOwned = () => Bluebird<AccountInstance[]> 15 export type ListOwned = () => Bluebird<AccountInstance[]>
16 export type ListFollowerUrlsForApi = (name: string, start: number, count: number) => Promise< ResultList<string> > 16 export type ListFollowerUrlsForApi = (name: string, start: number, count?: number) => Promise< ResultList<string> >
17 export type ListFollowingUrlsForApi = (name: string, start: number, count: number) => Promise< ResultList<string> > 17 export type ListFollowingUrlsForApi = (name: string, start: number, count?: number) => Promise< ResultList<string> >
18 18
19 export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor 19 export type ToActivityPubObject = (this: AccountInstance) => ActivityPubActor
20 export type IsOwned = (this: AccountInstance) => boolean 20 export type IsOwned = (this: AccountInstance) => boolean
diff --git a/server/models/account/account.ts b/server/models/account/account.ts
index 00c0aefd4..a79e13880 100644
--- a/server/models/account/account.ts
+++ b/server/models/account/account.ts
@@ -268,14 +268,15 @@ function afterDestroy (account: AccountInstance) {
268 uuid: account.uuid 268 uuid: account.uuid
269 } 269 }
270 270
271 return removeVideoAccountToFriends(removeVideoAccountToFriendsParams) 271 // FIXME: remove account in followers
272 // return removeVideoAccountToFriends(removeVideoAccountToFriendsParams)
272 } 273 }
273 274
274 return undefined 275 return undefined
275} 276}
276 277
277toActivityPubObject = function (this: AccountInstance) { 278toActivityPubObject = function (this: AccountInstance) {
278 const type = this.podId ? 'Application' : 'Person' 279 const type = this.podId ? 'Application' as 'Application' : 'Person' as 'Person'
279 280
280 const json = { 281 const json = {
281 type, 282 type,
@@ -346,11 +347,11 @@ listOwned = function () {
346 return Account.findAll(query) 347 return Account.findAll(query)
347} 348}
348 349
349listFollowerUrlsForApi = function (name: string, start: number, count: number) { 350listFollowerUrlsForApi = function (name: string, start: number, count?: number) {
350 return createListFollowForApiQuery('followers', name, start, count) 351 return createListFollowForApiQuery('followers', name, start, count)
351} 352}
352 353
353listFollowingUrlsForApi = function (name: string, start: number, count: number) { 354listFollowingUrlsForApi = function (name: string, start: number, count?: number) {
354 return createListFollowForApiQuery('following', name, start, count) 355 return createListFollowForApiQuery('following', name, start, count)
355} 356}
356 357
@@ -405,7 +406,7 @@ loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Se
405 406
406// ------------------------------ UTILS ------------------------------ 407// ------------------------------ UTILS ------------------------------
407 408
408async function createListFollowForApiQuery (type: 'followers' | 'following', name: string, start: number, count: number) { 409async function createListFollowForApiQuery (type: 'followers' | 'following', name: string, start: number, count?: number) {
409 let firstJoin: string 410 let firstJoin: string
410 let secondJoin: string 411 let secondJoin: string
411 412
@@ -421,11 +422,13 @@ async function createListFollowForApiQuery (type: 'followers' | 'following', nam
421 const tasks: Promise<any>[] = [] 422 const tasks: Promise<any>[] = []
422 423
423 for (const selection of selections) { 424 for (const selection of selections) {
424 const query = 'SELECT ' + selection + ' FROM "Account" ' + 425 let query = 'SELECT ' + selection + ' FROM "Account" ' +
425 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' + 426 'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' +
426 'INNER JOIN "Account" AS "Followers" ON "Followers"."id" = "AccountFollower"."' + secondJoin + '" ' + 427 'INNER JOIN "Account" AS "Followers" ON "Followers"."id" = "AccountFollower"."' + secondJoin + '" ' +
427 'WHERE "Account"."name" = \'$name\' ' + 428 'WHERE "Account"."name" = \'$name\' ' +
428 'LIMIT ' + start + ', ' + count 429 'LIMIT ' + start
430
431 if (count !== undefined) query += ', ' + count
429 432
430 const options = { 433 const options = {
431 bind: { name }, 434 bind: { name },
diff --git a/server/models/job/job-interface.ts b/server/models/job/job-interface.ts
index 163930a4f..411a05029 100644
--- a/server/models/job/job-interface.ts
+++ b/server/models/job/job-interface.ts
@@ -14,7 +14,7 @@ export interface JobClass {
14export interface JobAttributes { 14export interface JobAttributes {
15 state: JobState 15 state: JobState
16 handlerName: string 16 handlerName: string
17 handlerInputData: object 17 handlerInputData: any
18} 18}
19 19
20export interface JobInstance extends JobClass, JobAttributes, Sequelize.Instance<JobAttributes> { 20export interface JobInstance extends JobClass, JobAttributes, Sequelize.Instance<JobAttributes> {
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 93a611fa0..183ff3436 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -1,7 +1,6 @@
1import * as Sequelize from 'sequelize' 1import * as Sequelize from 'sequelize'
2 2
3import { isVideoChannelNameValid, isVideoChannelDescriptionValid } from '../../helpers' 3import { isVideoChannelNameValid, isVideoChannelDescriptionValid } from '../../helpers'
4import { removeVideoChannelToFriends } from '../../lib'
5 4
6import { addMethodsToModel, getSort } from '../utils' 5import { addMethodsToModel, getSort } from '../utils'
7import { 6import {
@@ -143,12 +142,13 @@ toFormattedJSON = function (this: VideoChannelInstance) {
143 142
144toActivityPubObject = function (this: VideoChannelInstance) { 143toActivityPubObject = function (this: VideoChannelInstance) {
145 const json = { 144 const json = {
145 type: 'VideoChannel' as 'VideoChannel',
146 id: this.url,
146 uuid: this.uuid, 147 uuid: this.uuid,
148 content: this.description,
147 name: this.name, 149 name: this.name,
148 description: this.description, 150 published: this.createdAt,
149 createdAt: this.createdAt, 151 updated: this.updatedAt
150 updatedAt: this.updatedAt,
151 ownerUUID: this.Account.uuid
152 } 152 }
153 153
154 return json 154 return json
@@ -180,7 +180,7 @@ function afterDestroy (videoChannel: VideoChannelInstance) {
180 uuid: videoChannel.uuid 180 uuid: videoChannel.uuid
181 } 181 }
182 182
183 return removeVideoChannelToFriends(removeVideoChannelToFriendsParams) 183 // FIXME: send remove event to followers
184 } 184 }
185 185
186 return undefined 186 return undefined
@@ -277,7 +277,7 @@ loadByUUIDOrUrl = function (uuid: string, url: string, t?: Sequelize.Transaction
277 { uuid }, 277 { uuid },
278 { url } 278 { url }
279 ] 279 ]
280 }, 280 }
281 } 281 }
282 282
283 if (t !== undefined) query.transaction = t 283 if (t !== undefined) query.transaction = t
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index b5d333347..10ae5097c 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1,58 +1,52 @@
1import * as safeBuffer from 'safe-buffer'
2const Buffer = safeBuffer.Buffer
3import * as magnetUtil from 'magnet-uri'
4import { map, maxBy, truncate } from 'lodash' 1import { map, maxBy, truncate } from 'lodash'
2import * as magnetUtil from 'magnet-uri'
5import * as parseTorrent from 'parse-torrent' 3import * as parseTorrent from 'parse-torrent'
6import { join } from 'path' 4import { join } from 'path'
5import * as safeBuffer from 'safe-buffer'
7import * as Sequelize from 'sequelize' 6import * as Sequelize from 'sequelize'
8 7import { VideoPrivacy, VideoResolution } from '../../../shared'
9import { TagInstance } from './tag-interface' 8import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object'
10import { 9import {
11 logger, 10 createTorrentPromise,
12 isVideoNameValid, 11 generateImageFromVideoFile,
12 getActivityPubUrl,
13 getVideoFileHeight,
13 isVideoCategoryValid, 14 isVideoCategoryValid,
14 isVideoLicenceValid,
15 isVideoLanguageValid,
16 isVideoNSFWValid,
17 isVideoDescriptionValid, 15 isVideoDescriptionValid,
18 isVideoDurationValid, 16 isVideoDurationValid,
17 isVideoLanguageValid,
18 isVideoLicenceValid,
19 isVideoNameValid,
20 isVideoNSFWValid,
19 isVideoPrivacyValid, 21 isVideoPrivacyValid,
20 readFileBufferPromise, 22 logger,
21 unlinkPromise,
22 renamePromise, 23 renamePromise,
23 writeFilePromise,
24 createTorrentPromise,
25 statPromise, 24 statPromise,
26 generateImageFromVideoFile,
27 transcode, 25 transcode,
28 getVideoFileHeight, 26 unlinkPromise,
29 getActivityPubUrl 27 writeFilePromise
30} from '../../helpers' 28} from '../../helpers'
31import { 29import {
30 API_VERSION,
32 CONFIG, 31 CONFIG,
32 CONSTRAINTS_FIELDS,
33 PREVIEWS_SIZE,
33 REMOTE_SCHEME, 34 REMOTE_SCHEME,
34 STATIC_PATHS, 35 STATIC_PATHS,
36 THUMBNAILS_SIZE,
35 VIDEO_CATEGORIES, 37 VIDEO_CATEGORIES,
36 VIDEO_LICENCES,
37 VIDEO_LANGUAGES, 38 VIDEO_LANGUAGES,
38 THUMBNAILS_SIZE, 39 VIDEO_LICENCES,
39 PREVIEWS_SIZE,
40 CONSTRAINTS_FIELDS,
41 API_VERSION,
42 VIDEO_PRIVACIES 40 VIDEO_PRIVACIES
43} from '../../initializers' 41} from '../../initializers'
44import { removeVideoToFriends } from '../../lib'
45import { VideoResolution, VideoPrivacy } from '../../../shared'
46import { VideoFileInstance, VideoFileModel } from './video-file-interface'
47 42
48import { addMethodsToModel, getSort } from '../utils' 43import { addMethodsToModel, getSort } from '../utils'
49import {
50 VideoInstance,
51 VideoAttributes,
52 44
53 VideoMethods 45import { TagInstance } from './tag-interface'
54} from './video-interface' 46import { VideoFileInstance, VideoFileModel } from './video-file-interface'
55import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' 47import { VideoAttributes, VideoInstance, VideoMethods } from './video-interface'
48
49const Buffer = safeBuffer.Buffer
56 50
57let Video: Sequelize.Model<VideoInstance, VideoAttributes> 51let Video: Sequelize.Model<VideoInstance, VideoAttributes>
58let getOriginalFile: VideoMethods.GetOriginalFile 52let getOriginalFile: VideoMethods.GetOriginalFile
@@ -374,8 +368,8 @@ function afterDestroy (video: VideoInstance) {
374 } 368 }
375 369
376 tasks.push( 370 tasks.push(
377 video.removePreview(), 371 video.removePreview()
378 removeVideoToFriends(removeVideoToFriendsParams) 372 // FIXME: remove video for followers
379 ) 373 )
380 374
381 // Remove physical files and torrents 375 // Remove physical files and torrents
@@ -566,7 +560,7 @@ toActivityPubObject = function (this: VideoInstance) {
566 const { baseUrlHttp, baseUrlWs } = getBaseUrls(this) 560 const { baseUrlHttp, baseUrlWs } = getBaseUrls(this)
567 561
568 const tag = this.Tags.map(t => ({ 562 const tag = this.Tags.map(t => ({
569 type: 'Hashtag', 563 type: 'Hashtag' as 'Hashtag',
570 name: t.name 564 name: t.name
571 })) 565 }))
572 566
@@ -596,7 +590,7 @@ toActivityPubObject = function (this: VideoInstance) {
596 } 590 }
597 591
598 const videoObject: VideoTorrentObject = { 592 const videoObject: VideoTorrentObject = {
599 type: 'Video', 593 type: 'Video' as 'Video',
600 id: getActivityPubUrl('video', this.uuid), 594 id: getActivityPubUrl('video', this.uuid),
601 name: this.name, 595 name: this.name,
602 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration 596 // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration
@@ -604,15 +598,15 @@ toActivityPubObject = function (this: VideoInstance) {
604 uuid: this.uuid, 598 uuid: this.uuid,
605 tag, 599 tag,
606 category: { 600 category: {
607 id: this.category, 601 identifier: this.category + '',
608 label: this.getCategoryLabel() 602 name: this.getCategoryLabel()
609 }, 603 },
610 licence: { 604 licence: {
611 id: this.licence, 605 identifier: this.licence + '',
612 name: this.getLicenceLabel() 606 name: this.getLicenceLabel()
613 }, 607 },
614 language: { 608 language: {
615 id: this.language, 609 identifier: this.language + '',
616 name: this.getLanguageLabel() 610 name: this.getLanguageLabel()
617 }, 611 },
618 views: this.views, 612 views: this.views,