Merge branch 'develop' of framagit.org:chocobozzz/PeerTube into develop

pull/525/head
Gérald Niel 2018-04-19 07:54:51 +02:00
commit 0030284b0d
14 changed files with 164 additions and 96 deletions

View File

@ -14,6 +14,8 @@
.comment { .comment {
flex-grow: 1; flex-grow: 1;
// Fix word-wrap with flex
min-width: 1px;
.highlighted-comment { .highlighted-comment {
display: inline-block; display: inline-block;
@ -44,8 +46,8 @@
} }
.comment-html { .comment-html {
word-wrap: initial;
word-break: normal; word-break: normal;
word-wrap: break-word;
text-align: justify; text-align: justify;
/deep/ a { /deep/ a {
@ -76,3 +78,26 @@
} }
} }
} }
// Decrease the space of child comments on small screens
@media screen and (max-width: 1600px) {
.children {
margin-left: -20px;
}
}
@media screen and (max-width: 1200px) {
.children {
margin-left: -30px;
}
}
@media screen and (max-width: 600px) {
.children {
margin-left: -40px;
}
.root-comment {
img { margin-right: 10px; }
}
}

View File

@ -19,8 +19,8 @@
font-size: 13px; font-size: 13px;
} }
.comment-html { @media screen and (max-width: 600px) {
word-wrap: normal; .view-replies {
word-break: normal; margin-left: 46px;
text-align: justify; }
} }

View File

