aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-30 11:53:38 +0100
committerChocobozzz <me@florianbigard.com>2020-01-30 11:53:38 +0100
commitca6d36227a9273f616a462d3aad6a721ab5dd627 (patch)
treea1610578e719ddb2c58199f06dd4eae436d25c0a /server/models/video
parent215304eaa06020f27152108567c6a9de16b220d3 (diff)
downloadPeerTube-ca6d36227a9273f616a462d3aad6a721ab5dd627.tar.gz
PeerTube-ca6d36227a9273f616a462d3aad6a721ab5dd627.tar.zst
PeerTube-ca6d36227a9273f616a462d3aad6a721ab5dd627.zip
Add url field in caption and use it for thumbnails
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/thumbnail.ts13
-rw-r--r--server/models/video/video-caption.ts26
-rw-r--r--server/models/video/video-format-utils.ts15
-rw-r--r--server/models/video/video.ts2
4 files changed, 39 insertions, 17 deletions
diff --git a/server/models/video/thumbnail.ts b/server/models/video/thumbnail.ts
index 3b011b1d2..b69bc0872 100644
--- a/server/models/video/thumbnail.ts
+++ b/server/models/video/thumbnail.ts
@@ -19,6 +19,8 @@ import { CONFIG } from '../../initializers/config'
19import { VideoModel } from './video' 19import { VideoModel } from './video'
20import { VideoPlaylistModel } from './video-playlist' 20import { VideoPlaylistModel } from './video-playlist'
21import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' 21import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type'
22import { MVideoAccountLight } from '@server/typings/models'
23import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
22 24
23@Table({ 25@Table({
24 tableName: 'thumbnail', 26 tableName: 'thumbnail',
@@ -126,11 +128,14 @@ export class ThumbnailModel extends Model<ThumbnailModel> {
126 return videoUUID + '.jpg' 128 return videoUUID + '.jpg'
127 } 129 }
128 130
129 getFileUrl (isLocal: boolean) { 131 getFileUrl (video: MVideoAccountLight) {
130 if (isLocal === false) return this.fileUrl 132 const staticPath = ThumbnailModel.types[this.type].staticPath + this.filename
131 133
132 const staticPath = ThumbnailModel.types[this.type].staticPath 134 if (video.isOwned()) return WEBSERVER.URL + staticPath
133 return WEBSERVER.URL + staticPath + this.filename 135 if (this.fileUrl) return this.fileUrl
136
137 // Fallback if we don't have a file URL
138 return buildRemoteVideoBaseUrl(video, staticPath)
134 } 139 }
135 140
136 getPath () { 141 getPath () {
diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts
index 6335d44e4..1307c27f1 100644
--- a/server/models/video/video-caption.ts
+++ b/server/models/video/video-caption.ts
@@ -4,7 +4,7 @@ import {
4 BeforeDestroy, 4 BeforeDestroy,
5 BelongsTo, 5 BelongsTo,
6 Column, 6 Column,
7 CreatedAt, 7 CreatedAt, DataType,
8 ForeignKey, 8 ForeignKey,
9 Is, 9 Is,
10 Model, 10 Model,
@@ -16,13 +16,14 @@ import { buildWhereIdOrUUID, throwIfNotValid } from '../utils'
16import { VideoModel } from './video' 16import { VideoModel } from './video'
17import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' 17import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions'
18import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' 18import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model'
19import { LAZY_STATIC_PATHS, VIDEO_LANGUAGES } from '../../initializers/constants' 19import { CONSTRAINTS_FIELDS, LAZY_STATIC_PATHS, STATIC_PATHS, VIDEO_LANGUAGES, WEBSERVER } from '../../initializers/constants'
20import { join } from 'path' 20import { join } from 'path'
21import { logger } from '../../helpers/logger' 21import { logger } from '../../helpers/logger'
22import { remove } from 'fs-extra' 22import { remove } from 'fs-extra'
23import { CONFIG } from '../../initializers/config' 23import { CONFIG } from '../../initializers/config'
24import * as Bluebird from 'bluebird' 24import * as Bluebird from 'bluebird'
25import { MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/typings/models' 25import { MVideo, MVideoAccountLight, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/typings/models'
26import { buildRemoteVideoBaseUrl } from '@server/helpers/activitypub'
26 27
27export enum ScopeNames { 28export enum ScopeNames {
28 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE' 29 WITH_VIDEO_UUID_AND_REMOTE = 'WITH_VIDEO_UUID_AND_REMOTE'
@@ -64,6 +65,10 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
64 @Column 65 @Column
65 language: string 66 language: string
66 67
68 @AllowNull(true)
69 @Column(DataType.STRING(CONSTRAINTS_FIELDS.COMMONS.URL.max))
70 fileUrl: string
71
67 @ForeignKey(() => VideoModel) 72 @ForeignKey(() => VideoModel)
68 @Column 73 @Column
69 videoId: number 74 videoId: number
@@ -114,10 +119,11 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
114 return VideoCaptionModel.findOne(query) 119 return VideoCaptionModel.findOne(query)
115 } 120 }
116 121
117 static insertOrReplaceLanguage (videoId: number, language: string, transaction: Transaction) { 122 static insertOrReplaceLanguage (videoId: number, language: string, fileUrl: string, transaction: Transaction) {
118 const values = { 123 const values = {
119 videoId, 124 videoId,
120 language 125 language,
126 fileUrl
121 } 127 }
122 128
123 return VideoCaptionModel.upsert(values, { transaction, returning: true }) 129 return VideoCaptionModel.upsert(values, { transaction, returning: true })
@@ -175,4 +181,14 @@ export class VideoCaptionModel extends Model<VideoCaptionModel> {
175 removeCaptionFile (this: MVideoCaptionFormattable) { 181 removeCaptionFile (this: MVideoCaptionFormattable) {
176 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName()) 182 return remove(CONFIG.STORAGE.CAPTIONS_DIR + this.getCaptionName())
177 } 183 }
184
185 getFileUrl (video: MVideoAccountLight) {
186 if (!this.Video) this.Video = video as VideoModel
187
188 if (video.isOwned()) return WEBSERVER.URL + this.getCaptionStaticPath()
189 if (this.fileUrl) return this.fileUrl
190
191 // Fallback if we don't have a file URL
192 return buildRemoteVideoBaseUrl(video, this.getCaptionStaticPath())
193 }
178} 194}
diff --git a/server/models/video/video-format-utils.ts b/server/models/video/video-format-utils.ts
index 2aa5b8677..bb50edcaa 100644
--- a/server/models/video/video-format-utils.ts
+++ b/server/models/video/video-format-utils.ts
@@ -307,11 +307,12 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
307 for (const caption of video.VideoCaptions) { 307 for (const caption of video.VideoCaptions) {
308 subtitleLanguage.push({ 308 subtitleLanguage.push({
309 identifier: caption.language, 309 identifier: caption.language,
310 name: VideoCaptionModel.getLanguageLabel(caption.language) 310 name: VideoCaptionModel.getLanguageLabel(caption.language),
311 url: caption.getFileUrl(video)
311 }) 312 })
312 } 313 }
313 314
314 const miniature = video.getMiniature() 315 const icons = [ video.getMiniature(), video.getPreview() ]
315 316
316 return { 317 return {
317 type: 'Video' as 'Video', 318 type: 'Video' as 'Video',
@@ -336,13 +337,13 @@ function videoModelToActivityPubObject (video: MVideoAP): VideoTorrentObject {
336 content: video.getTruncatedDescription(), 337 content: video.getTruncatedDescription(),
337 support: video.support, 338 support: video.support,
338 subtitleLanguage, 339 subtitleLanguage,
339 icon: { 340 icon: icons.map(i => ({
340 type: 'Image', 341 type: 'Image',
341 url: miniature.getFileUrl(video.isOwned()), 342 url: i.getFileUrl(video),
342 mediaType: 'image/jpeg', 343 mediaType: 'image/jpeg',
343 width: miniature.width, 344 width: i.width,
344 height: miniature.height 345 height: i.height
345 }, 346 })),
346 url, 347 url,
347 likes: getVideoLikesActivityPubUrl(video), 348 likes: getVideoLikesActivityPubUrl(video),
348 dislikes: getVideoDislikesActivityPubUrl(video), 349 dislikes: getVideoDislikesActivityPubUrl(video),
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 20e1f1c4a..1a924e6c9 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -1121,7 +1121,7 @@ export class VideoModel extends Model<VideoModel> {
1121 }, 1121 },
1122 include: [ 1122 include: [
1123 { 1123 {
1124 attributes: [ 'language' ], 1124 attributes: [ 'language', 'fileUrl' ],
1125 model: VideoCaptionModel.unscoped(), 1125 model: VideoCaptionModel.unscoped(),
1126 required: false 1126 required: false
1127 }, 1127 },