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.ts | 5 ++++- 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 +++++++ yarn.lock | 4 ++-- 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/server.ts b/server.ts index 84535c7a5..0e963c3d3 100644 --- a/server.ts +++ b/server.ts @@ -76,7 +76,10 @@ app.use(morgan('combined', { stream: { write: logger.info } })) // For body requests -app.use(bodyParser.json({ limit: '500kb' })) +app.use(bodyParser.json({ + type: 'application/*+json', + limit: '500kb' +})) app.use(bodyParser.urlencoded({ extended: false })) // ----------- Tracker ----------- 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, diff --git a/yarn.lock b/yarn.lock index 497f5da1f..4e92fd336 100644 --- a/yarn.lock +++ b/yarn.lock @@ -471,9 +471,9 @@ bitcore-lib@^0.13.7: inherits "=2.0.1" lodash "=3.10.1" -"bitcore-message@github:comakery/bitcore-message#dist": +"bitcore-message@github:CoMakery/bitcore-message#dist": version "1.0.2" - resolved "https://codeload.github.com/comakery/bitcore-message/tar.gz/8799cc327029c3d34fc725f05b2cf981363f6ebf" + resolved "https://codeload.github.com/CoMakery/bitcore-message/tar.gz/8799cc327029c3d34fc725f05b2cf981363f6ebf" dependencies: bitcore-lib "^0.13.7" -- cgit v1.2.3