aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-08 14:30:29 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-09 11:41:22 +0100
commitb49f22d8f9a52ab75fd38db2d377249eb58fa678 (patch)
treea2825877d7b3b53454804a79c9d2a14c5d37385c /server/lib
parent6c8c15f914cd375da1db5d0cd4d924a86c53d4c1 (diff)
downloadPeerTube-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.ts2
-rw-r--r--server/lib/activitypub/process/process-dislike.ts2
-rw-r--r--server/lib/activitypub/process/process-like.ts2
-rw-r--r--server/lib/activitypub/video-rates.ts15
-rw-r--r--server/lib/activitypub/videos.ts3
-rw-r--r--server/lib/client-html.ts31
-rw-r--r--server/lib/job-queue/handlers/activitypub-http-fetcher.ts21
-rw-r--r--server/lib/video-transcoding-profiles.ts1
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'
13import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' 13import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models'
14 14
15async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateType) { 15async 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
63async function sendVideoRateChange ( 52async 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 @@
1import * as express from 'express' 1import * as express from 'express'
2import * as Bluebird from 'bluebird' 2import { readFile } from 'fs-extra'
3import { join } from 'path'
4import validator from 'validator'
3import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n' 5import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n'
6import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
7import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos'
8import { escapeHTML, isTestInstance, sha256 } from '../helpers/core-utils'
9import { logger } from '../helpers/logger'
10import { CONFIG } from '../initializers/config'
4import { 11import {
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'
13import { join } from 'path'
14import { escapeHTML, isTestInstance, sha256 } from '../helpers/core-utils'
15import { VideoModel } from '../models/video/video'
16import { VideoPlaylistModel } from '../models/video/video-playlist'
17import validator from 'validator'
18import { VideoPrivacy, VideoPlaylistPrivacy } from '../../shared/models/videos'
19import { readFile } from 'fs-extra'
20import { getActivityStreamDuration } from '../models/video/video-format-utils'
21import { AccountModel } from '../models/account/account' 20import { AccountModel } from '../models/account/account'
21import { VideoModel } from '../models/video/video'
22import { VideoChannelModel } from '../models/video/video-channel' 22import { VideoChannelModel } from '../models/video/video-channel'
23import { CONFIG } from '../initializers/config' 23import { getActivityStreamDuration } from '../models/video/video-format-utils'
24import { logger } from '../helpers/logger' 24import { VideoPlaylistModel } from '../models/video/video-playlist'
25import { MAccountActor, MChannelActor } from '../types/models' 25import { MAccountActor, MChannelActor } from '../types/models'
26import { HttpStatusCode } from '../../shared/core-utils/miscs/http-error-codes'
27 26
28type Tags = { 27type 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 @@
1import * as Bull from 'bull' 1import * as Bull from 'bull'
2import * as Bluebird from 'bluebird' 2import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { processActivities } from '../../activitypub/process'
5import { addVideoComments } from '../../activitypub/video-comments'
6import { crawlCollectionPage } from '../../activitypub/crawl'
7import { VideoModel } from '../../../models/video/video'
8import { addVideoShares } from '../../activitypub/share'
9import { createRates } from '../../activitypub/video-rates'
10import { createAccountPlaylists } from '../../activitypub/playlist'
11import { AccountModel } from '../../../models/account/account' 4import { AccountModel } from '../../../models/account/account'
12import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 5import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
13import { VideoShareModel } from '../../../models/video/video-share' 6import { VideoModel } from '../../../models/video/video'
14import { VideoCommentModel } from '../../../models/video/video-comment' 7import { VideoCommentModel } from '../../../models/video/video-comment'
8import { VideoShareModel } from '../../../models/video/video-share'
15import { MAccountDefault, MVideoFullLight } from '../../../types/models' 9import { MAccountDefault, MVideoFullLight } from '../../../types/models'
16import { ActivitypubHttpFetcherPayload, FetchType } from '@shared/models' 10import { crawlCollectionPage } from '../../activitypub/crawl'
11import { createAccountPlaylists } from '../../activitypub/playlist'
12import { processActivities } from '../../activitypub/process'
13import { addVideoShares } from '../../activitypub/share'
14import { addVideoComments } from '../../activitypub/video-comments'
15import { createRates } from '../../activitypub/video-rates'
17 16
18async function processActivityPubHttpFetcher (job: Bull.Job) { 17async 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)