From 1735c825726edaa0af5035cb6cbb0cc0db502c6d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 18 Apr 2019 11:28:17 +0200 Subject: Update sequelize --- server/lib/activitypub/cache-file.ts | 4 ++-- server/lib/activitypub/playlist.ts | 6 +++--- server/lib/activitypub/process/process-follow.ts | 4 +++- server/lib/activitypub/process/process-update.ts | 8 +++++--- server/lib/activitypub/video-comments.ts | 3 ++- server/lib/activitypub/video-rates.ts | 5 ++++- server/lib/activitypub/videos.ts | 12 ++++++------ server/lib/user.ts | 3 +-- server/lib/video-comment.ts | 2 +- 9 files changed, 27 insertions(+), 20 deletions(-) (limited to 'server/lib') diff --git a/server/lib/activitypub/cache-file.ts b/server/lib/activitypub/cache-file.ts index 597003135..de5cc54ac 100644 --- a/server/lib/activitypub/cache-file.ts +++ b/server/lib/activitypub/cache-file.ts @@ -68,8 +68,8 @@ function updateCacheFile ( const attributes = cacheFileActivityObjectToDBAttributes(cacheFileObject, video, byActor) - redundancyModel.set('expires', attributes.expiresOn) - redundancyModel.set('fileUrl', attributes.fileUrl) + redundancyModel.expiresOn = attributes.expiresOn + redundancyModel.fileUrl = attributes.fileUrl return redundancyModel.save({ transaction: t }) } diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index 341e469f3..721c19603 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts @@ -14,7 +14,6 @@ import { getOrCreateVideoAndAccountAndChannel } from './videos' import { isPlaylistElementObjectValid, isPlaylistObjectValid } from '../../helpers/custom-validators/activitypub/playlist' import { VideoPlaylistElementModel } from '../../models/video/video-playlist-element' import { VideoModel } from '../../models/video/video' -import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model' import { sequelizeTypescript } from '../../initializers/database' import { createPlaylistThumbnailFromUrl } from '../thumbnail' @@ -87,7 +86,8 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc } } - const [ playlist ] = await VideoPlaylistModel.upsert(playlistAttributes, { returning: true }) + // FIXME: sequelize typings + const [ playlist ] = (await VideoPlaylistModel.upsert(playlistAttributes, { returning: true }) as any) let accItems: string[] = [] await crawlCollectionPage(playlistObject.id, items => { @@ -156,7 +156,7 @@ export { // --------------------------------------------------------------------------- async function resetVideoPlaylistElements (elementUrls: string[], playlist: VideoPlaylistModel) { - const elementsToCreate: FilteredModelAttributes[] = [] + const elementsToCreate: object[] = [] // FIXME: sequelize typings await Bluebird.map(elementUrls, async elementUrl => { try { diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index ac3dd6ac4..ed16ba172 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts @@ -37,7 +37,9 @@ async function processFollow (actor: ActorModel, targetActorURL: string) { if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) - return sendReject(actor, targetActor) + await sendReject(actor, targetActor) + + return { actorFollow: undefined } } const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 0b96ba352..54a9234bb 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts @@ -120,9 +120,11 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate) await actor.save({ transaction: t }) - accountOrChannelInstance.set('name', actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername) - accountOrChannelInstance.set('description', actorAttributesToUpdate.summary) - accountOrChannelInstance.set('support', actorAttributesToUpdate.support) + accountOrChannelInstance.name = actorAttributesToUpdate.name || actorAttributesToUpdate.preferredUsername + accountOrChannelInstance.description = actorAttributesToUpdate.summary + + if (accountOrChannelInstance instanceof VideoChannelModel) accountOrChannelInstance.support = actorAttributesToUpdate.support + await accountOrChannelInstance.save({ transaction: t }) }) diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts index 18f44d50e..cb67bf9a4 100644 --- a/server/lib/activitypub/video-comments.ts +++ b/server/lib/activitypub/video-comments.ts @@ -73,7 +73,8 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) { const entry = await videoCommentActivityObjectToDBAttributes(videoInstance, actor, body) if (!entry) return { created: false } - const [ comment, created ] = await VideoCommentModel.upsert(entry, { returning: true }) + // FIXME: sequelize typings + const [ comment, created ] = (await VideoCommentModel.upsert(entry, { returning: true }) as any) comment.Account = actor.Account comment.Video = videoInstance diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts index 7809c58b8..cda5b2981 100644 --- a/server/lib/activitypub/video-rates.ts +++ b/server/lib/activitypub/video-rates.ts @@ -56,7 +56,10 @@ async function createRates (ratesUrl: string[], video: VideoModel, rate: VideoRa logger.info('Adding %d %s to video %s.', rateCounts, rate, video.uuid) // This is "likes" and "dislikes" - if (rateCounts !== 0) await video.increment(rate + 's', { by: rateCounts }) + if (rateCounts !== 0) { + const field = rate === 'like' ? 'likes' : 'dislikes' + await video.increment(field, { by: rateCounts }) + } return } diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index 16c37a55f..5a56942a9 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts @@ -6,7 +6,7 @@ import { ActivityPlaylistSegmentHashesObject, ActivityPlaylistUrlObject, ActivityUrlObject, - ActivityVideoUrlObject, VideoCreate, + ActivityVideoUrlObject, VideoState } from '../../../shared/index' import { VideoTorrentObject } from '../../../shared/models/activitypub/objects' @@ -45,7 +45,6 @@ import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' import { Notifier } from '../notifier' import { VideoStreamingPlaylistModel } from '../../models/video/video-streaming-playlist' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' -import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' import { AccountVideoRateModel } from '../../models/account/account-video-rate' import { VideoShareModel } from '../../models/video/video-share' import { VideoCommentModel } from '../../models/video/video-comment' @@ -312,7 +311,7 @@ async function updateVideoFromAP (options: { // Update or add other one const upsertTasks = videoFileAttributes.map(a => { - return VideoFileModel.upsert(a, { returning: true, transaction: t }) + return (VideoFileModel.upsert(a, { returning: true, transaction: t }) as any) // FIXME: sequelize typings .then(([ file ]) => file) }) @@ -335,7 +334,8 @@ async function updateVideoFromAP (options: { // Update or add other one const upsertTasks = streamingPlaylistAttributes.map(a => { - return VideoStreamingPlaylistModel.upsert(a, { returning: true, transaction: t }) + // FIXME: sequelize typings + return (VideoStreamingPlaylistModel.upsert(a, { returning: true, transaction: t }) as any) .then(([ streamingPlaylist ]) => streamingPlaylist) }) @@ -594,7 +594,7 @@ function videoFileActivityUrlToDBAttributes (video: VideoModel, videoObject: Vid throw new Error('Cannot find video files for ' + video.url) } - const attributes: FilteredModelAttributes[] = [] + const attributes: object[] = [] // FIXME: add typings for (const fileUrl of fileUrls) { // Fetch associated magnet uri const magnet = videoObject.url.find(u => { @@ -629,7 +629,7 @@ function streamingPlaylistActivityUrlToDBAttributes (video: VideoModel, videoObj const playlistUrls = videoObject.url.filter(u => isAPStreamingPlaylistUrlObject(u)) as ActivityPlaylistUrlObject[] if (playlistUrls.length === 0) return [] - const attributes: FilteredModelAttributes[] = [] + const attributes: object[] = [] // FIXME: add typings for (const playlistUrlObject of playlistUrls) { const segmentsSha256UrlObject = playlistUrlObject.tag .find(t => { diff --git a/server/lib/user.ts b/server/lib/user.ts index ce0d60518..7badb3e72 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -7,7 +7,6 @@ import { UserModel } from '../models/account/user' import { buildActorInstance, getAccountActivityPubUrl, setAsyncActorKeys } from './activitypub' import { createVideoChannel } from './video-channel' import { VideoChannelModel } from '../models/video/video-channel' -import { FilteredModelAttributes } from 'sequelize-typescript/lib/models/Model' import { ActorModel } from '../models/activitypub/actor' import { UserNotificationSettingModel } from '../models/account/user-notification-setting' import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' @@ -73,7 +72,7 @@ async function createLocalAccountWithoutKeys ( userId, applicationId, actorId: actorInstanceCreated.id - } as FilteredModelAttributes) + }) const accountInstanceCreated = await accountInstance.save({ transaction: t }) accountInstanceCreated.Actor = actorInstanceCreated diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts index 59bce7520..bfe22d225 100644 --- a/server/lib/video-comment.ts +++ b/server/lib/video-comment.ts @@ -28,7 +28,7 @@ async function createVideoComment (obj: { videoId: obj.video.id, accountId: obj.account.id, url: 'fake url' - }, { transaction: t, validate: false }) + }, { transaction: t, validate: false } as any) // FIXME: sequelize typings comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) -- cgit v1.2.3