@ -335,7 +335,7 @@
.video-actions-rates { .video-actions-rates {
margin-top: 20px; margin-top: 20px;
align-items: left; align-items: start;
.video-info-likes-dislikes-bar { .video-info-likes-dislikes-bar {
margin-top: 10px; margin-top: 10px;

View File

@ -27,11 +27,12 @@ function getVideojsOptions (options: {
const videojsOptions = { const videojsOptions = {
controls: true, controls: true,
poster: options.poster, poster: options.poster,
autoplay: options.autoplay, autoplay: false,
inactivityTimeout: options.inactivityTimeout, inactivityTimeout: options.inactivityTimeout,
playbackRates: [ 0.5, 1, 1.5, 2 ], playbackRates: [ 0.5, 1, 1.5, 2 ],
plugins: { plugins: {
peertube: { peertube: {
autoplay: options.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
videoFiles: options.videoFiles, videoFiles: options.videoFiles,
playerElement: options.playerElement, playerElement: options.playerElement,
videoViewUrl: options.videoViewUrl, videoViewUrl: options.videoViewUrl,

View File

@ -68,9 +68,7 @@ class PeerTubePlugin extends Plugin {
constructor (player: videojs.Player, options: PeertubePluginOptions) { constructor (player: videojs.Player, options: PeertubePluginOptions) {
super(player, options) super(player, options)
// Fix canplay event on google chrome by disabling default videojs autoplay this.autoplay = options.autoplay
this.autoplay = this.player.options_.autoplay
this.player.options_.autoplay = false
this.startTime = options.startTime this.startTime = options.startTime
this.videoFiles = options.videoFiles this.videoFiles = options.videoFiles
@ -190,12 +188,7 @@ class PeerTubePlugin extends Plugin {
if (err) return this.fallbackToHttp(done) if (err) return this.fallbackToHttp(done)
if (!this.player.paused()) { if (!this.player.paused()) return this.tryToPlay(done)
const playPromise = this.player.play()
if (playPromise !== undefined) return playPromise.then(done)
return done()
}
return done() return done()
}) })
@ -264,6 +257,25 @@ class PeerTubePlugin extends Plugin {
this.trigger('autoResolutionUpdate') this.trigger('autoResolutionUpdate')
} }
private tryToPlay (done?: Function) {
if (!done) done = function () { /* empty */ }
const playPromise = this.player.play()
if (playPromise !== undefined) {
return playPromise.then(done)
.catch(err => {
console.error(err)
this.player.pause()
this.player.posterImage.show()
this.player.removeClass('vjs-has-autoplay')
return done()
})
}
return done()
}
private seek (time: number) { private seek (time: number) {
this.player.currentTime(time) this.player.currentTime(time)
this.player.handleTechSeeked_() this.player.handleTechSeeked_()
@ -317,7 +329,10 @@ class PeerTubePlugin extends Plugin {
if (this.autoplay === true) { if (this.autoplay === true) {
this.player.posterImage.hide() this.player.posterImage.hide()
this.updateVideoFile(undefined, 0, () => this.seek(this.startTime)) this.updateVideoFile(undefined, 0, () => {
this.seek(this.startTime)
this.tryToPlay()
})
} else { } else {
// Proxy first play // Proxy first play
const oldPlay = this.player.play.bind(this.player) const oldPlay = this.player.play.bind(this.player)

View File

@ -22,6 +22,7 @@ type PeertubePluginOptions = {
videoViewUrl: string videoViewUrl: string
videoDuration: number videoDuration: number
startTime: number startTime: number
autoplay: boolean
} }
// videojs typings don't have some method we need // videojs typings don't have some method we need

View File

@ -215,7 +215,8 @@ async function startApplication () {
Redis.Instance.init() Redis.Instance.init()
// Make server listening // Make server listening
server.listen(port, hostname) server.listen(port, hostname, () => {
logger.info('Server listening on %s:%d', hostname, port) logger.info('Server listening on %s:%d', hostname, port)
logger.info('Web server: %s', CONFIG.WEBSERVER.URL) logger.info('Web server: %s', CONFIG.WEBSERVER.URL)
})
} }

View File

@ -1,20 +1,22 @@
import * as express from 'express' import * as express from 'express'
import { UserRight } from '../../../../shared/models/users' import { UserRight } from '../../../../shared/models/users'
import { sanitizeHost } from '../../../helpers/core-utils'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { getFormattedObjects, getServerActor } from '../../../helpers/utils' import { getFormattedObjects, getServerActor } from '../../../helpers/utils'
import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger' import { sequelizeTypescript } from '../../../initializers'
import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers' import { sendUndoFollow } from '../../../lib/activitypub/send'
import { getOrCreateActorAndServerAndModel } from '../../../lib/activitypub/actor'
import { sendFollow, sendUndoFollow } from '../../../lib/activitypub/send'
import { import {
asyncMiddleware, authenticate, ensureUserHasRight, paginationValidator, removeFollowingValidator, setBodyHostsPort, setDefaultSort, asyncMiddleware,
setDefaultPagination authenticate,
ensureUserHasRight,
paginationValidator,
removeFollowingValidator,
setBodyHostsPort,
setDefaultPagination,
setDefaultSort
} from '../../../middlewares' } from '../../../middlewares'
import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators' import { followersSortValidator, followingSortValidator, followValidator } from '../../../middlewares/validators'
import { ActorModel } from '../../../models/activitypub/actor'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { JobQueue } from '../../../lib/job-queue'
const serverFollowsRouter = express.Router() const serverFollowsRouter = express.Router()
serverFollowsRouter.get('/following', serverFollowsRouter.get('/following',
@ -30,7 +32,7 @@ serverFollowsRouter.post('/following',
ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW), ensureUserHasRight(UserRight.MANAGE_SERVER_FOLLOW),
followValidator, followValidator,
setBodyHostsPort, setBodyHostsPort,
asyncMiddleware(followRetry) asyncMiddleware(followInstance)
) )
serverFollowsRouter.delete('/following/:host', serverFollowsRouter.delete('/following/:host',
@ -70,67 +72,17 @@ async function listFollowers (req: express.Request, res: express.Response, next:
return res.json(getFormattedObjects(resultList.data, resultList.total)) return res.json(getFormattedObjects(resultList.data, resultList.total))
} }
async function followRetry (req: express.Request, res: express.Response, next: express.NextFunction) { async function followInstance (req: express.Request, res: express.Response, next: express.NextFunction) {
const hosts = req.body.hosts as string[] const hosts = req.body.hosts as string[]
const fromActor = await getServerActor()
const tasks: Promise<any>[] = []
const actorName = SERVER_ACTOR_NAME
for (const host of hosts) { for (const host of hosts) {
const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP) JobQueue.Instance.createJob({ type: 'activitypub-follow', payload: { host } })
.catch(err => logger.error('Cannot create follow job for %s.', host, err))
// We process each host in a specific transaction
// First, we add the follow request in the database
// Then we send the follow request to other actor
const p = loadActorUrlOrGetFromWebfinger(actorName, sanitizedHost)
.then(actorUrl => getOrCreateActorAndServerAndModel(actorUrl))
.then(targetActor => {
const options = {
arguments: [ fromActor, targetActor ],
errorMessage: 'Cannot follow with many retries.'
} }
return retryTransactionWrapper(follow, options)
})
.catch(err => logger.warn('Cannot follow server %s.', sanitizedHost, { err }))
tasks.push(p)
}
// Don't make the client wait the tasks
Promise.all(tasks)
.catch(err => logger.error('Error in follow.', { err }))
return res.status(204).end() return res.status(204).end()
} }
function follow (fromActor: ActorModel, targetActor: ActorModel) {
if (fromActor.id === targetActor.id) {
throw new Error('Follower is the same than target actor.')
}
return sequelizeTypescript.transaction(async t => {
const [ actorFollow ] = await ActorFollowModel.findOrCreate({
where: {
actorId: fromActor.id,
targetActorId: targetActor.id
},
defaults: {
state: 'pending',
actorId: fromActor.id,
targetActorId: targetActor.id
},
transaction: t
})
actorFollow.ActorFollowing = targetActor
actorFollow.ActorFollower = fromActor
// Send a notification to remote server
await sendFollow(actorFollow)
})
}
async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) { async function removeFollow (req: express.Request, res: express.Response, next: express.NextFunction) {
const follow: ActorFollowModel = res.locals.follow const follow: ActorFollowModel = res.locals.follow

View File

@ -65,6 +65,7 @@ const JOB_ATTEMPTS: { [ id in JobType ]: number } = {
'activitypub-http-broadcast': 5, 'activitypub-http-broadcast': 5,
'activitypub-http-unicast': 5, 'activitypub-http-unicast': 5,
'activitypub-http-fetcher': 5, 'activitypub-http-fetcher': 5,
'activitypub-follow': 5,
'video-file': 1, 'video-file': 1,
'email': 5 'email': 5
} }
@ -72,9 +73,11 @@ const JOB_CONCURRENCY: { [ id in JobType ]: number } = {
'activitypub-http-broadcast': 1, 'activitypub-http-broadcast': 1,
'activitypub-http-unicast': 5, 'activitypub-http-unicast': 5,
'activitypub-http-fetcher': 1, 'activitypub-http-fetcher': 1,
'activitypub-follow': 3,
'video-file': 1, 'video-file': 1,
'email': 5 'email': 5
} }
const BROADCAST_CONCURRENCY = 5 // How many requests in parallel we do in activitypub-http-broadcast job
// 2 days // 2 days
const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2 const JOB_COMPLETED_LIFETIME = 60000 * 60 * 24 * 2
@ -461,6 +464,7 @@ export {
LAST_MIGRATION_VERSION, LAST_MIGRATION_VERSION,
OAUTH_LIFETIME, OAUTH_LIFETIME,
OPENGRAPH_AND_OEMBED_COMMENT, OPENGRAPH_AND_OEMBED_COMMENT,
BROADCAST_CONCURRENCY,
PAGINATION_COUNT_DEFAULT, PAGINATION_COUNT_DEFAULT,
ACTOR_FOLLOW_SCORE, ACTOR_FOLLOW_SCORE,
PREVIEWS_SIZE, PREVIEWS_SIZE,

View File

@ -0,0 +1,68 @@
import * as kue from 'kue'
import { logger } from '../../../helpers/logger'
import { getServerActor } from '../../../helpers/utils'
import { REMOTE_SCHEME, sequelizeTypescript, SERVER_ACTOR_NAME } from '../../../initializers'
import { sendFollow } from '../../activitypub/send'
import { sanitizeHost } from '../../../helpers/core-utils'
import { loadActorUrlOrGetFromWebfinger } from '../../../helpers/webfinger'
import { getOrCreateActorAndServerAndModel } from '../../activitypub/actor'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { ActorModel } from '../../../models/activitypub/actor'
export type ActivitypubFollowPayload = {
host: string
}
async function processActivityPubFollow (job: kue.Job) {
const payload = job.data as ActivitypubFollowPayload
const host = payload.host
logger.info('Processing ActivityPub follow in job %d.', job.id)
const sanitizedHost = sanitizeHost(host, REMOTE_SCHEME.HTTP)
const actorUrl = await loadActorUrlOrGetFromWebfinger(SERVER_ACTOR_NAME, sanitizedHost)
const targetActor = await getOrCreateActorAndServerAndModel(actorUrl)
const fromActor = await getServerActor()
const options = {
arguments: [ fromActor, targetActor ],
errorMessage: 'Cannot follow with many retries.'
}
return retryTransactionWrapper(follow, options)
}
// ---------------------------------------------------------------------------
export {
processActivityPubFollow
}
// ---------------------------------------------------------------------------
function follow (fromActor: ActorModel, targetActor: ActorModel) {
if (fromActor.id === targetActor.id) {
throw new Error('Follower is the same than target actor.')
}
return sequelizeTypescript.transaction(async t => {
const [ actorFollow ] = await ActorFollowModel.findOrCreate({
where: {
actorId: fromActor.id,
targetActorId: targetActor.id
},
defaults: {
state: 'pending',
actorId: fromActor.id,
targetActorId: targetActor.id
},
transaction: t
})
actorFollow.ActorFollowing = targetActor
actorFollow.ActorFollower = fromActor
// Send a notification to remote server
await sendFollow(actorFollow)
})
}

View File

@ -1,8 +1,10 @@
import * as kue from 'kue' import * as kue from 'kue'
import * as Bluebird from 'bluebird'
import { logger } from '../../../helpers/logger' import { logger } from '../../../helpers/logger'
import { doRequest } from '../../../helpers/requests' import { doRequest } from '../../../helpers/requests'
import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils' import { buildSignedRequestOptions, computeBody } from './utils/activitypub-http-utils'
import { BROADCAST_CONCURRENCY } from '../../../initializers'
export type ActivitypubHttpBroadcastPayload = { export type ActivitypubHttpBroadcastPayload = {
uris: string[] uris: string[]
@ -28,16 +30,11 @@ async function processActivityPubHttpBroadcast (job: kue.Job) {
const badUrls: string[] = [] const badUrls: string[] = []
const goodUrls: string[] = [] const goodUrls: string[] = []
for (const uri of payload.uris) { await Bluebird.map(payload.uris, uri => {
options.uri = uri return doRequest(Object.assign({}, options, { uri }))
.then(() => goodUrls.push(uri))
try { .catch(() => badUrls.push(uri))
await doRequest(options) }, { concurrency: BROADCAST_CONCURRENCY })
goodUrls.push(uri)
} catch (err) {
badUrls.push(uri)
}
}
return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined) return ActorFollowModel.updateActorFollowsScore(goodUrls, badUrls, undefined)
} }

View File

@ -8,11 +8,13 @@ import { ActivitypubHttpFetcherPayload, processActivityPubHttpFetcher } from './
import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast' import { ActivitypubHttpUnicastPayload, processActivityPubHttpUnicast } from './handlers/activitypub-http-unicast'
import { EmailPayload, processEmail } from './handlers/email' import { EmailPayload, processEmail } from './handlers/email'
import { processVideoFile, VideoFilePayload } from './handlers/video-file' import { processVideoFile, VideoFilePayload } from './handlers/video-file'
import { ActivitypubFollowPayload, processActivityPubFollow } from './handlers/activitypub-follow'
type CreateJobArgument = type CreateJobArgument =
{ type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } | { type: 'activitypub-http-broadcast', payload: ActivitypubHttpBroadcastPayload } |
{ type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } | { type: 'activitypub-http-unicast', payload: ActivitypubHttpUnicastPayload } |
{ type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } | { type: 'activitypub-http-fetcher', payload: ActivitypubHttpFetcherPayload } |
{ type: 'activitypub-follow', payload: ActivitypubFollowPayload } |
{ type: 'video-file', payload: VideoFilePayload } | { type: 'video-file', payload: VideoFilePayload } |
{ type: 'email', payload: EmailPayload } { type: 'email', payload: EmailPayload }
@ -20,6 +22,7 @@ const handlers: { [ id in JobType ]: (job: kue.Job) => Promise<any>} = {
'activitypub-http-broadcast': processActivityPubHttpBroadcast, 'activitypub-http-broadcast': processActivityPubHttpBroadcast,
'activitypub-http-unicast': processActivityPubHttpUnicast, 'activitypub-http-unicast': processActivityPubHttpUnicast,
'activitypub-http-fetcher': processActivityPubHttpFetcher, 'activitypub-http-fetcher': processActivityPubHttpFetcher,
'activitypub-follow': processActivityPubFollow,
'video-file': processVideoFile, 'video-file': processVideoFile,
'email': processEmail 'email': processEmail
} }
@ -50,7 +53,7 @@ class JobQueue {
} }
}) })
this.jobQueue.setMaxListeners(15) this.jobQueue.setMaxListeners(20)
this.jobQueue.on('error', err => { this.jobQueue.on('error', err => {
logger.error('Error in job queue.', { err }) logger.error('Error in job queue.', { err })

View File

@ -88,7 +88,7 @@ function runServer (serverNumber: number, configOverride?: Object) {
// These actions are async so we need to be sure that they have both been done // These actions are async so we need to be sure that they have both been done
const serverRunString = { const serverRunString = {
'Server listening on port': false 'Server listening': false
} }
const key = 'Database peertube_test' + serverNumber + ' is ready' const key = 'Database peertube_test' + serverNumber + ' is ready'
serverRunString[key] = false serverRunString[key] = false

View File

@ -3,6 +3,7 @@ export type JobState = 'active' | 'complete' | 'failed' | 'inactive' | 'delayed'
export type JobType = 'activitypub-http-unicast' | export type JobType = 'activitypub-http-unicast' |
'activitypub-http-broadcast' | 'activitypub-http-broadcast' |
'activitypub-http-fetcher' | 'activitypub-http-fetcher' |
'activitypub-follow' |
'video-file' | 'video-file' |
'email' 'email'