diff options
author | Chocobozzz <me@florianbigard.com> | 2020-12-08 14:30:29 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-12-09 11:41:22 +0100 |
commit | b49f22d8f9a52ab75fd38db2d377249eb58fa678 (patch) | |
tree | a2825877d7b3b53454804a79c9d2a14c5d37385c /server/lib | |
parent | 6c8c15f914cd375da1db5d0cd4d924a86c53d4c1 (diff) | |
download | PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.gz PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.tar.zst PeerTube-b49f22d8f9a52ab75fd38db2d377249eb58fa678.zip |
Upgrade sequelize to v6
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/activitypub/playlist.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/video-rates.ts | 15 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 3 | ||||
-rw-r--r-- | server/lib/client-html.ts | 31 | ||||
-rw-r--r-- | server/lib/job-queue/handlers/activitypub-http-fetcher.ts | 21 | ||||
-rw-r--r-- | server/lib/video-transcoding-profiles.ts | 1 |
8 files changed, 34 insertions, 43 deletions
diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index 53298e968..8b54a001a 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts | |||
@@ -99,6 +99,8 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc | |||
99 | return Promise.resolve() | 99 | return Promise.resolve() |
100 | }) | 100 | }) |
101 | 101 | ||
102 | logger.info('toto', { playlist, id: playlist.id }) | ||
103 | |||
102 | const refreshedPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(playlist.id, null) | 104 | const refreshedPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(playlist.id, null) |
103 | 105 | ||
104 | if (playlistObject.icon) { | 106 | if (playlistObject.icon) { |
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index 635c8bfcc..089c7b881 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts | |||
@@ -33,7 +33,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) |
34 | 34 | ||
35 | return sequelizeTypescript.transaction(async t => { | 35 | return sequelizeTypescript.transaction(async t => { |
36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) | 36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) |
37 | if (existingRate && existingRate.type === 'dislike') return | 37 | if (existingRate && existingRate.type === 'dislike') return |
38 | 38 | ||
39 | await video.increment('dislikes', { transaction: t }) | 39 | await video.increment('dislikes', { transaction: t }) |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 6acc097b1..8688b3b47 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -30,7 +30,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik | |||
30 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) | 30 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) |
31 | 31 | ||
32 | return sequelizeTypescript.transaction(async t => { | 32 | return sequelizeTypescript.transaction(async t => { |
33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) | 33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) |
34 | if (existingRate && existingRate.type === 'like') return | 34 | if (existingRate && existingRate.type === 'like') return |
35 | 35 | ||
36 | if (existingRate && existingRate.type === 'dislike') { | 36 | if (existingRate && existingRate.type === 'dislike') { |
diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts index 581a2bca1..e246b1313 100644 --- a/server/lib/activitypub/video-rates.ts +++ b/server/lib/activitypub/video-rates.ts | |||
@@ -13,8 +13,6 @@ import { sendDislike } from './send/send-dislike' | |||
13 | import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' | 13 | import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' |
14 | 14 | ||
15 | async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateType) { | 15 | async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateType) { |
16 | let rateCounts = 0 | ||
17 | |||
18 | await Bluebird.map(ratesUrl, async rateUrl => { | 16 | await Bluebird.map(ratesUrl, async rateUrl => { |
19 | try { | 17 | try { |
20 | // Fetch url | 18 | // Fetch url |
@@ -43,21 +41,12 @@ async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateTy | |||
43 | url: body.id | 41 | url: body.id |
44 | } | 42 | } |
45 | 43 | ||
46 | const created = await AccountVideoRateModel.upsert(entry) | 44 | // Video "likes"/"dislikes" will be updated by the caller |
47 | 45 | await AccountVideoRateModel.upsert(entry) | |
48 | if (created) rateCounts += 1 | ||
49 | } catch (err) { | 46 | } catch (err) { |
50 | logger.warn('Cannot add rate %s.', rateUrl, { err }) | 47 | logger.warn('Cannot add rate %s.', rateUrl, { err }) |
51 | } | 48 | } |
52 | }, { concurrency: CRAWL_REQUEST_CONCURRENCY }) | 49 | }, { concurrency: CRAWL_REQUEST_CONCURRENCY }) |
53 | |||
54 | logger.info('Adding %d %s to video %s.', rateCounts, rate, video.uuid) | ||
55 | |||
56 | // This is "likes" and "dislikes" | ||
57 | if (rateCounts !== 0) { | ||
58 | const field = rate === 'like' ? 'likes' : 'dislikes' | ||
59 | await video.increment(field, { by: rateCounts }) | ||
60 | } | ||
61 | } | 50 | } |
62 | 51 | ||
63 | async function sendVideoRateChange ( | 52 | async function sendVideoRateChange ( |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index b15d5da1c..cb462e258 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -352,6 +352,9 @@ async function updateVideoFromAP (options: { | |||
352 | video.views = videoData.views | 352 | video.views = videoData.views |
353 | video.isLive = videoData.isLive | 353 | video.isLive = videoData.isLive |
354 | 354 | ||
355 | // Ensures we update the updated video attribute | ||
356 | video.changed('updatedAt', true) | ||
357 | |||
355 | const videoUpdated = await video.save(sequelizeOptions) as MVideoFullLight | 358 | const videoUpdated = await video.save(sequelizeOptions) as MVideoFullLight |
356 | 359 | ||
357 | if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) | 360 | if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) |
diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index 32f5d29ab..43585c591 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts | |||
@@ -1,29 +1,28 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import * as Bluebird from 'bluebird' | 2 | import { readFile } from 'fs-extra' |
3 | import { join } from 'path' | ||
4 | import validator from 'validator' | ||
3 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' | 5 | import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' |
6 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
7 | import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' | ||
8 | import { escapeHTML, isTestInstance, sha256 } from '../helpers/core-utils' | ||
9 | import { logger } from '../helpers/logger' | ||
10 | import { CONFIG } from '../initializers/config' | ||
4 | import { | 11 | import { |
12 | ACCEPT_HEADERS, | ||
5 | AVATARS_SIZE, | 13 | AVATARS_SIZE, |
6 | CUSTOM_HTML_TAG_COMMENTS, | 14 | CUSTOM_HTML_TAG_COMMENTS, |
7 | EMBED_SIZE, | 15 | EMBED_SIZE, |
8 | PLUGIN_GLOBAL_CSS_PATH, | ||
9 | WEBSERVER, | ||
10 | FILES_CONTENT_HASH, | 16 | FILES_CONTENT_HASH, |
11 | ACCEPT_HEADERS | 17 | PLUGIN_GLOBAL_CSS_PATH, |
18 | WEBSERVER | ||
12 | } from '../initializers/constants' | 19 | } from '../initializers/constants' |
13 | import { join } from 'path' | ||
14 | import { escapeHTML, isTestInstance, sha256 } from '../helpers/core-utils' | ||
15 | import { VideoModel } from '../models/video/video' | ||
16 | import { VideoPlaylistModel } from '../models/video/video-playlist' | ||
17 | import validator from 'validator' | ||
18 | import { VideoPrivacy, VideoPlaylistPrivacy } from '../../shared/models/videos' | ||
19 | import { readFile } from 'fs-extra' | ||
20 | import { getActivityStreamDuration } from '../models/video/video-format-utils' | ||
21 | import { AccountModel } from '../models/account/account' | 20 | import { AccountModel } from '../models/account/account' |
21 | import { VideoModel } from '../models/video/video' | ||
22 | import { VideoChannelModel } from '../models/video/video-channel' | 22 | import { VideoChannelModel } from '../models/video/video-channel' |
23 | import { CONFIG } from '../initializers/config' | 23 | import { getActivityStreamDuration } from '../models/video/video-format-utils' |
24 | import { logger } from '../helpers/logger' | 24 | import { VideoPlaylistModel } from '../models/video/video-playlist' |
25 | import { MAccountActor, MChannelActor } from '../types/models' | 25 | import { MAccountActor, MChannelActor } from '../types/models' |
26 | import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes' | ||
27 | 26 | ||
28 | type Tags = { | 27 | type Tags = { |
29 | ogType: string | 28 | ogType: string |
@@ -218,7 +217,7 @@ class ClientHtml { | |||
218 | } | 217 | } |
219 | 218 | ||
220 | private static async getAccountOrChannelHTMLPage ( | 219 | private static async getAccountOrChannelHTMLPage ( |
221 | loader: () => Bluebird<MAccountActor | MChannelActor>, | 220 | loader: () => Promise<MAccountActor | MChannelActor>, |
222 | req: express.Request, | 221 | req: express.Request, |
223 | res: express.Response | 222 | res: express.Response |
224 | ) { | 223 | ) { |
diff --git a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts index a7c1a556c..e210ac3ef 100644 --- a/server/lib/job-queue/handlers/activitypub-http-fetcher.ts +++ b/server/lib/job-queue/handlers/activitypub-http-fetcher.ts | |||
@@ -1,19 +1,18 @@ | |||
1 | import * as Bull from 'bull' | 1 | import * as Bull from 'bull' |
2 | import * as Bluebird from 'bluebird' | 2 | import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models' |
3 | import { logger } from '../../../helpers/logger' | 3 | import { logger } from '../../../helpers/logger' |
4 | import { processActivities } from '../../activitypub/process' | ||
5 | import { addVideoComments } from '../../activitypub/video-comments' | ||
6 | import { crawlCollectionPage } from '../../activitypub/crawl' | ||
7 | import { VideoModel } from '../../../models/video/video' | ||
8 | import { addVideoShares } from '../../activitypub/share' | ||
9 | import { createRates } from '../../activitypub/video-rates' | ||
10 | import { createAccountPlaylists } from '../../activitypub/playlist' | ||
11 | import { AccountModel } from '../../../models/account/account' | 4 | import { AccountModel } from '../../../models/account/account' |
12 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 5 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
13 | import { VideoShareModel } from '../../../models/video/video-share' | 6 | import { VideoModel } from '../../../models/video/video' |
14 | import { VideoCommentModel } from '../../../models/video/video-comment' | 7 | import { VideoCommentModel } from '../../../models/video/video-comment' |
8 | import { VideoShareModel } from '../../../models/video/video-share' | ||
15 | import { MAccountDefault, MVideoFullLight } from '../../../types/models' | 9 | import { MAccountDefault, MVideoFullLight } from '../../../types/models' |
16 | import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models' | 10 | import { crawlCollectionPage } from '../../activitypub/crawl' |
11 | import { createAccountPlaylists } from '../../activitypub/playlist' | ||
12 | import { processActivities } from '../../activitypub/process' | ||
13 | import { addVideoShares } from '../../activitypub/share' | ||
14 | import { addVideoComments } from '../../activitypub/video-comments' | ||
15 | import { createRates } from '../../activitypub/video-rates' | ||
17 | 16 | ||
18 | async function processActivityPubHttpFetcher (job: Bull.Job) { | 17 | async function processActivityPubHttpFetcher (job: Bull.Job) { |
19 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) | 18 | logger.info('Processing ActivityPub fetcher in job %d.', job.id) |
@@ -35,7 +34,7 @@ async function processActivityPubHttpFetcher (job: Bull.Job) { | |||
35 | 'account-playlists': items => createAccountPlaylists(items, account) | 34 | 'account-playlists': items => createAccountPlaylists(items, account) |
36 | } | 35 | } |
37 | 36 | ||
38 | const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Bluebird<any> } = { | 37 | const cleanerType: { [ id in FetchType ]?: (crawlStartDate: Date) => Promise<any> } = { |
39 | 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate), | 38 | 'video-likes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'like' as 'like', crawlStartDate), |
40 | 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate), | 39 | 'video-dislikes': crawlStartDate => AccountVideoRateModel.cleanOldRatesOf(video.id, 'dislike' as 'dislike', crawlStartDate), |
41 | 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), | 40 | 'video-shares': crawlStartDate => VideoShareModel.cleanOldSharesOf(video.id, crawlStartDate), |
diff --git a/server/lib/video-transcoding-profiles.ts b/server/lib/video-transcoding-profiles.ts index 3bf83d6a8..338f4de4a 100644 --- a/server/lib/video-transcoding-profiles.ts +++ b/server/lib/video-transcoding-profiles.ts | |||
@@ -111,7 +111,6 @@ async function buildTargetBitrate (options: { | |||
111 | input: string | 111 | input: string |
112 | resolution: VideoResolution | 112 | resolution: VideoResolution |
113 | fps: number | 113 | fps: number |
114 | |||
115 | }) { | 114 | }) { |
116 | const { input, resolution, fps } = options | 115 | const { input, resolution, fps } = options |
117 | const probe = await ffprobePromise(input) | 116 | const probe = await ffprobePromise(input) |