aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts72
1 files changed, 33 insertions, 39 deletions
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,