diff --git a/server/controllers/api/server/follows.ts b/server/controllers/api/server/follows.ts index c9775ad21..ac8ea87f9 100644 --- a/server/controllers/api/server/follows.ts +++ b/server/controllers/api/server/follows.ts @@ -108,7 +108,11 @@ async function follow (req: express.Request, res: express.Response, next: expres tasks.push(p) } - await Promise.all(tasks) + // Don't make the client wait the tasks + Promise.all(tasks) + .catch(err => { + logger.error('Error in follow.', err) + }) return res.status(204).end() } diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index c9ecf1f3d..a46757397 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts @@ -1,20 +1,17 @@ import * as validator from 'validator' - +import { ACTIVITY_PUB } from '../../../initializers' +import { exists, isDateValid, isUUIDValid } from '../misc' +import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' import { - ACTIVITY_PUB -} from '../../../initializers' -import { isDateValid, isUUIDValid } from '../misc' -import { - isVideoViewsValid, - isVideoNSFWValid, - isVideoTruncatedDescriptionValid, isVideoDurationValid, isVideoNameValid, + isVideoNSFWValid, isVideoTagValid, - isVideoUrlValid + isVideoTruncatedDescriptionValid, + isVideoUrlValid, + isVideoViewsValid } from '../videos' -import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' -import { isActivityPubUrlValid, isBaseActivityValid } from './misc' +import { isBaseActivityValid } from './misc' function isVideoTorrentAddActivityValid (activity: any) { return isBaseActivityValid(activity, 'Add') && @@ -30,10 +27,19 @@ function isVideoTorrentDeleteActivityValid (activity: any) { return isBaseActivityValid(activity, 'Delete') } +function isActivityPubVideoDurationValid (value: string) { + // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration + return exists(value) && + typeof value === 'string' && + value.startsWith('PT') && + value.endsWith('S') && + isVideoDurationValid(value.replace(/[^0-9]+/, '')) +} + function isVideoTorrentObjectValid (video: any) { return video.type === 'Video' && isVideoNameValid(video.name) && - isVideoDurationValid(video.duration) && + isActivityPubVideoDurationValid(video.duration) && isUUIDValid(video.uuid) && setValidRemoteTags(video) && isRemoteIdentifierValid(video.category) && diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts index 1505632da..c97c9a2ad 100644 --- a/server/helpers/custom-validators/videos.ts +++ b/server/helpers/custom-validators/videos.ts @@ -69,6 +69,10 @@ function isVideoNSFWValid (value: any) { return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) } +function isVideoDurationValid (value: string) { + return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) +} + function isVideoTruncatedDescriptionValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.TRUNCATED_DESCRIPTION) } @@ -77,15 +81,6 @@ function isVideoDescriptionValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) } -function isVideoDurationValid (value: string) { - // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration - return exists(value) && - typeof value === 'string' && - value.startsWith('PT') && - value.endsWith('S') && - validator.isInt(value.replace(/[^0-9]+/, ''), VIDEOS_CONSTRAINTS_FIELDS.DURATION) -} - function isVideoNameValid (value: string) { return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) } @@ -197,7 +192,6 @@ export { isVideoNSFWValid, isVideoTruncatedDescriptionValid, isVideoDescriptionValid, - isVideoDurationValid, isVideoFileInfoHashValid, isVideoNameValid, isVideoTagsValid, @@ -214,6 +208,7 @@ export { isVideoFileSizeValid, isVideoPrivacyValid, isRemoteVideoPrivacyValid, + isVideoDurationValid, isVideoFileResolutionValid, checkVideoExists, isVideoTagValid, diff --git a/server/lib/activitypub/send-request.ts b/server/lib/activitypub/send-request.ts index 1a6cebc03..1dad51828 100644 --- a/server/lib/activitypub/send-request.ts +++ b/server/lib/activitypub/send-request.ts @@ -11,6 +11,7 @@ import { signObject, activityPubContextify } from '../../helpers' import { Activity } from '../../../shared' import { VideoAbuseInstance } from '../../models/video/video-abuse-interface' import { getActivityPubUrl } from '../../helpers/activitypub' +import { logger } from '../../helpers/logger' async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) { const videoChannelObject = videoChannel.toActivityPubObject() @@ -100,7 +101,11 @@ export { // --------------------------------------------------------------------------- async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) { - const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(fromAccount.id, 0) + const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi(fromAccount.id) + if (result.data.length === 0) { + logger.info('Not broadcast because of 0 followers.') + return + } const jobPayload = { uris: result.data, diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts index 2f1d9ee92..ccb008e4d 100644 --- a/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts +++ b/server/lib/jobs/http-request-job-scheduler/http-request-broadcast-handler.ts @@ -22,8 +22,9 @@ function onError (err: Error, jobId: number) { return Promise.resolve() } -async function onSuccess (jobId: number) { +function onSuccess (jobId: number) { logger.info('Job %d is a success.', jobId) + return Promise.resolve() } // --------------------------------------------------------------------------- diff --git a/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts b/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts index 3a1a7fabf..9e4e73891 100644 --- a/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts +++ b/server/lib/jobs/http-request-job-scheduler/http-request-unicast-handler.ts @@ -20,8 +20,9 @@ function onError (err: Error, jobId: number) { return Promise.resolve() } -async function onSuccess (jobId: number) { +function onSuccess (jobId: number) { logger.info('Job %d is a success.', jobId) + return Promise.resolve() } // --------------------------------------------------------------------------- diff --git a/server/lib/jobs/job-scheduler.ts b/server/lib/jobs/job-scheduler.ts index b25bb7ab3..73c440279 100644 --- a/server/lib/jobs/job-scheduler.ts +++ b/server/lib/jobs/job-scheduler.ts @@ -9,7 +9,7 @@ import { error } from 'util' export interface JobHandler
{
process (data: object, jobId: number): Promise )
+ onSuccess (jobId: number, jobResult: T, jobScheduler: JobScheduler ): Promise {
try {
await job.save()
- jobHandler.onSuccess(job.id, jobResult, this)
+ await jobHandler.onSuccess(job.id, jobResult, this)
} catch (err) {
this.cannotSaveJobError(err)
}
diff --git a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
index d3ee886e7..f6d9627a5 100644
--- a/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
+++ b/server/lib/jobs/transcoding-job-scheduler/video-file-optimizer-handler.ts
@@ -39,8 +39,8 @@ async function onSuccess (jobId: number, video: VideoInstance, jobScheduler: Job
await sendAddVideo(video, undefined)
const originalFileHeight = await videoDatabase.getOriginalFileHeight()
- // Create transcoding jobs if there are enabled resolutions
+ // Create transcoding jobs if there are enabled resolutions
const resolutionsEnabled = computeResolutionsToTranscode(originalFileHeight)
logger.info(
'Resolutions computed for video %s and origin file height of %d.', videoDatabase.uuid, originalFileHeight,
diff --git a/server/models/account/account-follow-interface.ts b/server/models/account/account-follow-interface.ts
index 413dad190..54baf45ed 100644
--- a/server/models/account/account-follow-interface.ts
+++ b/server/models/account/account-follow-interface.ts
@@ -10,8 +10,8 @@ export namespace AccountFollowMethods {
export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList