From 3acc50844047a37698f0618fa235c138e386a053 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 23 Apr 2019 09:50:57 +0200 Subject: Upgrade sequelize --- server/lib/activitypub/playlist.ts | 14 ++++++------- server/lib/activitypub/video-comments.ts | 3 +-- server/lib/activitypub/videos.ts | 34 +++++++++++--------------------- 3 files changed, 19 insertions(+), 32 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index 721c19603..36a91faec 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts @@ -16,7 +16,8 @@ import { VideoPlaylistElementModel } from '../../models/video/video-playlist-ele import { VideoModel } from '../../models/video/video' import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' import { sequelizeTypescript } from '../../initializers/database' -import { createPlaylistThumbnailFromUrl } from '../thumbnail' +import { createPlaylistMiniatureFromUrl } from '../thumbnail' +import { FilteredModelAttributes } from '../../typings/sequelize' function playlistObjectToDBAttributes (playlistObject: PlaylistObject, byAccount: AccountModel, to: string[]) { const privacy = to.indexOf(ACTIVITY_PUB.PUBLIC) !== -1 ? VideoPlaylistPrivacy.PUBLIC : VideoPlaylistPrivacy.UNLISTED @@ -86,8 +87,7 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc } } - // FIXME: sequelize typings - const [ playlist ] = (await VideoPlaylistModel.upsert(playlistAttributes, { returning: true }) as any) + const [ playlist ] = await VideoPlaylistModel.upsert(playlistAttributes, { returning: true }) let accItems: string[] = [] await crawlCollectionPage(playlistObject.id, items => { @@ -100,10 +100,8 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc if (playlistObject.icon) { try { - const thumbnailModel = await createPlaylistThumbnailFromUrl(playlistObject.icon.url, refreshedPlaylist) - thumbnailModel.videoPlaylistId = refreshedPlaylist.id - - refreshedPlaylist.setThumbnail(await thumbnailModel.save()) + const thumbnailModel = await createPlaylistMiniatureFromUrl(playlistObject.icon.url, refreshedPlaylist) + await refreshedPlaylist.setAndSaveThumbnail(thumbnailModel, undefined) } catch (err) { logger.warn('Cannot generate thumbnail of %s.', playlistObject.id, { err }) } @@ -156,7 +154,7 @@ export { // --------------------------------------------------------------------------- async function resetVideoPlaylistElements (elementUrls: string[], playlist: VideoPlaylistModel) { - const elementsToCreate: object[] = [] // FIXME: sequelize typings + const elementsToCreate: FilteredModelAttributes[] = [] await Bluebird.map(elementUrls, async elementUrl => { try { diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts index cb67bf9a4..18f44d50e 100644 --- a/server/lib/activitypub/video-comments.ts +++ b/server/lib/activitypub/video-comments.ts @@ -73,8 +73,7 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) { const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body) if (!entry) return { created: false } - // FIXME: sequelize typings - const [ comment, created ] = (await VideoCommentModel.upsert(entry, { returning: true }) as any) + const [ comment, created ] = await VideoCommentModel.upsert(entry, { returning: true }) comment.Account = actor.Account comment.Video = videoInstance 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' import { VideoShareModel } from '../../models/video/video-share' import { VideoCommentModel } from '../../models/video/video-comment' import { sequelizeTypescript } from '../../initializers/database' -import { createPlaceholderThumbnail, createVideoThumbnailFromUrl } from '../thumbnail' +import { createPlaceholderThumbnail, createVideoMiniatureFromUrl } from '../thumbnail' import { ThumbnailModel } from '../../models/video/thumbnail' import { ThumbnailType } from '../../../shared/models/videos/thumbnail.type' import { join } from 'path' +import { FilteredModelAttributes } from '../../typings/sequelize' async function federateVideoIfNeeded (video: VideoModel, isNewVideo: boolean, transaction?: sequelize.Transaction) { // If the video is not private and is published, we federate it @@ -247,7 +248,7 @@ async function updateVideoFromAP (options: { let thumbnailModel: ThumbnailModel try { - thumbnailModel = await createVideoThumbnailFromUrl(options.videoObject.icon.url, options.video, ThumbnailType.THUMBNAIL) + thumbnailModel = await createVideoMiniatureFromUrl(options.videoObject.icon.url, options.video, ThumbnailType.MINIATURE) } catch (err) { logger.warn('Cannot generate thumbnail of %s.', options.videoObject.id, { err }) } @@ -288,16 +289,12 @@ async function updateVideoFromAP (options: { await options.video.save(sequelizeOptions) - if (thumbnailModel) { - thumbnailModel.videoId = options.video.id - options.video.addThumbnail(await thumbnailModel.save({ transaction: t })) - } + if (thumbnailModel) if (thumbnailModel) await options.video.addAndSaveThumbnail(thumbnailModel, t) // FIXME: use icon URL instead const previewUrl = buildRemoteBaseUrl(options.video, join(STATIC_PATHS.PREVIEWS, options.video.getPreview().filename)) const previewModel = createPlaceholderThumbnail(previewUrl, options.video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) - - options.video.addThumbnail(await previewModel.save({ transaction: t })) + await options.video.addAndSaveThumbnail(previewModel, t) { const videoFileAttributes = videoFileActivityUrlToDBAttributes(options.video, options.videoObject) @@ -311,7 +308,7 @@ async function updateVideoFromAP (options: { // Update or add other one const upsertTasks = videoFileAttributes.map(a => { - return (VideoFileModel.upsert(a, { returning: true, transaction: t }) as any) // FIXME: sequelize typings + return VideoFileModel.upsert(a, { returning: true, transaction: t }) .then(([ file ]) => file) }) @@ -334,8 +331,7 @@ async function updateVideoFromAP (options: { // Update or add other one const upsertTasks = streamingPlaylistAttributes.map(a => { - // FIXME: sequelize typings - return (VideoStreamingPlaylistModel.upsert(a, { returning: true, transaction: t }) as any) + return VideoStreamingPlaylistModel.upsert(a, { returning: true, transaction: t }) .then(([ streamingPlaylist ]) => streamingPlaylist) }) @@ -464,7 +460,7 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor const videoData = await videoActivityObjectToDBAttributes(channelActor.VideoChannel, videoObject, videoObject.to) const video = VideoModel.build(videoData) - const promiseThumbnail = createVideoThumbnailFromUrl(videoObject.icon.url, video, ThumbnailType.THUMBNAIL) + const promiseThumbnail = createVideoMiniatureFromUrl(videoObject.icon.url, video, ThumbnailType.MINIATURE) let thumbnailModel: ThumbnailModel if (waitThumbnail === true) { @@ -477,18 +473,12 @@ async function createVideo (videoObject: VideoTorrentObject, channelActor: Actor const videoCreated = await video.save(sequelizeOptions) videoCreated.VideoChannel = channelActor.VideoChannel - if (thumbnailModel) { - thumbnailModel.videoId = videoCreated.id - - videoCreated.addThumbnail(await thumbnailModel.save({ transaction: t })) - } + if (thumbnailModel) await videoCreated.addAndSaveThumbnail(thumbnailModel, t) // FIXME: use icon URL instead const previewUrl = buildRemoteBaseUrl(videoCreated, join(STATIC_PATHS.PREVIEWS, video.generatePreviewName())) const previewModel = createPlaceholderThumbnail(previewUrl, video, ThumbnailType.PREVIEW, PREVIEWS_SIZE) - previewModel.videoId = videoCreated.id - - videoCreated.addThumbnail(await previewModel.save({ transaction: t })) + if (thumbnailModel) await videoCreated.addAndSaveThumbnail(previewModel, t) // Process files const videoFileAttributes = videoFileActivityUrlToDBAttributes(videoCreated, videoObject) @@ -594,7 +584,7 @@ function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: Vid throw new Error('Cannot find video files for ' + video.url) } - const attributes: object[] = [] // FIXME: add typings + const attributes: FilteredModelAttributes[] = [] for (const fileUrl of fileUrls) { // Fetch associated magnet uri const magnet = videoObject.url.find(u => { @@ -629,7 +619,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObj const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] if (playlistUrls.length === 0) return [] - const attributes: object[] = [] // FIXME: add typings + const attributes: FilteredModelAttributes[] = [] for (const playlistUrlObject of playlistUrls) { const segmentsSha256UrlObject = playlistUrlObject.tag .find(t => { -- cgit v1.2.3