diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-23 09:50:57 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-24 16:26:21 +0200 |
commit | 3acc50844047a37698f0618fa235c138e386a053 (patch) | |
tree | e33243bf7fadbcf2df616fc41814245094fd881a /server/lib/activitypub/videos.ts | |
parent | 1735c825726edaa0af5035cb6cbb0cc0db502c6d (diff) | |
download | PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.gz PeerTube-3acc50844047a37698f0618fa235c138e386a053.tar.zst PeerTube-3acc50844047a37698f0618fa235c138e386a053.zip |
Upgrade sequelize
Diffstat (limited to 'server/lib/activitypub/videos.ts')
-rw-r--r-- | server/lib/activitypub/videos.ts | 34 |
1 files changed, 12 insertions, 22 deletions
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 5a56942a9..63bb07ec1 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -49,10 +49,11 @@ import { AccountVideoRateModel } from '../../models/account/account-video-rate' | |||
49 | import { VideoShareModel } from '../../models/video/video-share' | 49 | import { VideoShareModel } from '../../models/video/video-share' |
50 | import { VideoCommentModel } from '../../models/video/video-comment' | 50 | import { VideoCommentModel } from '../../models/video/video-comment' |
51 | import { sequelizeTypescript } from '../../initializers/database' | 51 | import { sequelizeTypescript } from '../../initializers/database' |
52 | import { createPlaceholderThumbnail, createVideoThumbnailFromUrl } from '../thumbnail' | 52 | import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail' |
53 | import { ThumbnailModel } from '../../models/video/thumbnail' | 53 | import { ThumbnailModel } from '../../models/video/thumbnail' |
54 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' | 54 | import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' |
55 | import { join } from 'path' | 55 | import { join } from 'path' |
56 | import { FilteredModelAttributes } from '../../typings/sequelize' | ||
56 | 57 | ||
57 | async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { | 58 | async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { |
58 | // If the video is not private and is published, we federate it | 59 | // If the video is not private and is published, we federate it |
@@ -247,7 +248,7 @@ async function updateVideoFromAP (options: { | |||
247 | let thumbnailModel: ThumbnailModel | 248 | let thumbnailModel: ThumbnailModel |
248 | 249 | ||
249 | try { | 250 | try { |
250 | thumbnailModel = await createVideoThumbnailFromUrl(options.videoObject.icon.url, options.video, ThumbnailType.THUMBNAIL) | 251 | thumbnailModel = await createVideoMiniatureFromUrl(options.videoObject.icon.url, options.video, ThumbnailType.MINIATURE) |
251 | } catch (err) { | 252 | } catch (err) { |
252 | logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err }) | 253 | logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err }) |
253 | } | 254 | } |
@@ -288,16 +289,12 @@ async function updateVideoFromAP (options: { | |||
288 | 289 | ||
289 | await options.video.save(sequelizeOptions) | 290 | await options.video.save(sequelizeOptions) |
290 | 291 | ||
291 | if (thumbnailModel) { | 292 | if (thumbnailModel) if (thumbnailModel) await options.video.addAndSaveThumbnail(thumbnailModel, t) |
292 | thumbnailModel.videoId = options.video.id | ||
293 | options.video.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
294 | } | ||
295 | 293 | ||
296 | // FIXME: use icon URL instead | 294 | // FIXME: use icon URL instead |
297 | const previewUrl = buildRemoteBaseUrl(options.video, join(STATIC_PATHS.PREVIEWS, options.video.getPreview().filename)) | 295 | const previewUrl = buildRemoteBaseUrl(options.video, join(STATIC_PATHS.PREVIEWS, options.video.getPreview().filename)) |
298 | const previewModel = createPlaceholderThumbnail(previewUrl, options.video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) | 296 | const previewModel = createPlaceholderThumbnail(previewUrl, options.video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) |
299 | 297 | await options.video.addAndSaveThumbnail(previewModel, t) | |
300 | options.video.addThumbnail(await previewModel.save({ transaction: t })) | ||
301 | 298 | ||
302 | { | 299 | { |
303 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject) | 300 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject) |
@@ -311,7 +308,7 @@ async function updateVideoFromAP (options: { | |||
311 | 308 | ||
312 | // Update or add other one | 309 | // Update or add other one |
313 | const upsertTasks = videoFileAttributes.map(a => { | 310 | const upsertTasks = videoFileAttributes.map(a => { |
314 | return (VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t }) as any) // FIXME: sequelize typings | 311 | return VideoFileModel.upsert<VideoFileModel>(a, { returning: true, transaction: t }) |
315 | .then(([ file ]) => file) | 312 | .then(([ file ]) => file) |
316 | }) | 313 | }) |
317 | 314 | ||
@@ -334,8 +331,7 @@ async function updateVideoFromAP (options: { | |||
334 | 331 | ||
335 | // Update or add other one | 332 | // Update or add other one |
336 | const upsertTasks = streamingPlaylistAttributes.map(a => { | 333 | const upsertTasks = streamingPlaylistAttributes.map(a => { |
337 | // FIXME: sequelize typings | 334 | return VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t }) |
338 | return (VideoStreamingPlaylistModel.upsert<VideoStreamingPlaylistModel>(a, { returning: true, transaction: t }) as any) | ||
339 | .then(([ streamingPlaylist ]) => streamingPlaylist) | 335 | .then(([ streamingPlaylist ]) => streamingPlaylist) |
340 | }) | 336 | }) |
341 | 337 | ||
@@ -464,7 +460,7 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor | |||
464 | const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, videoObject.to) | 460 | const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, videoObject.to) |
465 | const video = VideoModel.build(videoData) | 461 | const video = VideoModel.build(videoData) |
466 | 462 | ||
467 | const promiseThumbnail = createVideoThumbnailFromUrl(videoObject.icon.url, video, ThumbnailType.THUMBNAIL) | 463 | const promiseThumbnail = createVideoMiniatureFromUrl(videoObject.icon.url, video, ThumbnailType.MINIATURE) |
468 | 464 | ||
469 | let thumbnailModel: ThumbnailModel | 465 | let thumbnailModel: ThumbnailModel |
470 | if (waitThumbnail === true) { | 466 | if (waitThumbnail === true) { |
@@ -477,18 +473,12 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor | |||
477 | const videoCreated = await video.save(sequelizeOptions) | 473 | const videoCreated = await video.save(sequelizeOptions) |
478 | videoCreated.VideoChannel = channelActor.VideoChannel | 474 | videoCreated.VideoChannel = channelActor.VideoChannel |
479 | 475 | ||
480 | if (thumbnailModel) { | 476 | if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) |
481 | thumbnailModel.videoId = videoCreated.id | ||
482 | |||
483 | videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) | ||
484 | } | ||
485 | 477 | ||
486 | // FIXME: use icon URL instead | 478 | // FIXME: use icon URL instead |
487 | const previewUrl = buildRemoteBaseUrl(videoCreated, join(STATIC_PATHS.PREVIEWS, video.generatePreviewName())) | 479 | const previewUrl = buildRemoteBaseUrl(videoCreated, join(STATIC_PATHS.PREVIEWS, video.generatePreviewName())) |
488 | const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) | 480 | const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) |
489 | previewModel.videoId = videoCreated.id | 481 | if (thumbnailModel) await videoCreated.addAndSaveThumbnail(previewModel, t) |
490 | |||
491 | videoCreated.addThumbnail(await previewModel.save({ transaction: t })) | ||
492 | 482 | ||
493 | // Process files | 483 | // Process files |
494 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject) | 484 | const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject) |
@@ -594,7 +584,7 @@ function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: Vid | |||
594 | throw new Error('Cannot find video files for ' + video.url) | 584 | throw new Error('Cannot find video files for ' + video.url) |
595 | } | 585 | } |
596 | 586 | ||
597 | const attributes: object[] = [] // FIXME: add typings | 587 | const attributes: FilteredModelAttributes<VideoFileModel>[] = [] |
598 | for (const fileUrl of fileUrls) { | 588 | for (const fileUrl of fileUrls) { |
599 | // Fetch associated magnet uri | 589 | // Fetch associated magnet uri |
600 | const magnet = videoObject.url.find(u => { | 590 | const magnet = videoObject.url.find(u => { |
@@ -629,7 +619,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObj | |||
629 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] | 619 | const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] |
630 | if (playlistUrls.length === 0) return [] | 620 | if (playlistUrls.length === 0) return [] |
631 | 621 | ||
632 | const attributes: object[] = [] // FIXME: add typings | 622 | const attributes: FilteredModelAttributes<VideoStreamingPlaylistModel>[] = [] |
633 | for (const playlistUrlObject of playlistUrls) { | 623 | for (const playlistUrlObject of playlistUrls) { |
634 | const segmentsSha256UrlObject = playlistUrlObject.tag | 624 | const segmentsSha256UrlObject = playlistUrlObject.tag |
635 | .find(t => { | 625 | .find(t => { |