diff options
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index ab33b7c99..74a3a5d05 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -92,6 +92,7 @@ import { VideoFileModel } from './video-file' | |||
92 | import { VideoShareModel } from './video-share' | 92 | import { VideoShareModel } from './video-share' |
93 | import { VideoTagModel } from './video-tag' | 93 | import { VideoTagModel } from './video-tag' |
94 | import { ScheduleVideoUpdateModel } from './schedule-video-update' | 94 | import { ScheduleVideoUpdateModel } from './schedule-video-update' |
95 | import { VideoCaptionModel } from './video-caption' | ||
95 | 96 | ||
96 | export enum ScopeNames { | 97 | export enum ScopeNames { |
97 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', | 98 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', |
@@ -526,6 +527,17 @@ export class VideoModel extends Model<VideoModel> { | |||
526 | }) | 527 | }) |
527 | ScheduleVideoUpdate: ScheduleVideoUpdateModel | 528 | ScheduleVideoUpdate: ScheduleVideoUpdateModel |
528 | 529 | ||
530 | @HasMany(() => VideoCaptionModel, { | ||
531 | foreignKey: { | ||
532 | name: 'videoId', | ||
533 | allowNull: false | ||
534 | }, | ||
535 | onDelete: 'cascade', | ||
536 | hooks: true, | ||
537 | ['separate' as any]: true | ||
538 | }) | ||
539 | VideoCaptions: VideoCaptionModel[] | ||
540 | |||
529 | @BeforeDestroy | 541 | @BeforeDestroy |
530 | static async sendDelete (instance: VideoModel, options) { | 542 | static async sendDelete (instance: VideoModel, options) { |
531 | if (instance.isOwned()) { | 543 | if (instance.isOwned()) { |
@@ -550,7 +562,7 @@ export class VideoModel extends Model<VideoModel> { | |||
550 | } | 562 | } |
551 | 563 | ||
552 | @BeforeDestroy | 564 | @BeforeDestroy |
553 | static async removeFilesAndSendDelete (instance: VideoModel) { | 565 | static async removeFiles (instance: VideoModel) { |
554 | const tasks: Promise<any>[] = [] | 566 | const tasks: Promise<any>[] = [] |
555 | 567 | ||
556 | logger.debug('Removing files of video %s.', instance.url) | 568 | logger.debug('Removing files of video %s.', instance.url) |
@@ -616,6 +628,11 @@ export class VideoModel extends Model<VideoModel> { | |||
616 | }, | 628 | }, |
617 | include: [ | 629 | include: [ |
618 | { | 630 | { |
631 | attributes: [ 'language' ], | ||
632 | model: VideoCaptionModel.unscoped(), | ||
633 | required: false | ||
634 | }, | ||
635 | { | ||
619 | attributes: [ 'id', 'url' ], | 636 | attributes: [ 'id', 'url' ], |
620 | model: VideoShareModel.unscoped(), | 637 | model: VideoShareModel.unscoped(), |
621 | required: false, | 638 | required: false, |
@@ -1028,15 +1045,15 @@ export class VideoModel extends Model<VideoModel> { | |||
1028 | videoFile.infoHash = parsedTorrent.infoHash | 1045 | videoFile.infoHash = parsedTorrent.infoHash |
1029 | } | 1046 | } |
1030 | 1047 | ||
1031 | getEmbedPath () { | 1048 | getEmbedStaticPath () { |
1032 | return '/videos/embed/' + this.uuid | 1049 | return '/videos/embed/' + this.uuid |
1033 | } | 1050 | } |
1034 | 1051 | ||
1035 | getThumbnailPath () { | 1052 | getThumbnailStaticPath () { |
1036 | return join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName()) | 1053 | return join(STATIC_PATHS.THUMBNAILS, this.getThumbnailName()) |
1037 | } | 1054 | } |
1038 | 1055 | ||
1039 | getPreviewPath () { | 1056 | getPreviewStaticPath () { |
1040 | return join(STATIC_PATHS.PREVIEWS, this.getPreviewName()) | 1057 | return join(STATIC_PATHS.PREVIEWS, this.getPreviewName()) |
1041 | } | 1058 | } |
1042 | 1059 | ||
@@ -1077,9 +1094,9 @@ export class VideoModel extends Model<VideoModel> { | |||
1077 | views: this.views, | 1094 | views: this.views, |
1078 | likes: this.likes, | 1095 | likes: this.likes, |
1079 | dislikes: this.dislikes, | 1096 | dislikes: this.dislikes, |
1080 | thumbnailPath: this.getThumbnailPath(), | 1097 | thumbnailPath: this.getThumbnailStaticPath(), |
1081 | previewPath: this.getPreviewPath(), | 1098 | previewPath: this.getPreviewStaticPath(), |
1082 | embedPath: this.getEmbedPath(), | 1099 | embedPath: this.getEmbedStaticPath(), |
1083 | createdAt: this.createdAt, | 1100 | createdAt: this.createdAt, |
1084 | updatedAt: this.updatedAt, | 1101 | updatedAt: this.updatedAt, |
1085 | publishedAt: this.publishedAt, | 1102 | publishedAt: this.publishedAt, |
@@ -1247,6 +1264,14 @@ export class VideoModel extends Model<VideoModel> { | |||
1247 | href: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid | 1264 | href: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid |
1248 | }) | 1265 | }) |
1249 | 1266 | ||
1267 | const subtitleLanguage = [] | ||
1268 | for (const caption of this.VideoCaptions) { | ||
1269 | subtitleLanguage.push({ | ||
1270 | identifier: caption.language, | ||
1271 | name: VideoCaptionModel.getLanguageLabel(caption.language) | ||
1272 | }) | ||
1273 | } | ||
1274 | |||
1250 | return { | 1275 | return { |
1251 | type: 'Video' as 'Video', | 1276 | type: 'Video' as 'Video', |
1252 | id: this.url, | 1277 | id: this.url, |
@@ -1267,6 +1292,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1267 | mediaType: 'text/markdown', | 1292 | mediaType: 'text/markdown', |
1268 | content: this.getTruncatedDescription(), | 1293 | content: this.getTruncatedDescription(), |
1269 | support: this.support, | 1294 | support: this.support, |
1295 | subtitleLanguage, | ||
1270 | icon: { | 1296 | icon: { |
1271 | type: 'Image', | 1297 | type: 'Image', |
1272 | url: this.getThumbnailUrl(baseUrlHttp), | 1298 | url: this.getThumbnailUrl(baseUrlHttp), |