Speed up activity pub http requests
This commit is contained in:
parent
1b3989b096
commit
afffe98839
|
@ -38,5 +38,11 @@ const rl = createInterface({
|
||||||
|
|
||||||
rl.on('line', line => {
|
rl.on('line', line => {
|
||||||
const log = JSON.parse(line)
|
const log = JSON.parse(line)
|
||||||
logLevels[log.level](log.message, log.stack)
|
const additionalInfo: any = {}
|
||||||
|
|
||||||
|
Object.keys(log).forEach(logKey => {
|
||||||
|
if (logKey !== 'message' && logKey !== 'level') additionalInfo[logKey] = log[logKey]
|
||||||
|
})
|
||||||
|
|
||||||
|
logLevels[log.level](log.message, additionalInfo)
|
||||||
})
|
})
|
||||||
|
|
|
@ -46,7 +46,7 @@ db.init(false).then(() => onDatabaseInitDone())
|
||||||
|
|
||||||
// ----------- PeerTube modules -----------
|
// ----------- PeerTube modules -----------
|
||||||
import { migrate, installApplication } from './server/initializers'
|
import { migrate, installApplication } from './server/initializers'
|
||||||
import { httpRequestJobScheduler, transcodingJobScheduler, VideosPreviewCache } from './server/lib'
|
import { activitypubHttpJobScheduler, transcodingJobScheduler, VideosPreviewCache } from './server/lib'
|
||||||
import { apiRouter, clientsRouter, staticRouter, servicesRouter, webfingerRouter, activityPubRouter } from './server/controllers'
|
import { apiRouter, clientsRouter, staticRouter, servicesRouter, webfingerRouter, activityPubRouter } from './server/controllers'
|
||||||
|
|
||||||
// ----------- Command line -----------
|
// ----------- Command line -----------
|
||||||
|
@ -154,7 +154,7 @@ function onDatabaseInitDone () {
|
||||||
// ----------- Make the server listening -----------
|
// ----------- Make the server listening -----------
|
||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
|
VideosPreviewCache.Instance.init(CONFIG.CACHE.PREVIEWS.SIZE)
|
||||||
httpRequestJobScheduler.activate()
|
activitypubHttpJobScheduler.activate()
|
||||||
transcodingJobScheduler.activate()
|
transcodingJobScheduler.activate()
|
||||||
|
|
||||||
logger.info('Server listening on port %d', port)
|
logger.info('Server listening on port %d', port)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as request from 'request'
|
||||||
import * as Sequelize from 'sequelize'
|
import * as Sequelize from 'sequelize'
|
||||||
import * as url from 'url'
|
import * as url from 'url'
|
||||||
import { ActivityIconObject } from '../../shared/index'
|
import { ActivityIconObject } from '../../shared/index'
|
||||||
|
import { Activity } from '../../shared/models/activitypub/activity'
|
||||||
import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor'
|
import { ActivityPubActor } from '../../shared/models/activitypub/activitypub-actor'
|
||||||
import { VideoChannelObject } from '../../shared/models/activitypub/objects/video-channel-object'
|
import { VideoChannelObject } from '../../shared/models/activitypub/objects/video-channel-object'
|
||||||
import { ResultList } from '../../shared/models/result-list.model'
|
import { ResultList } from '../../shared/models/result-list.model'
|
||||||
|
@ -17,6 +18,7 @@ import { VideoInstance } from '../models/video/video-interface'
|
||||||
import { isRemoteAccountValid } from './custom-validators'
|
import { isRemoteAccountValid } from './custom-validators'
|
||||||
import { isVideoChannelObjectValid } from './custom-validators/activitypub/videos'
|
import { isVideoChannelObjectValid } from './custom-validators/activitypub/videos'
|
||||||
import { logger } from './logger'
|
import { logger } from './logger'
|
||||||
|
import { signObject } from './peertube-crypto'
|
||||||
import { doRequest, doRequestAndSaveToFile } from './requests'
|
import { doRequest, doRequestAndSaveToFile } from './requests'
|
||||||
import { getServerAccount } from './utils'
|
import { getServerAccount } from './utils'
|
||||||
|
|
||||||
|
@ -239,6 +241,12 @@ function activityPubCollectionPagination (url: string, page: number, result: Res
|
||||||
return activityPubContextify(obj)
|
return activityPubContextify(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildSignedActivity (byAccount: AccountInstance, data: Object) {
|
||||||
|
const activity = activityPubContextify(data)
|
||||||
|
|
||||||
|
return signObject(byAccount, activity) as Promise<Activity>
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -252,7 +260,8 @@ export {
|
||||||
fetchRemoteVideoDescription,
|
fetchRemoteVideoDescription,
|
||||||
shareVideoChannelByServer,
|
shareVideoChannelByServer,
|
||||||
shareVideoByServer,
|
shareVideoByServer,
|
||||||
getOrCreateVideoChannel
|
getOrCreateVideoChannel,
|
||||||
|
buildSignedActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -260,7 +260,7 @@ const JOB_STATES: { [ id: string ]: JobState } = {
|
||||||
}
|
}
|
||||||
const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
|
const JOB_CATEGORIES: { [ id: string ]: JobCategory } = {
|
||||||
TRANSCODING: 'transcoding',
|
TRANSCODING: 'transcoding',
|
||||||
HTTP_REQUEST: 'http-request'
|
ACTIVITYPUB_HTTP: 'activitypub-http'
|
||||||
}
|
}
|
||||||
// How many maximum jobs we fetch from the database per cycle
|
// How many maximum jobs we fetch from the database per cycle
|
||||||
const JOBS_FETCH_LIMIT_PER_CYCLE = {
|
const JOBS_FETCH_LIMIT_PER_CYCLE = {
|
||||||
|
|
|
@ -1,116 +1,124 @@
|
||||||
import * as Sequelize from 'sequelize'
|
import { Transaction } from 'sequelize'
|
||||||
|
|
||||||
import { database as db } from '../../initializers'
|
|
||||||
import {
|
import {
|
||||||
AccountInstance,
|
ActivityAccept,
|
||||||
VideoInstance,
|
ActivityAdd,
|
||||||
VideoChannelInstance
|
ActivityCreate,
|
||||||
} from '../../models'
|
ActivityDelete,
|
||||||
import { httpRequestJobScheduler } from '../jobs'
|
ActivityFollow,
|
||||||
import { signObject, activityPubContextify } from '../../helpers'
|
ActivityUpdate
|
||||||
import { Activity, VideoAbuseObject } from '../../../shared'
|
} from '../../../shared/models/activitypub/activity'
|
||||||
import { VideoAbuseInstance } from '../../models/video/video-abuse-interface'
|
|
||||||
import { getActivityPubUrl } from '../../helpers/activitypub'
|
import { getActivityPubUrl } from '../../helpers/activitypub'
|
||||||
import { logger } from '../../helpers/logger'
|
import { logger } from '../../helpers/logger'
|
||||||
|
import { database as db } from '../../initializers'
|
||||||
|
import { AccountInstance, VideoChannelInstance, VideoInstance } from '../../models'
|
||||||
|
import { VideoAbuseInstance } from '../../models/video/video-abuse-interface'
|
||||||
|
import { activitypubHttpJobScheduler } from '../jobs'
|
||||||
|
|
||||||
|
async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
|
const byAccount = videoChannel.Account
|
||||||
|
|
||||||
async function sendCreateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
|
|
||||||
const videoChannelObject = videoChannel.toActivityPubObject()
|
const videoChannelObject = videoChannel.toActivityPubObject()
|
||||||
const data = await createActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
|
const data = await createActivityData(videoChannel.url, byAccount, videoChannelObject)
|
||||||
|
|
||||||
return broadcastToFollowers(data, [ videoChannel.Account ], t)
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
|
async function sendUpdateVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
|
const byAccount = videoChannel.Account
|
||||||
|
|
||||||
const videoChannelObject = videoChannel.toActivityPubObject()
|
const videoChannelObject = videoChannel.toActivityPubObject()
|
||||||
const data = await updateActivityData(videoChannel.url, videoChannel.Account, videoChannelObject)
|
const data = await updateActivityData(videoChannel.url, byAccount, videoChannelObject)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
||||||
accountsInvolved.push(videoChannel.Account)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
|
async function sendDeleteVideoChannel (videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
const data = await deleteActivityData(videoChannel.url, videoChannel.Account)
|
const byAccount = videoChannel.Account
|
||||||
|
|
||||||
|
const data = await deleteActivityData(videoChannel.url, byAccount)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
const accountsInvolved = await db.VideoChannelShare.loadAccountsByShare(videoChannel.id)
|
||||||
accountsInvolved.push(videoChannel.Account)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendAddVideo (video: VideoInstance, t: Sequelize.Transaction) {
|
async function sendAddVideo (video: VideoInstance, t: Transaction) {
|
||||||
const videoObject = video.toActivityPubObject()
|
const byAccount = video.VideoChannel.Account
|
||||||
const data = await addActivityData(video.url, video.VideoChannel.Account, video.VideoChannel.url, videoObject)
|
|
||||||
|
|
||||||
return broadcastToFollowers(data, [ video.VideoChannel.Account ], t)
|
const videoObject = video.toActivityPubObject()
|
||||||
|
const data = await addActivityData(video.url, byAccount, video.VideoChannel.url, videoObject)
|
||||||
|
|
||||||
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendUpdateVideo (video: VideoInstance, t: Sequelize.Transaction) {
|
async function sendUpdateVideo (video: VideoInstance, t: Transaction) {
|
||||||
|
const byAccount = video.VideoChannel.Account
|
||||||
|
|
||||||
const videoObject = video.toActivityPubObject()
|
const videoObject = video.toActivityPubObject()
|
||||||
const data = await updateActivityData(video.url, video.VideoChannel.Account, videoObject)
|
const data = await updateActivityData(video.url, byAccount, videoObject)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
||||||
accountsInvolved.push(video.VideoChannel.Account)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendDeleteVideo (video: VideoInstance, t: Sequelize.Transaction) {
|
async function sendDeleteVideo (video: VideoInstance, t: Transaction) {
|
||||||
const data = await deleteActivityData(video.url, video.VideoChannel.Account)
|
const byAccount = video.VideoChannel.Account
|
||||||
|
|
||||||
|
const data = await deleteActivityData(video.url, byAccount)
|
||||||
|
|
||||||
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
const accountsInvolved = await db.VideoShare.loadAccountsByShare(video.id)
|
||||||
accountsInvolved.push(video.VideoChannel.Account)
|
accountsInvolved.push(byAccount)
|
||||||
|
|
||||||
return broadcastToFollowers(data, accountsInvolved, t)
|
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendDeleteAccount (account: AccountInstance, t: Sequelize.Transaction) {
|
async function sendDeleteAccount (account: AccountInstance, t: Transaction) {
|
||||||
const data = await deleteActivityData(account.url, account)
|
const data = await deleteActivityData(account.url, account)
|
||||||
|
|
||||||
return broadcastToFollowers(data, [ account ], t)
|
return broadcastToFollowers(data, account, [ account ], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendVideoChannelAnnounce (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Sequelize.Transaction) {
|
async function sendVideoChannelAnnounce (byAccount: AccountInstance, videoChannel: VideoChannelInstance, t: Transaction) {
|
||||||
const url = getActivityPubUrl('videoChannel', videoChannel.uuid) + '#announce'
|
const url = getActivityPubUrl('videoChannel', videoChannel.uuid) + '#announce'
|
||||||
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject(), true)
|
const announcedActivity = await createActivityData(url, videoChannel.Account, videoChannel.toActivityPubObject())
|
||||||
|
|
||||||
const data = await announceActivityData(url, byAccount, announcedActivity)
|
const data = await announceActivityData(url, byAccount, announcedActivity)
|
||||||
return broadcastToFollowers(data, [ byAccount ], t)
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstance, t: Sequelize.Transaction) {
|
async function sendVideoAnnounce (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
|
||||||
const url = getActivityPubUrl('video', video.uuid) + '#announce'
|
const url = getActivityPubUrl('video', video.uuid) + '#announce'
|
||||||
|
|
||||||
const videoChannel = video.VideoChannel
|
const videoChannel = video.VideoChannel
|
||||||
const announcedActivity = await addActivityData(url, videoChannel.Account, videoChannel.url, video.toActivityPubObject(), true)
|
const announcedActivity = await addActivityData(url, videoChannel.Account, videoChannel.url, video.toActivityPubObject())
|
||||||
|
|
||||||
const data = await announceActivityData(url, byAccount, announcedActivity)
|
const data = await announceActivityData(url, byAccount, announcedActivity)
|
||||||
return broadcastToFollowers(data, [ byAccount ], t)
|
return broadcastToFollowers(data, byAccount, [ byAccount ], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendVideoAbuse (
|
async function sendVideoAbuse (byAccount: AccountInstance, videoAbuse: VideoAbuseInstance, video: VideoInstance, t: Transaction) {
|
||||||
fromAccount: AccountInstance,
|
|
||||||
videoAbuse: VideoAbuseInstance,
|
|
||||||
video: VideoInstance,
|
|
||||||
t: Sequelize.Transaction
|
|
||||||
) {
|
|
||||||
const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString())
|
const url = getActivityPubUrl('videoAbuse', videoAbuse.id.toString())
|
||||||
const data = await createActivityData(url, fromAccount, videoAbuse.toActivityPubObject())
|
const data = await createActivityData(url, byAccount, videoAbuse.toActivityPubObject())
|
||||||
|
|
||||||
return unicastTo(data, video.VideoChannel.Account.sharedInboxUrl, t)
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendAccept (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
|
async function sendAccept (byAccount: AccountInstance, toAccount: AccountInstance, t: Transaction) {
|
||||||
const data = await acceptActivityData(fromAccount)
|
const data = await acceptActivityData(byAccount)
|
||||||
|
|
||||||
return unicastTo(data, toAccount.inboxUrl, t)
|
return unicastTo(data, byAccount, toAccount.inboxUrl, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendFollow (fromAccount: AccountInstance, toAccount: AccountInstance, t: Sequelize.Transaction) {
|
async function sendFollow (byAccount: AccountInstance, toAccount: AccountInstance, t: Transaction) {
|
||||||
const data = await followActivityData(toAccount.url, fromAccount)
|
const data = await followActivityData(toAccount.url, byAccount)
|
||||||
|
|
||||||
return unicastTo(data, toAccount.inboxUrl, t)
|
return unicastTo(data, byAccount, toAccount.inboxUrl, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@ -132,7 +140,7 @@ export {
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function broadcastToFollowers (data: any, toAccountFollowers: AccountInstance[], t: Sequelize.Transaction) {
|
async function broadcastToFollowers (data: any, byAccount: AccountInstance, toAccountFollowers: AccountInstance[], t: Transaction) {
|
||||||
const toAccountFollowerIds = toAccountFollowers.map(a => a.id)
|
const toAccountFollowerIds = toAccountFollowers.map(a => a.id)
|
||||||
const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds)
|
const result = await db.AccountFollow.listAcceptedFollowerSharedInboxUrls(toAccountFollowerIds)
|
||||||
if (result.data.length === 0) {
|
if (result.data.length === 0) {
|
||||||
|
@ -142,25 +150,21 @@ async function broadcastToFollowers (data: any, toAccountFollowers: AccountInsta
|
||||||
|
|
||||||
const jobPayload = {
|
const jobPayload = {
|
||||||
uris: result.data,
|
uris: result.data,
|
||||||
|
signatureAccountId: byAccount.id,
|
||||||
body: data
|
body: data
|
||||||
}
|
}
|
||||||
|
|
||||||
return httpRequestJobScheduler.createJob(t, 'httpRequestBroadcastHandler', jobPayload)
|
return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpBroadcastHandler', jobPayload)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function unicastTo (data: any, toAccountUrl: string, t: Sequelize.Transaction) {
|
async function unicastTo (data: any, byAccount: AccountInstance, toAccountUrl: string, t: Transaction) {
|
||||||
const jobPayload = {
|
const jobPayload = {
|
||||||
uris: [ toAccountUrl ],
|
uris: [ toAccountUrl ],
|
||||||
|
signatureAccountId: byAccount.id,
|
||||||
body: data
|
body: data
|
||||||
}
|
}
|
||||||
|
|
||||||
return httpRequestJobScheduler.createJob(t, 'httpRequestUnicastHandler', jobPayload)
|
return activitypubHttpJobScheduler.createJob(t, 'activitypubHttpUnicastHandler', jobPayload)
|
||||||
}
|
|
||||||
|
|
||||||
function buildSignedActivity (byAccount: AccountInstance, data: Object) {
|
|
||||||
const activity = activityPubContextify(data)
|
|
||||||
|
|
||||||
return signObject(byAccount, activity) as Promise<Activity>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPublicActivityTo (account: AccountInstance) {
|
async function getPublicActivityTo (account: AccountInstance) {
|
||||||
|
@ -169,9 +173,9 @@ async function getPublicActivityTo (account: AccountInstance) {
|
||||||
return inboxUrls.concat('https://www.w3.org/ns/activitystreams#Public')
|
return inboxUrls.concat('https://www.w3.org/ns/activitystreams#Public')
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createActivityData (url: string, byAccount: AccountInstance, object: any, raw = false) {
|
async function createActivityData (url: string, byAccount: AccountInstance, object: any) {
|
||||||
const to = await getPublicActivityTo(byAccount)
|
const to = await getPublicActivityTo(byAccount)
|
||||||
const base = {
|
const activity: ActivityCreate = {
|
||||||
type: 'Create',
|
type: 'Create',
|
||||||
id: url,
|
id: url,
|
||||||
actor: byAccount.url,
|
actor: byAccount.url,
|
||||||
|
@ -179,14 +183,12 @@ async function createActivityData (url: string, byAccount: AccountInstance, obje
|
||||||
object
|
object
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw === true) return base
|
return activity
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
|
async function updateActivityData (url: string, byAccount: AccountInstance, object: any) {
|
||||||
const to = await getPublicActivityTo(byAccount)
|
const to = await getPublicActivityTo(byAccount)
|
||||||
const base = {
|
const activity: ActivityUpdate = {
|
||||||
type: 'Update',
|
type: 'Update',
|
||||||
id: url,
|
id: url,
|
||||||
actor: byAccount.url,
|
actor: byAccount.url,
|
||||||
|
@ -194,22 +196,22 @@ async function updateActivityData (url: string, byAccount: AccountInstance, obje
|
||||||
object
|
object
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteActivityData (url: string, byAccount: AccountInstance) {
|
async function deleteActivityData (url: string, byAccount: AccountInstance) {
|
||||||
const base = {
|
const activity: ActivityDelete = {
|
||||||
type: 'Delete',
|
type: 'Delete',
|
||||||
id: url,
|
id: url,
|
||||||
actor: byAccount.url
|
actor: byAccount.url
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any, raw = false) {
|
async function addActivityData (url: string, byAccount: AccountInstance, target: string, object: any) {
|
||||||
const to = await getPublicActivityTo(byAccount)
|
const to = await getPublicActivityTo(byAccount)
|
||||||
const base = {
|
const activity: ActivityAdd = {
|
||||||
type: 'Add',
|
type: 'Add',
|
||||||
id: url,
|
id: url,
|
||||||
actor: byAccount.url,
|
actor: byAccount.url,
|
||||||
|
@ -218,39 +220,37 @@ async function addActivityData (url: string, byAccount: AccountInstance, target:
|
||||||
target
|
target
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw === true) return base
|
return activity
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function announceActivityData (url: string, byAccount: AccountInstance, object: any) {
|
async function announceActivityData (url: string, byAccount: AccountInstance, object: any) {
|
||||||
const base = {
|
const activity = {
|
||||||
type: 'Announce',
|
type: 'Announce',
|
||||||
id: url,
|
id: url,
|
||||||
actor: byAccount.url,
|
actor: byAccount.url,
|
||||||
object
|
object
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
async function followActivityData (url: string, byAccount: AccountInstance) {
|
async function followActivityData (url: string, byAccount: AccountInstance) {
|
||||||
const base = {
|
const activity: ActivityFollow = {
|
||||||
type: 'Follow',
|
type: 'Follow',
|
||||||
id: byAccount.url,
|
id: byAccount.url,
|
||||||
actor: byAccount.url,
|
actor: byAccount.url,
|
||||||
object: url
|
object: url
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
async function acceptActivityData (byAccount: AccountInstance) {
|
async function acceptActivityData (byAccount: AccountInstance) {
|
||||||
const base = {
|
const activity: ActivityAccept = {
|
||||||
type: 'Accept',
|
type: 'Accept',
|
||||||
id: byAccount.url,
|
id: byAccount.url,
|
||||||
actor: byAccount.url
|
actor: byAccount.url
|
||||||
}
|
}
|
||||||
|
|
||||||
return buildSignedActivity(byAccount, base)
|
return activity
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import { logger } from '../../../helpers'
|
||||||
|
import { buildSignedActivity } from '../../../helpers/activitypub'
|
||||||
|
import { doRequest } from '../../../helpers/requests'
|
||||||
|
import { database as db } from '../../../initializers'
|
||||||
|
import { ActivityPubHttpPayload } from './activitypub-http-job-scheduler'
|
||||||
|
|
||||||
|
async function process (payload: ActivityPubHttpPayload, jobId: number) {
|
||||||
|
logger.info('Processing ActivityPub broadcast in job %d.', jobId)
|
||||||
|
|
||||||
|
const accountSignature = await db.Account.load(payload.signatureAccountId)
|
||||||
|
if (!accountSignature) throw new Error('Unknown signature account id.')
|
||||||
|
|
||||||
|
const signedBody = await buildSignedActivity(accountSignature, payload.body)
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
uri: '',
|
||||||
|
json: signedBody
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const uri of payload.uris) {
|
||||||
|
options.uri = uri
|
||||||
|
await doRequest(options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError (err: Error, jobId: number) {
|
||||||
|
logger.error('Error when broadcasting ActivityPub request in job %d.', jobId, err)
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSuccess (jobId: number) {
|
||||||
|
logger.info('Job %d is a success.', jobId)
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export {
|
||||||
|
process,
|
||||||
|
onError,
|
||||||
|
onSuccess
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { JobScheduler, JobHandler } from '../job-scheduler'
|
||||||
|
|
||||||
|
import * as activitypubHttpBroadcastHandler from './activitypub-http-broadcast-handler'
|
||||||
|
import * as activitypubHttpUnicastHandler from './activitypub-http-unicast-handler'
|
||||||
|
import { JobCategory } from '../../../../shared'
|
||||||
|
|
||||||
|
type ActivityPubHttpPayload = {
|
||||||
|
uris: string[]
|
||||||
|
signatureAccountId: number
|
||||||
|
body: any
|
||||||
|
}
|
||||||
|
const jobHandlers: { [ handlerName: string ]: JobHandler<ActivityPubHttpPayload, void> } = {
|
||||||
|
activitypubHttpBroadcastHandler,
|
||||||
|
activitypubHttpUnicastHandler
|
||||||
|
}
|
||||||
|
const jobCategory: JobCategory = 'activitypub-http'
|
||||||
|
|
||||||
|
const activitypubHttpJobScheduler = new JobScheduler(jobCategory, jobHandlers)
|
||||||
|
|
||||||
|
export {
|
||||||
|
ActivityPubHttpPayload,
|
||||||
|
activitypubHttpJobScheduler
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { logger } from '../../../helpers'
|
||||||
|
import { doRequest } from '../../../helpers/requests'
|
||||||
|
import { ActivityPubHttpPayload } from './activitypub-http-job-scheduler'
|
||||||
|
import { database as db } from '../../../initializers/database'
|
||||||
|
import { buildSignedActivity } from '../../../helpers/activitypub'
|
||||||
|
|
||||||
|
async function process (payload: ActivityPubHttpPayload, jobId: number) {
|
||||||
|
logger.info('Processing ActivityPub unicast in job %d.', jobId)
|
||||||
|
|
||||||
|
const accountSignature = await db.Account.load(payload.signatureAccountId)
|
||||||
|
if (!accountSignature) throw new Error('Unknown signature account id.')
|
||||||
|
|
||||||
|
const signedBody = await buildSignedActivity(accountSignature, payload.body)
|
||||||
|
const uri = payload.uris[0]
|
||||||
|
const options = {
|
||||||
|
method: 'POST',
|
||||||
|
uri,
|
||||||
|
json: signedBody
|
||||||
|
}
|
||||||
|
|
||||||
|
await doRequest(options)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError (err: Error, jobId: number) {
|
||||||
|
logger.error('Error when sending ActivityPub request in job %d.', jobId, err)
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSuccess (jobId: number) {
|
||||||
|
logger.info('Job %d is a success.', jobId)
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export {
|
||||||
|
process,
|
||||||
|
onError,
|
||||||
|
onSuccess
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './activitypub-http-job-scheduler'
|
|
@ -1,36 +0,0 @@
|
||||||
import { logger } from '../../../helpers'
|
|
||||||
import { doRequest } from '../../../helpers/requests'
|
|
||||||
import { HTTPRequestPayload } from './http-request-job-scheduler'
|
|
||||||
|
|
||||||
async function process (payload: HTTPRequestPayload, jobId: number) {
|
|
||||||
logger.info('Processing broadcast in job %d.', jobId)
|
|
||||||
|
|
||||||
const options = {
|
|
||||||
method: 'POST',
|
|
||||||
uri: '',
|
|
||||||
json: payload.body
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const uri of payload.uris) {
|
|
||||||
options.uri = uri
|
|
||||||
await doRequest(options)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function onError (err: Error, jobId: number) {
|
|
||||||
logger.error('Error when broadcasting request in job %d.', jobId, err)
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSuccess (jobId: number) {
|
|
||||||
logger.info('Job %d is a success.', jobId)
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export {
|
|
||||||
process,
|
|
||||||
onError,
|
|
||||||
onSuccess
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
import { JobScheduler, JobHandler } from '../job-scheduler'
|
|
||||||
|
|
||||||
import * as httpRequestBroadcastHandler from './http-request-broadcast-handler'
|
|
||||||
import * as httpRequestUnicastHandler from './http-request-unicast-handler'
|
|
||||||
import { JobCategory } from '../../../../shared'
|
|
||||||
|
|
||||||
type HTTPRequestPayload = {
|
|
||||||
uris: string[]
|
|
||||||
body: any
|
|
||||||
}
|
|
||||||
const jobHandlers: { [ handlerName: string ]: JobHandler<HTTPRequestPayload, void> } = {
|
|
||||||
httpRequestBroadcastHandler,
|
|
||||||
httpRequestUnicastHandler
|
|
||||||
}
|
|
||||||
const jobCategory: JobCategory = 'http-request'
|
|
||||||
|
|
||||||
const httpRequestJobScheduler = new JobScheduler(jobCategory, jobHandlers)
|
|
||||||
|
|
||||||
export {
|
|
||||||
HTTPRequestPayload,
|
|
||||||
httpRequestJobScheduler
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
import { logger } from '../../../helpers'
|
|
||||||
import { doRequest } from '../../../helpers/requests'
|
|
||||||
import { HTTPRequestPayload } from './http-request-job-scheduler'
|
|
||||||
|
|
||||||
async function process (payload: HTTPRequestPayload, jobId: number) {
|
|
||||||
logger.info('Processing unicast in job %d.', jobId)
|
|
||||||
|
|
||||||
const uri = payload.uris[0]
|
|
||||||
const options = {
|
|
||||||
method: 'POST',
|
|
||||||
uri,
|
|
||||||
json: payload.body
|
|
||||||
}
|
|
||||||
|
|
||||||
await doRequest(options)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onError (err: Error, jobId: number) {
|
|
||||||
logger.error('Error when sending request in job %d.', jobId, err)
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
function onSuccess (jobId: number) {
|
|
||||||
logger.info('Job %d is a success.', jobId)
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
export {
|
|
||||||
process,
|
|
||||||
onError,
|
|
||||||
onSuccess
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
export * from './http-request-job-scheduler'
|
|
|
@ -1,2 +1,2 @@
|
||||||
export * from './http-request-job-scheduler'
|
export * from './activitypub-http-job-scheduler'
|
||||||
export * from './transcoding-job-scheduler'
|
export * from './transcoding-job-scheduler'
|
||||||
|
|
|
@ -10,4 +10,3 @@ import './video-blacklist-management'
|
||||||
import './video-description'
|
import './video-description'
|
||||||
import './video-privacy'
|
import './video-privacy'
|
||||||
import './services'
|
import './services'
|
||||||
import './request-schedulers'
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ describe('Test multiple pods', function () {
|
||||||
expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
|
expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
expect(dateIsValid(video.updatedAt)).to.be.true
|
expect(dateIsValid(video.updatedAt)).to.be.true
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
|
|
||||||
const res2 = await getVideo(server.url, video.uuid)
|
const res2 = await getVideo(server.url, video.uuid)
|
||||||
const videoDetails = res2.body
|
const videoDetails = res2.body
|
||||||
|
@ -202,7 +202,7 @@ describe('Test multiple pods', function () {
|
||||||
expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
|
expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
expect(dateIsValid(video.updatedAt)).to.be.true
|
expect(dateIsValid(video.updatedAt)).to.be.true
|
||||||
expect(video.author).to.equal('user1')
|
expect(video.account).to.equal('user1')
|
||||||
|
|
||||||
if (server.url !== 'http://localhost:9002') {
|
if (server.url !== 'http://localhost:9002') {
|
||||||
expect(video.isLocal).to.be.false
|
expect(video.isLocal).to.be.false
|
||||||
|
@ -696,7 +696,7 @@ describe('Test multiple pods', function () {
|
||||||
expect(baseVideo.licence).to.equal(video.licence)
|
expect(baseVideo.licence).to.equal(video.licence)
|
||||||
expect(baseVideo.category).to.equal(video.category)
|
expect(baseVideo.category).to.equal(video.category)
|
||||||
expect(baseVideo.nsfw).to.equal(video.nsfw)
|
expect(baseVideo.nsfw).to.equal(video.nsfw)
|
||||||
expect(baseVideo.author).to.equal(video.author)
|
expect(baseVideo.author).to.equal(video.account)
|
||||||
expect(baseVideo.tags).to.deep.equal(video.tags)
|
expect(baseVideo.tags).to.deep.equal(video.tags)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
/* tslint:disable:no-unused-expression */
|
|
||||||
|
|
||||||
import 'mocha'
|
|
||||||
import * as chai from 'chai'
|
|
||||||
const expect = chai.expect
|
|
||||||
|
|
||||||
import {
|
|
||||||
ServerInfo,
|
|
||||||
flushTests,
|
|
||||||
uploadVideo,
|
|
||||||
makeFriends,
|
|
||||||
wait,
|
|
||||||
setAccessTokensToServers,
|
|
||||||
flushAndRunMultipleServers,
|
|
||||||
getRequestsStats,
|
|
||||||
killallServers
|
|
||||||
} from '../utils'
|
|
||||||
|
|
||||||
describe('Test requests schedulers stats', function () {
|
|
||||||
const requestSchedulerNames = [ 'requestScheduler', 'requestVideoQaduScheduler', 'requestVideoEventScheduler' ]
|
|
||||||
let servers: ServerInfo[] = []
|
|
||||||
|
|
||||||
function uploadVideoWrapper (server: ServerInfo) {
|
|
||||||
const videoAttributes = {
|
|
||||||
tags: [ 'tag1', 'tag2' ]
|
|
||||||
}
|
|
||||||
|
|
||||||
return uploadVideo(server.url, server.accessToken, videoAttributes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------
|
|
||||||
|
|
||||||
before(async function () {
|
|
||||||
this.timeout(120000)
|
|
||||||
|
|
||||||
servers = await flushAndRunMultipleServers(2)
|
|
||||||
|
|
||||||
await setAccessTokensToServers(servers)
|
|
||||||
|
|
||||||
await makeFriends(servers[0].url, servers[0].accessToken)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should have a correct timer', async function () {
|
|
||||||
const server = servers[0]
|
|
||||||
|
|
||||||
const res = await getRequestsStats(server)
|
|
||||||
|
|
||||||
const requestSchedulers = res.body
|
|
||||||
for (const requestSchedulerName of requestSchedulerNames) {
|
|
||||||
const requestScheduler = requestSchedulers[requestSchedulerName]
|
|
||||||
|
|
||||||
expect(requestScheduler.remainingMilliSeconds).to.be.at.least(0)
|
|
||||||
expect(requestScheduler.remainingMilliSeconds).to.be.at.most(10000)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should have the correct total request', async function () {
|
|
||||||
this.timeout(15000)
|
|
||||||
|
|
||||||
const server = servers[0]
|
|
||||||
// Ensure the requests of pod 1 won't be made
|
|
||||||
servers[1].app.kill()
|
|
||||||
|
|
||||||
await uploadVideoWrapper(server)
|
|
||||||
|
|
||||||
await wait(1000)
|
|
||||||
|
|
||||||
const res = await getRequestsStats(server)
|
|
||||||
const requestSchedulers = res.body
|
|
||||||
const requestScheduler = requestSchedulers.requestScheduler
|
|
||||||
expect(requestScheduler.totalRequests).to.equal(3)
|
|
||||||
})
|
|
||||||
|
|
||||||
after(async function () {
|
|
||||||
// Server 1 has already been killed
|
|
||||||
killallServers([ servers[0] ])
|
|
||||||
|
|
||||||
if (this['ok']) {
|
|
||||||
await flushTests()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -14,6 +14,7 @@ import {
|
||||||
getOEmbed
|
getOEmbed
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { runServer } from '../utils/servers'
|
import { runServer } from '../utils/servers'
|
||||||
|
import { Video } from '../../../client/src/app/videos/shared/video.model'
|
||||||
|
|
||||||
describe('Test services', function () {
|
describe('Test services', function () {
|
||||||
let server: ServerInfo = null
|
let server: ServerInfo = null
|
||||||
|
@ -46,7 +47,7 @@ describe('Test services', function () {
|
||||||
|
|
||||||
expect(res.body.html).to.equal(expectedHtml)
|
expect(res.body.html).to.equal(expectedHtml)
|
||||||
expect(res.body.title).to.equal(server.video.name)
|
expect(res.body.title).to.equal(server.video.name)
|
||||||
expect(res.body.author_name).to.equal(server.video.author)
|
expect(res.body.author_name).to.equal(server.video.account)
|
||||||
expect(res.body.width).to.equal(560)
|
expect(res.body.width).to.equal(560)
|
||||||
expect(res.body.height).to.equal(315)
|
expect(res.body.height).to.equal(315)
|
||||||
expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
|
expect(res.body.thumbnail_url).to.equal(expectedThumbnailUrl)
|
||||||
|
@ -66,7 +67,7 @@ describe('Test services', function () {
|
||||||
|
|
||||||
expect(res.body.html).to.equal(expectedHtml)
|
expect(res.body.html).to.equal(expectedHtml)
|
||||||
expect(res.body.title).to.equal(server.video.name)
|
expect(res.body.title).to.equal(server.video.name)
|
||||||
expect(res.body.author_name).to.equal(server.video.author)
|
expect(res.body.author_name).to.equal(server.video.account)
|
||||||
expect(res.body.height).to.equal(50)
|
expect(res.body.height).to.equal(50)
|
||||||
expect(res.body.width).to.equal(50)
|
expect(res.body.width).to.equal(50)
|
||||||
expect(res.body).to.not.have.property('thumbnail_url')
|
expect(res.body).to.not.have.property('thumbnail_url')
|
||||||
|
|
|
@ -125,8 +125,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Mandarin')
|
expect(video.languageLabel).to.equal('Mandarin')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('my super description')
|
expect(video.description).to.equal('my super description')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
@ -174,8 +174,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Mandarin')
|
expect(video.languageLabel).to.equal('Mandarin')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('my super description')
|
expect(video.description).to.equal('my super description')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
@ -237,8 +237,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Mandarin')
|
expect(video.languageLabel).to.equal('Mandarin')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('my super description')
|
expect(video.description).to.equal('my super description')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
@ -249,7 +249,7 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Not implemented yet
|
// Not implemented yet
|
||||||
// it('Should search the video by podHost', async function () {
|
// it('Should search the video by serverHost', async function () {
|
||||||
// const res = await videosUtils.searchVideo(server.url, '9001', 'host')
|
// const res = await videosUtils.searchVideo(server.url, '9001', 'host')
|
||||||
|
|
||||||
// expect(res.body.total).to.equal(1)
|
// expect(res.body.total).to.equal(1)
|
||||||
|
@ -259,7 +259,7 @@ describe('Test a single pod', function () {
|
||||||
// const video = res.body.data[0]
|
// const video = res.body.data[0]
|
||||||
// expect(video.name).to.equal('my super name')
|
// expect(video.name).to.equal('my super name')
|
||||||
// expect(video.description).to.equal('my super description')
|
// expect(video.description).to.equal('my super description')
|
||||||
// expect(video.podHost).to.equal('localhost:9001')
|
// expect(video.serverHost).to.equal('localhost:9001')
|
||||||
// expect(video.author).to.equal('root')
|
// expect(video.author).to.equal('root')
|
||||||
// expect(video.isLocal).to.be.true
|
// expect(video.isLocal).to.be.true
|
||||||
// expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
// expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
||||||
|
@ -291,8 +291,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Mandarin')
|
expect(video.languageLabel).to.equal('Mandarin')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('my super description')
|
expect(video.description).to.equal('my super description')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
@ -311,7 +311,7 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not find a search by author', async function () {
|
it('Should not find a search by author', async function () {
|
||||||
const res = await searchVideo(server.url, 'hello', 'author')
|
const res = await searchVideo(server.url, 'hello', 'account')
|
||||||
|
|
||||||
expect(res.body.total).to.equal(0)
|
expect(res.body.total).to.equal(0)
|
||||||
expect(res.body.data).to.be.an('array')
|
expect(res.body.data).to.be.an('array')
|
||||||
|
@ -352,7 +352,7 @@ describe('Test a single pod', function () {
|
||||||
'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
|
'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
|
||||||
]
|
]
|
||||||
|
|
||||||
const tasks: Promise<any>[] = []
|
// const tasks: Promise<any>[] = []
|
||||||
for (const video of videos) {
|
for (const video of videos) {
|
||||||
const videoAttributes = {
|
const videoAttributes = {
|
||||||
name: video + ' name',
|
name: video + ' name',
|
||||||
|
@ -366,10 +366,13 @@ describe('Test a single pod', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
const p = uploadVideo(server.url, server.accessToken, videoAttributes)
|
const p = uploadVideo(server.url, server.accessToken, videoAttributes)
|
||||||
tasks.push(p)
|
await p
|
||||||
}
|
}
|
||||||
|
// FIXME: concurrent uploads does not work :(
|
||||||
await Promise.all(tasks)
|
// tasks.push(p)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// await Promise.all(tasks)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have the correct durations', async function () {
|
it('Should have the correct durations', async function () {
|
||||||
|
@ -462,7 +465,7 @@ describe('Test a single pod', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should search all the root author videos', async function () {
|
it('Should search all the root author videos', async function () {
|
||||||
const res = await searchVideoWithPagination(server.url, 'root', 'author', 0, 15)
|
const res = await searchVideoWithPagination(server.url, 'root', 'account', 0, 15)
|
||||||
|
|
||||||
const videos = res.body.data
|
const videos = res.body.data
|
||||||
expect(res.body.total).to.equal(6)
|
expect(res.body.total).to.equal(6)
|
||||||
|
@ -550,8 +553,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Arabic')
|
expect(video.languageLabel).to.equal('Arabic')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('my super description updated')
|
expect(video.description).to.equal('my super description updated')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
|
expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
@ -599,8 +602,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Arabic')
|
expect(video.languageLabel).to.equal('Arabic')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('my super description updated')
|
expect(video.description).to.equal('my super description updated')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
|
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
@ -639,8 +642,8 @@ describe('Test a single pod', function () {
|
||||||
expect(video.languageLabel).to.equal('Arabic')
|
expect(video.languageLabel).to.equal('Arabic')
|
||||||
expect(video.nsfw).to.be.ok
|
expect(video.nsfw).to.be.ok
|
||||||
expect(video.description).to.equal('hello everybody')
|
expect(video.description).to.equal('hello everybody')
|
||||||
expect(video.podHost).to.equal('localhost:9001')
|
expect(video.serverHost).to.equal('localhost:9001')
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account).to.equal('root')
|
||||||
expect(video.isLocal).to.be.true
|
expect(video.isLocal).to.be.true
|
||||||
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
|
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
|
||||||
expect(dateIsValid(video.createdAt)).to.be.true
|
expect(dateIsValid(video.createdAt)).to.be.true
|
||||||
|
|
|
@ -1,38 +1,36 @@
|
||||||
/* tslint:disable:no-unused-expression */
|
/* tslint:disable:no-unused-expression */
|
||||||
|
|
||||||
import 'mocha'
|
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
const expect = chai.expect
|
import 'mocha'
|
||||||
|
import { UserRole } from '../../../shared'
|
||||||
import {
|
import {
|
||||||
ServerInfo,
|
|
||||||
flushTests,
|
|
||||||
runServer,
|
|
||||||
login,
|
|
||||||
uploadVideo,
|
|
||||||
makeFriends,
|
|
||||||
quitFriends,
|
|
||||||
getVideosList,
|
|
||||||
rateVideo,
|
|
||||||
getUserVideoRating,
|
|
||||||
removeVideo,
|
|
||||||
makePutBodyRequest,
|
|
||||||
createUser,
|
createUser,
|
||||||
loginAndGetAccessToken,
|
flushTests,
|
||||||
|
getBlacklistedVideosList,
|
||||||
getMyUserInformation,
|
getMyUserInformation,
|
||||||
|
getUserInformation,
|
||||||
getUsersList,
|
getUsersList,
|
||||||
getUsersListPaginationAndSort,
|
getUsersListPaginationAndSort,
|
||||||
updateUser,
|
getUserVideoRating,
|
||||||
updateMyUser,
|
getVideosList,
|
||||||
|
killallServers,
|
||||||
|
login,
|
||||||
|
loginAndGetAccessToken,
|
||||||
|
makePutBodyRequest,
|
||||||
|
rateVideo,
|
||||||
registerUser,
|
registerUser,
|
||||||
removeUser,
|
removeUser,
|
||||||
killallServers,
|
removeVideo,
|
||||||
getUserInformation,
|
runServer,
|
||||||
getBlacklistedVideosList
|
ServerInfo,
|
||||||
|
updateMyUser,
|
||||||
|
updateUser,
|
||||||
|
uploadVideo
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
import { UserRole } from '../../../shared'
|
import { follow } from '../utils/follows'
|
||||||
import { getMyVideos } from '../utils/videos'
|
import { getMyVideos } from '../utils/videos'
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Test users', function () {
|
describe('Test users', function () {
|
||||||
let server: ServerInfo
|
let server: ServerInfo
|
||||||
let accessToken: string
|
let accessToken: string
|
||||||
|
@ -57,28 +55,36 @@ describe('Test users', function () {
|
||||||
const client = { id: 'client', secret: server.client.secret }
|
const client = { id: 'client', secret: server.client.secret }
|
||||||
const res = await login(server.url, client, server.user, 400)
|
const res = await login(server.url, client, server.user, 400)
|
||||||
|
|
||||||
expect(res.body.error).to.equal('invalid_client')
|
expect(res.body.error)
|
||||||
|
.to
|
||||||
|
.equal('invalid_client')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not login with an invalid client secret', async function () {
|
it('Should not login with an invalid client secret', async function () {
|
||||||
const client = { id: server.client.id, secret: 'coucou' }
|
const client = { id: server.client.id, secret: 'coucou' }
|
||||||
const res = await login(server.url, client, server.user, 400)
|
const res = await login(server.url, client, server.user, 400)
|
||||||
|
|
||||||
expect(res.body.error).to.equal('invalid_client')
|
expect(res.body.error)
|
||||||
|
.to
|
||||||
|
.equal('invalid_client')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not login with an invalid username', async function () {
|
it('Should not login with an invalid username', async function () {
|
||||||
const user = { username: 'captain crochet', password: server.user.password }
|
const user = { username: 'captain crochet', password: server.user.password }
|
||||||
const res = await login(server.url, server.client, user, 400)
|
const res = await login(server.url, server.client, user, 400)
|
||||||
|
|
||||||
expect(res.body.error).to.equal('invalid_grant')
|
expect(res.body.error)
|
||||||
|
.to
|
||||||
|
.equal('invalid_grant')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not login with an invalid password', async function () {
|
it('Should not login with an invalid password', async function () {
|
||||||
const user = { username: server.user.username, password: 'mew_three' }
|
const user = { username: server.user.username, password: 'mew_three' }
|
||||||
const res = await login(server.url, server.client, user, 400)
|
const res = await login(server.url, server.client, user, 400)
|
||||||
|
|
||||||
expect(res.body.error).to.equal('invalid_grant')
|
expect(res.body.error)
|
||||||
|
.to
|
||||||
|
.equal('invalid_grant')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to upload a video', async function () {
|
it('Should not be able to upload a video', async function () {
|
||||||
|
@ -88,15 +94,12 @@ describe('Test users', function () {
|
||||||
await uploadVideo(server.url, accessToken, videoAttributes, 401)
|
await uploadVideo(server.url, accessToken, videoAttributes, 401)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to make friends', async function () {
|
it('Should not be able to follow', async function () {
|
||||||
accessToken = 'my_super_token'
|
accessToken = 'my_super_token'
|
||||||
await makeFriends(server.url, accessToken, 401)
|
await follow(server.url, [ 'http://example.com' ], accessToken, 401)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to quit friends', async function () {
|
it('Should not be able to unfollow')
|
||||||
accessToken = 'my_super_token'
|
|
||||||
await quitFriends(server.url, accessToken, 401)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('Should be able to login', async function () {
|
it('Should be able to login', async function () {
|
||||||
const res = await login(server.url, server.client, server.user, 200)
|
const res = await login(server.url, server.client, server.user, 200)
|
||||||
|
@ -108,9 +111,11 @@ describe('Test users', function () {
|
||||||
const videoAttributes = {}
|
const videoAttributes = {}
|
||||||
await uploadVideo(server.url, accessToken, videoAttributes, 204)
|
await uploadVideo(server.url, accessToken, videoAttributes, 204)
|
||||||
const res = await getVideosList(server.url)
|
const res = await getVideosList(server.url)
|
||||||
const video = res.body.data[0]
|
const video = res.body.data[ 0 ]
|
||||||
|
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account)
|
||||||
|
.to
|
||||||
|
.equal('root')
|
||||||
videoId = video.id
|
videoId = video.id
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -124,8 +129,12 @@ describe('Test users', function () {
|
||||||
const res = await getUserVideoRating(server.url, accessToken, videoId)
|
const res = await getUserVideoRating(server.url, accessToken, videoId)
|
||||||
const rating = res.body
|
const rating = res.body
|
||||||
|
|
||||||
expect(rating.videoId).to.equal(videoId)
|
expect(rating.videoId)
|
||||||
expect(rating.rating).to.equal('like')
|
.to
|
||||||
|
.equal(videoId)
|
||||||
|
expect(rating.rating)
|
||||||
|
.to
|
||||||
|
.equal('like')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to remove the video with an incorrect token', async function () {
|
it('Should not be able to remove the video with an incorrect token', async function () {
|
||||||
|
@ -187,12 +196,23 @@ describe('Test users', function () {
|
||||||
const res = await getMyUserInformation(server.url, accessTokenUser)
|
const res = await getMyUserInformation(server.url, accessTokenUser)
|
||||||
const user = res.body
|
const user = res.body
|
||||||
|
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.false
|
expect(user.displayNSFW).to.be.false
|
||||||
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
|
expect(user.videoQuota)
|
||||||
expect(user.roleLabel).to.equal('User')
|
.to
|
||||||
expect(user.id).to.be.a('number')
|
.equal(2 * 1024 * 1024)
|
||||||
|
expect(user.roleLabel)
|
||||||
|
.to
|
||||||
|
.equal('User')
|
||||||
|
expect(user.id)
|
||||||
|
.to
|
||||||
|
.be
|
||||||
|
.a('number')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should be able to upload a video with this user', async function () {
|
it('Should be able to upload a video with this user', async function () {
|
||||||
|
@ -206,12 +226,19 @@ describe('Test users', function () {
|
||||||
|
|
||||||
it('Should be able to list my videos', async function () {
|
it('Should be able to list my videos', async function () {
|
||||||
const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
|
const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
|
||||||
expect(res.body.total).to.equal(1)
|
expect(res.body.total)
|
||||||
|
.to
|
||||||
|
.equal(1)
|
||||||
|
|
||||||
const videos = res.body.data
|
const videos = res.body.data
|
||||||
expect(videos).to.have.lengthOf(1)
|
expect(videos)
|
||||||
|
.to
|
||||||
|
.have
|
||||||
|
.lengthOf(1)
|
||||||
|
|
||||||
expect(videos[0].name).to.equal('super user video')
|
expect(videos[ 0 ].name)
|
||||||
|
.to
|
||||||
|
.equal('super user video')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should list all the users', async function () {
|
it('Should list all the users', async function () {
|
||||||
|
@ -220,18 +247,33 @@ describe('Test users', function () {
|
||||||
const total = result.total
|
const total = result.total
|
||||||
const users = result.data
|
const users = result.data
|
||||||
|
|
||||||
expect(total).to.equal(2)
|
expect(total)
|
||||||
expect(users).to.be.an('array')
|
.to
|
||||||
expect(users.length).to.equal(2)
|
.equal(2)
|
||||||
|
expect(users)
|
||||||
|
.to
|
||||||
|
.be
|
||||||
|
.an('array')
|
||||||
|
expect(users.length)
|
||||||
|
.to
|
||||||
|
.equal(2)
|
||||||
|
|
||||||
const user = users[0]
|
const user = users[ 0 ]
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.false
|
expect(user.displayNSFW).to.be.false
|
||||||
|
|
||||||
const rootUser = users[1]
|
const rootUser = users[ 1 ]
|
||||||
expect(rootUser.username).to.equal('root')
|
expect(rootUser.username)
|
||||||
expect(rootUser.email).to.equal('admin1@example.com')
|
.to
|
||||||
|
.equal('root')
|
||||||
|
expect(rootUser.email)
|
||||||
|
.to
|
||||||
|
.equal('admin1@example.com')
|
||||||
expect(rootUser.displayNSFW).to.be.false
|
expect(rootUser.displayNSFW).to.be.false
|
||||||
|
|
||||||
userId = user.id
|
userId = user.id
|
||||||
|
@ -244,13 +286,23 @@ describe('Test users', function () {
|
||||||
const total = result.total
|
const total = result.total
|
||||||
const users = result.data
|
const users = result.data
|
||||||
|
|
||||||
expect(total).to.equal(2)
|
expect(total)
|
||||||
expect(users.length).to.equal(1)
|
.to
|
||||||
|
.equal(2)
|
||||||
|
expect(users.length)
|
||||||
|
.to
|
||||||
|
.equal(1)
|
||||||
|
|
||||||
const user = users[0]
|
const user = users[ 0 ]
|
||||||
expect(user.username).to.equal('root')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('admin1@example.com')
|
.to
|
||||||
expect(user.roleLabel).to.equal('Administrator')
|
.equal('root')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('admin1@example.com')
|
||||||
|
expect(user.roleLabel)
|
||||||
|
.to
|
||||||
|
.equal('Administrator')
|
||||||
expect(user.displayNSFW).to.be.false
|
expect(user.displayNSFW).to.be.false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -260,12 +312,20 @@ describe('Test users', function () {
|
||||||
const total = result.total
|
const total = result.total
|
||||||
const users = result.data
|
const users = result.data
|
||||||
|
|
||||||
expect(total).to.equal(2)
|
expect(total)
|
||||||
expect(users.length).to.equal(1)
|
.to
|
||||||
|
.equal(2)
|
||||||
|
expect(users.length)
|
||||||
|
.to
|
||||||
|
.equal(1)
|
||||||
|
|
||||||
const user = users[0]
|
const user = users[ 0 ]
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.false
|
expect(user.displayNSFW).to.be.false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -275,12 +335,20 @@ describe('Test users', function () {
|
||||||
const total = result.total
|
const total = result.total
|
||||||
const users = result.data
|
const users = result.data
|
||||||
|
|
||||||
expect(total).to.equal(2)
|
expect(total)
|
||||||
expect(users.length).to.equal(1)
|
.to
|
||||||
|
.equal(2)
|
||||||
|
expect(users.length)
|
||||||
|
.to
|
||||||
|
.equal(1)
|
||||||
|
|
||||||
const user = users[0]
|
const user = users[ 0 ]
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.false
|
expect(user.displayNSFW).to.be.false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -290,16 +358,28 @@ describe('Test users', function () {
|
||||||
const total = result.total
|
const total = result.total
|
||||||
const users = result.data
|
const users = result.data
|
||||||
|
|
||||||
expect(total).to.equal(2)
|
expect(total)
|
||||||
expect(users.length).to.equal(2)
|
.to
|
||||||
|
.equal(2)
|
||||||
|
expect(users.length)
|
||||||
|
.to
|
||||||
|
.equal(2)
|
||||||
|
|
||||||
expect(users[0].username).to.equal('root')
|
expect(users[ 0 ].username)
|
||||||
expect(users[0].email).to.equal('admin1@example.com')
|
.to
|
||||||
expect(users[0].displayNSFW).to.be.false
|
.equal('root')
|
||||||
|
expect(users[ 0 ].email)
|
||||||
|
.to
|
||||||
|
.equal('admin1@example.com')
|
||||||
|
expect(users[ 0 ].displayNSFW).to.be.false
|
||||||
|
|
||||||
expect(users[1].username).to.equal('user_1')
|
expect(users[ 1 ].username)
|
||||||
expect(users[1].email).to.equal('user_1@example.com')
|
.to
|
||||||
expect(users[1].displayNSFW).to.be.false
|
.equal('user_1')
|
||||||
|
expect(users[ 1 ].email)
|
||||||
|
.to
|
||||||
|
.equal('user_1@example.com')
|
||||||
|
expect(users[ 1 ].displayNSFW).to.be.false
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should update my password', async function () {
|
it('Should update my password', async function () {
|
||||||
|
@ -315,11 +395,20 @@ describe('Test users', function () {
|
||||||
const res = await getMyUserInformation(server.url, accessTokenUser)
|
const res = await getMyUserInformation(server.url, accessTokenUser)
|
||||||
const user = res.body
|
const user = res.body
|
||||||
|
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('user_1@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('user_1@example.com')
|
||||||
expect(user.displayNSFW).to.be.ok
|
expect(user.displayNSFW).to.be.ok
|
||||||
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
|
expect(user.videoQuota)
|
||||||
expect(user.id).to.be.a('number')
|
.to
|
||||||
|
.equal(2 * 1024 * 1024)
|
||||||
|
expect(user.id)
|
||||||
|
.to
|
||||||
|
.be
|
||||||
|
.a('number')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should be able to change the email display attribute', async function () {
|
it('Should be able to change the email display attribute', async function () {
|
||||||
|
@ -328,11 +417,20 @@ describe('Test users', function () {
|
||||||
const res = await getMyUserInformation(server.url, accessTokenUser)
|
const res = await getMyUserInformation(server.url, accessTokenUser)
|
||||||
const user = res.body
|
const user = res.body
|
||||||
|
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('updated@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('updated@example.com')
|
||||||
expect(user.displayNSFW).to.be.ok
|
expect(user.displayNSFW).to.be.ok
|
||||||
expect(user.videoQuota).to.equal(2 * 1024 * 1024)
|
expect(user.videoQuota)
|
||||||
expect(user.id).to.be.a('number')
|
.to
|
||||||
|
.equal(2 * 1024 * 1024)
|
||||||
|
expect(user.id)
|
||||||
|
.to
|
||||||
|
.be
|
||||||
|
.a('number')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should be able to update another user', async function () {
|
it('Should be able to update another user', async function () {
|
||||||
|
@ -341,12 +439,23 @@ describe('Test users', function () {
|
||||||
const res = await getUserInformation(server.url, accessToken, userId)
|
const res = await getUserInformation(server.url, accessToken, userId)
|
||||||
const user = res.body
|
const user = res.body
|
||||||
|
|
||||||
expect(user.username).to.equal('user_1')
|
expect(user.username)
|
||||||
expect(user.email).to.equal('updated2@example.com')
|
.to
|
||||||
|
.equal('user_1')
|
||||||
|
expect(user.email)
|
||||||
|
.to
|
||||||
|
.equal('updated2@example.com')
|
||||||
expect(user.displayNSFW).to.be.ok
|
expect(user.displayNSFW).to.be.ok
|
||||||
expect(user.videoQuota).to.equal(42)
|
expect(user.videoQuota)
|
||||||
expect(user.roleLabel).to.equal('Moderator')
|
.to
|
||||||
expect(user.id).to.be.a('number')
|
.equal(42)
|
||||||
|
expect(user.roleLabel)
|
||||||
|
.to
|
||||||
|
.equal('Moderator')
|
||||||
|
expect(user.id)
|
||||||
|
.to
|
||||||
|
.be
|
||||||
|
.a('number')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not be able to delete a user by a moderator', async function () {
|
it('Should not be able to delete a user by a moderator', async function () {
|
||||||
|
@ -369,10 +478,14 @@ describe('Test users', function () {
|
||||||
it('Should not have videos of this user', async function () {
|
it('Should not have videos of this user', async function () {
|
||||||
const res = await getVideosList(server.url)
|
const res = await getVideosList(server.url)
|
||||||
|
|
||||||
expect(res.body.total).to.equal(1)
|
expect(res.body.total)
|
||||||
|
.to
|
||||||
|
.equal(1)
|
||||||
|
|
||||||
const video = res.body.data[0]
|
const video = res.body.data[ 0 ]
|
||||||
expect(video.author).to.equal('root')
|
expect(video.account)
|
||||||
|
.to
|
||||||
|
.equal('root')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should register a new user', async function () {
|
it('Should register a new user', async function () {
|
||||||
|
@ -392,14 +505,16 @@ describe('Test users', function () {
|
||||||
const res = await getMyUserInformation(server.url, accessToken)
|
const res = await getMyUserInformation(server.url, accessToken)
|
||||||
const user = res.body
|
const user = res.body
|
||||||
|
|
||||||
expect(user.videoQuota).to.equal(5 * 1024 * 1024)
|
expect(user.videoQuota)
|
||||||
|
.to
|
||||||
|
.equal(5 * 1024 * 1024)
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
killallServers([ server ])
|
killallServers([ server ])
|
||||||
|
|
||||||
// Keep the logs if the test failed
|
// Keep the logs if the test failed
|
||||||
if (this['ok']) {
|
if (this[ 'ok' ]) {
|
||||||
await flushTests()
|
await flushTests()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
/* tslint:disable:no-unused-expression */
|
/* tslint:disable:no-unused-expression */
|
||||||
|
|
||||||
import 'mocha'
|
|
||||||
import * as chai from 'chai'
|
import * as chai from 'chai'
|
||||||
const expect = chai.expect
|
import 'mocha'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ServerInfo,
|
|
||||||
flushAndRunMultipleServers,
|
flushAndRunMultipleServers,
|
||||||
uploadVideo,
|
flushTests,
|
||||||
makeFriends,
|
|
||||||
getVideosList,
|
|
||||||
wait,
|
|
||||||
setAccessTokensToServers,
|
|
||||||
getVideoAbusesList,
|
getVideoAbusesList,
|
||||||
reportVideoAbuse,
|
getVideosList,
|
||||||
killallServers,
|
killallServers,
|
||||||
flushTests
|
reportVideoAbuse,
|
||||||
|
ServerInfo,
|
||||||
|
setAccessTokensToServers,
|
||||||
|
uploadVideo,
|
||||||
|
wait
|
||||||
} from '../utils'
|
} from '../utils'
|
||||||
|
import { doubleFollow } from '../utils/follows'
|
||||||
|
|
||||||
|
const expect = chai.expect
|
||||||
|
|
||||||
describe('Test video abuses', function () {
|
describe('Test video abuses', function () {
|
||||||
let servers: ServerInfo[] = []
|
let servers: ServerInfo[] = []
|
||||||
|
@ -30,32 +30,32 @@ describe('Test video abuses', function () {
|
||||||
// Get the access tokens
|
// Get the access tokens
|
||||||
await setAccessTokensToServers(servers)
|
await setAccessTokensToServers(servers)
|
||||||
|
|
||||||
// Pod 1 makes friend with pod 2
|
// Server 1 and server 2 follow each other
|
||||||
await makeFriends(servers[0].url, servers[0].accessToken)
|
await doubleFollow(servers[0], servers[1])
|
||||||
|
|
||||||
// Upload some videos on each pods
|
// Upload some videos on each servers
|
||||||
const video1Attributes = {
|
const video1Attributes = {
|
||||||
name: 'my super name for pod 1',
|
name: 'my super name for server 1',
|
||||||
description: 'my super description for pod 1'
|
description: 'my super description for server 1'
|
||||||
}
|
}
|
||||||
await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
|
await uploadVideo(servers[0].url, servers[0].accessToken, video1Attributes)
|
||||||
|
|
||||||
const video2Attributes = {
|
const video2Attributes = {
|
||||||
name: 'my super name for pod 2',
|
name: 'my super name for server 2',
|
||||||
description: 'my super description for pod 2'
|
description: 'my super description for server 2'
|
||||||
}
|
}
|
||||||
await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
|
await uploadVideo(servers[1].url, servers[1].accessToken, video2Attributes)
|
||||||
|
|
||||||
// Wait videos propagation
|
// Wait videos propagation
|
||||||
await wait(22000)
|
await wait(25000)
|
||||||
|
|
||||||
const res = await getVideosList(servers[0].url)
|
const res = await getVideosList(servers[0].url)
|
||||||
const videos = res.body.data
|
const videos = res.body.data
|
||||||
|
|
||||||
expect(videos.length).to.equal(2)
|
expect(videos.length).to.equal(2)
|
||||||
|
|
||||||
servers[0].video = videos.find(video => video.name === 'my super name for pod 1')
|
servers[0].video = videos.find(video => video.name === 'my super name for server 1')
|
||||||
servers[1].video = videos.find(video => video.name === 'my super name for pod 2')
|
servers[1].video = videos.find(video => video.name === 'my super name for server 2')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not have video abuses', async function () {
|
it('Should not have video abuses', async function () {
|
||||||
|
@ -72,11 +72,11 @@ describe('Test video abuses', function () {
|
||||||
const reason = 'my super bad reason'
|
const reason = 'my super bad reason'
|
||||||
await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
|
await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason)
|
||||||
|
|
||||||
// We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2
|
// We wait requests propagation, even if the server 1 is not supposed to make a request to server 2
|
||||||
await wait(11000)
|
await wait(11000)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have 1 video abuses on pod 1 and 0 on pod 2', async function () {
|
it('Should have 1 video abuses on server 1 and 0 on server 2', async function () {
|
||||||
const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
|
const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
|
||||||
|
|
||||||
expect(res1.body.total).to.equal(1)
|
expect(res1.body.total).to.equal(1)
|
||||||
|
@ -86,7 +86,7 @@ describe('Test video abuses', function () {
|
||||||
const abuse = res1.body.data[0]
|
const abuse = res1.body.data[0]
|
||||||
expect(abuse.reason).to.equal('my super bad reason')
|
expect(abuse.reason).to.equal('my super bad reason')
|
||||||
expect(abuse.reporterUsername).to.equal('root')
|
expect(abuse.reporterUsername).to.equal('root')
|
||||||
expect(abuse.reporterPodHost).to.equal('localhost:9001')
|
expect(abuse.reporterServerHost).to.equal('localhost:9001')
|
||||||
expect(abuse.videoId).to.equal(servers[0].video.id)
|
expect(abuse.videoId).to.equal(servers[0].video.id)
|
||||||
|
|
||||||
const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
|
const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
|
||||||
|
@ -96,16 +96,16 @@ describe('Test video abuses', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should report abuse on a remote video', async function () {
|
it('Should report abuse on a remote video', async function () {
|
||||||
this.timeout(15000)
|
this.timeout(25000)
|
||||||
|
|
||||||
const reason = 'my super bad reason 2'
|
const reason = 'my super bad reason 2'
|
||||||
await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
|
await reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason)
|
||||||
|
|
||||||
// We wait requests propagation
|
// We wait requests propagation
|
||||||
await wait(11000)
|
await wait(15000)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should have 2 video abuse on pod 1 and 1 on pod 2', async function () {
|
it('Should have 2 video abuse on server 1 and 1 on server 2', async function () {
|
||||||
const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
|
const res1 = await getVideoAbusesList(servers[0].url, servers[0].accessToken)
|
||||||
expect(res1.body.total).to.equal(2)
|
expect(res1.body.total).to.equal(2)
|
||||||
expect(res1.body.data).to.be.an('array')
|
expect(res1.body.data).to.be.an('array')
|
||||||
|
@ -114,13 +114,13 @@ describe('Test video abuses', function () {
|
||||||
const abuse1 = res1.body.data[0]
|
const abuse1 = res1.body.data[0]
|
||||||
expect(abuse1.reason).to.equal('my super bad reason')
|
expect(abuse1.reason).to.equal('my super bad reason')
|
||||||
expect(abuse1.reporterUsername).to.equal('root')
|
expect(abuse1.reporterUsername).to.equal('root')
|
||||||
expect(abuse1.reporterPodHost).to.equal('localhost:9001')
|
expect(abuse1.reporterServerHost).to.equal('localhost:9001')
|
||||||
expect(abuse1.videoId).to.equal(servers[0].video.id)
|
expect(abuse1.videoId).to.equal(servers[0].video.id)
|
||||||
|
|
||||||
const abuse2 = res1.body.data[1]
|
const abuse2 = res1.body.data[1]
|
||||||
expect(abuse2.reason).to.equal('my super bad reason 2')
|
expect(abuse2.reason).to.equal('my super bad reason 2')
|
||||||
expect(abuse2.reporterUsername).to.equal('root')
|
expect(abuse2.reporterUsername).to.equal('root')
|
||||||
expect(abuse2.reporterPodHost).to.equal('localhost:9001')
|
expect(abuse2.reporterServerHost).to.equal('localhost:9001')
|
||||||
expect(abuse2.videoId).to.equal(servers[1].video.id)
|
expect(abuse2.videoId).to.equal(servers[1].video.id)
|
||||||
|
|
||||||
const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
|
const res2 = await getVideoAbusesList(servers[1].url, servers[1].accessToken)
|
||||||
|
@ -131,7 +131,7 @@ describe('Test video abuses', function () {
|
||||||
const abuse3 = res2.body.data[0]
|
const abuse3 = res2.body.data[0]
|
||||||
expect(abuse3.reason).to.equal('my super bad reason 2')
|
expect(abuse3.reason).to.equal('my super bad reason 2')
|
||||||
expect(abuse3.reporterUsername).to.equal('root')
|
expect(abuse3.reporterUsername).to.equal('root')
|
||||||
expect(abuse3.reporterPodHost).to.equal('localhost:9001')
|
expect(abuse3.reporterServerHost).to.equal('localhost:9001')
|
||||||
})
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import * as request from 'supertest'
|
import * as request from 'supertest'
|
||||||
|
|
||||||
import { wait } from './miscs'
|
import { wait } from './miscs'
|
||||||
|
import { ServerInfo } from './servers'
|
||||||
|
|
||||||
function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
|
function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
|
||||||
const path = '/api/v1/servers/followers'
|
const path = '/api/v1/server/followers'
|
||||||
|
|
||||||
return request(url)
|
return request(url)
|
||||||
.get(path)
|
.get(path)
|
||||||
|
@ -16,7 +16,7 @@ function getFollowersListPaginationAndSort (url: string, start: number, count: n
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
|
function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
|
||||||
const path = '/api/v1/servers/following'
|
const path = '/api/v1/server/following'
|
||||||
|
|
||||||
return request(url)
|
return request(url)
|
||||||
.get(path)
|
.get(path)
|
||||||
|
@ -29,25 +29,36 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n
|
||||||
}
|
}
|
||||||
|
|
||||||
async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
|
async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
|
||||||
const path = '/api/v1/servers/follow'
|
const path = '/api/v1/server/follow'
|
||||||
|
|
||||||
|
const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
|
||||||
const res = await request(follower)
|
const res = await request(follower)
|
||||||
.post(path)
|
.post(path)
|
||||||
.set('Accept', 'application/json')
|
.set('Accept', 'application/json')
|
||||||
.set('Authorization', 'Bearer ' + accessToken)
|
.set('Authorization', 'Bearer ' + accessToken)
|
||||||
.send({ 'hosts': following })
|
.send({ 'hosts': followingHosts })
|
||||||
.expect(expectedStatus)
|
.expect(expectedStatus)
|
||||||
|
|
||||||
// Wait request propagation
|
// Wait request propagation
|
||||||
await wait(1000)
|
await wait(20000)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
|
||||||
|
await Promise.all([
|
||||||
|
follow(server1.url, [ server2.url ], server1.accessToken),
|
||||||
|
follow(server2.url, [ server1.url ], server2.accessToken)
|
||||||
|
])
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getFollowersListPaginationAndSort,
|
getFollowersListPaginationAndSort,
|
||||||
getFollowingListPaginationAndSort,
|
getFollowingListPaginationAndSort,
|
||||||
follow
|
follow,
|
||||||
|
doubleFollow
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ interface ServerInfo {
|
||||||
id: number
|
id: number
|
||||||
uuid: string
|
uuid: string
|
||||||
name: string
|
name: string
|
||||||
author: string
|
account: string
|
||||||
}
|
}
|
||||||
|
|
||||||
remoteVideo?: {
|
remoteVideo?: {
|
||||||
|
|
|
@ -11,10 +11,10 @@ export type ActivityType = 'Create' | 'Add' | 'Update' | 'Flag' | 'Delete' | 'Fo
|
||||||
export interface BaseActivity {
|
export interface BaseActivity {
|
||||||
'@context'?: any[]
|
'@context'?: any[]
|
||||||
id: string
|
id: string
|
||||||
to: string[]
|
to?: string[]
|
||||||
actor: string
|
actor: string
|
||||||
type: ActivityType
|
type: ActivityType
|
||||||
signature: ActivityPubSignature
|
signature?: ActivityPubSignature
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActivityCreate extends BaseActivity {
|
export interface ActivityCreate extends BaseActivity {
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
export type JobState = 'pending' | 'processing' | 'error' | 'success'
|
export type JobState = 'pending' | 'processing' | 'error' | 'success'
|
||||||
export type JobCategory = 'transcoding' | 'http-request'
|
export type JobCategory = 'transcoding' | 'activitypub-http'
|
||||||
|
|
14
yarn.lock
14
yarn.lock
|
@ -107,7 +107,11 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/express" "*"
|
"@types/express" "*"
|
||||||
|
|
||||||
"@types/node@*", "@types/node@^8.0.3":
|
"@types/node@*":
|
||||||
|
version "8.0.53"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.53.tgz#396b35af826fa66aad472c8cb7b8d5e277f4e6d8"
|
||||||
|
|
||||||
|
"@types/node@^8.0.3":
|
||||||
version "8.0.47"
|
version "8.0.47"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.47.tgz#968e596f91acd59069054558a00708c445ca30c2"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.47.tgz#968e596f91acd59069054558a00708c445ca30c2"
|
||||||
|
|
||||||
|
@ -2717,8 +2721,8 @@ moment-timezone@^0.5.4:
|
||||||
moment ">= 2.9.0"
|
moment ">= 2.9.0"
|
||||||
|
|
||||||
"moment@>= 2.9.0", moment@^2.13.0:
|
"moment@>= 2.9.0", moment@^2.13.0:
|
||||||
version "2.19.1"
|
version "2.19.2"
|
||||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.19.1.tgz#56da1a2d1cbf01d38b7e1afc31c10bcfa1929167"
|
resolved "https://registry.yarnpkg.com/moment/-/moment-2.19.2.tgz#8a7f774c95a64550b4c7ebd496683908f9419dbe"
|
||||||
|
|
||||||
morgan@^1.5.3:
|
morgan@^1.5.3:
|
||||||
version "1.9.0"
|
version "1.9.0"
|
||||||
|
@ -3647,8 +3651,8 @@ send@0.16.1:
|
||||||
statuses "~1.3.1"
|
statuses "~1.3.1"
|
||||||
|
|
||||||
sequelize@^4.7.5:
|
sequelize@^4.7.5:
|
||||||
version "4.22.5"
|
version "4.22.7"
|
||||||
resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-4.22.5.tgz#5771f8dc2173c61366d77b9fb89aeb34b0522435"
|
resolved "https://registry.yarnpkg.com/sequelize/-/sequelize-4.22.7.tgz#9425ad640f9813455cdc49cbeaf54aece141d76e"
|
||||||
dependencies:
|
dependencies:
|
||||||
bluebird "^3.4.6"
|
bluebird "^3.4.6"
|
||||||
cls-bluebird "^2.0.1"
|
cls-bluebird "^2.0.1"
|
||||||
|
|
Loading…
Reference in New Issue