From 165cdc75bf1942ed687f78094c2bd366839a7c99 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 29 Nov 2017 11:34:44 +0100 Subject: Fix well known and json parser with mastodon --- server/controllers/webfinger.ts | 1 + server/initializers/constants.ts | 7 ++++++- server/initializers/database.ts | 2 ++ server/middlewares/activitypub.ts | 4 +++- server/models/video/video.ts | 7 +++++++ 5 files changed, 19 insertions(+), 2 deletions(-) (limited to 'server') diff --git a/server/controllers/webfinger.ts b/server/controllers/webfinger.ts index 1cea513a1..78e5dee79 100644 --- a/server/controllers/webfinger.ts +++ b/server/controllers/webfinger.ts @@ -27,6 +27,7 @@ function webfingerController (req: express.Request, res: express.Response, next: links: [ { rel: 'self', + type: 'application/activity+json', href: account.url } ] diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 82373ba84..6d8aa7332 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -219,7 +219,11 @@ const VIDEO_MIMETYPE_EXT = { const SERVER_ACCOUNT_NAME = 'peertube' const ACTIVITY_PUB = { - ACCEPT_HEADER: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + ACCEPT_HEADERS: [ + 'application/activity+json, application/ld+json', + 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' + ], + ACCEPT_HEADER: '', PUBLIC: 'https://www.w3.org/ns/activitystreams#Public', COLLECTION_ITEMS_PER_PAGE: 10, FETCH_PAGE_LIMIT: 100, @@ -230,6 +234,7 @@ const ACTIVITY_PUB = { MAGNET: [ 'application/x-bittorrent;x-scheme-handler/magnet' ] } } +ACTIVITY_PUB.ACCEPT_HEADER = ACTIVITY_PUB.ACCEPT_HEADERS[0] // --------------------------------------------------------------------------- diff --git a/server/initializers/database.ts b/server/initializers/database.ts index 9b9a81e26..90dbba5b9 100644 --- a/server/initializers/database.ts +++ b/server/initializers/database.ts @@ -66,6 +66,8 @@ const sequelize = new Sequelize(dbname, username, password, { operatorsAliases: false, logging: (message: string, benchmark: number) => { + if (process.env.NODE_DB_LOG === 'false') return + let newMessage = message if (isTestInstance() === true && benchmark !== undefined) { newMessage += ' | ' + benchmark + 'ms' diff --git a/server/middlewares/activitypub.ts b/server/middlewares/activitypub.ts index 061b2dddc..34386e76d 100644 --- a/server/middlewares/activitypub.ts +++ b/server/middlewares/activitypub.ts @@ -37,10 +37,12 @@ async function checkSignature (req: Request, res: Response, next: NextFunction) function executeIfActivityPub (fun: RequestHandler | RequestHandler[]) { return (req: Request, res: Response, next: NextFunction) => { - if (req.header('Accept') !== ACTIVITY_PUB.ACCEPT_HEADER) { + if (ACTIVITY_PUB.ACCEPT_HEADERS.indexOf(req.header('Accept')) === -1) { return next() } + logger.debug('ActivityPub request for %s.', req.url) + if (Array.isArray(fun) === true) { return eachSeries(fun as RequestHandler[], (f, cb) => { f(req, res, cb) diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 3f416d04c..f3469c1de 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -616,6 +616,13 @@ toActivityPubObject = function (this: VideoInstance) { }) } + // Add video url too + url.push({ + type: 'Link', + mimeType: 'text/html', + url: CONFIG.WEBSERVER.URL + '/videos/watch/' + this.uuid + }) + const videoObject: VideoTorrentObject = { type: 'Video' as 'Video', id: this.url, -- cgit v1.2.3