From 98ec8b8e73a918d5680e6f13aaef56ca8756c2a8 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Nov 2017 13:16:23 +0100 Subject: [PATCH] Fix lint --- .travis.yml | 2 +- scripts/travis.sh | 4 ++-- scripts/update-host.ts | 2 +- server.ts | 6 +++++- server/controllers/activitypub/client.ts | 4 ++-- server/controllers/activitypub/outbox.ts | 7 ++++--- server/lib/activitypub/send/send-delete.ts | 2 +- server/middlewares/validators/video-channels.ts | 2 +- server/middlewares/validators/videos.ts | 2 +- server/models/video/video-channel-share-interface.ts | 5 ++--- server/models/video/video-share-interface.ts | 5 ++--- server/tests/client.ts | 11 +++++++---- server/tests/index.ts | 1 + server/tests/utils/index.ts | 1 + 14 files changed, 31 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index bb7e2c130..1ca6ea886 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,7 @@ before_script: matrix: include: - - env: TEST_SUITE=client + - env: TEST_SUITE=misc - env: TEST_SUITE=api-fast - env: TEST_SUITE=api-slow - env: TEST_SUITE=cli diff --git a/scripts/travis.sh b/scripts/travis.sh index e0a59806a..f24aac885 100755 --- a/scripts/travis.sh +++ b/scripts/travis.sh @@ -5,9 +5,9 @@ if [ $# -eq 0 ]; then exit -1 fi -if [ "$1" = "client" ]; then +if [ "$1" = "misc" ]; then npm run build - mocha --exit --require ts-node/register --bail server/tests/client.ts + mocha --exit --require ts-node/register --bail server/tests/client.ts server/tests/activitypub.ts elif [ "$1" = "api" ]; then npm run build:server mocha --exit --require ts-node/register --bail server/tests/api/index.ts diff --git a/scripts/update-host.ts b/scripts/update-host.ts index 4410e1ff7..759443623 100755 --- a/scripts/update-host.ts +++ b/scripts/update-host.ts @@ -6,7 +6,7 @@ db.init(true) return getServerAccount() }) .then(serverAccount => { - return db.AccountFollow.listAcceptedFollowingUrlsForApi([ serverAccount.id ]) + return db.AccountFollow.listAcceptedFollowingUrlsForApi([ serverAccount.id ], undefined) }) .then(res => { return res.total > 0 diff --git a/server.ts b/server.ts index 3221c1790..a723dd32b 100644 --- a/server.ts +++ b/server.ts @@ -129,7 +129,11 @@ app.use('/', staticRouter) // Always serve index client page (the client is a single page application, let it handle routing) app.use('/*', function (req, res) { - res.sendFile(path.join(__dirname, '../client/dist/index.html')) + if (req.accepts('html')) { + return res.sendFile(path.join(__dirname, '../client/dist/index.html')) + } + + return res.status(404).end() }) // ----------- Errors ----------- diff --git a/server/controllers/activitypub/client.ts b/server/controllers/activitypub/client.ts index 62cde1fc7..a478acd14 100644 --- a/server/controllers/activitypub/client.ts +++ b/server/controllers/activitypub/client.ts @@ -73,7 +73,7 @@ async function accountFollowersController (req: express.Request, res: express.Re const page = req.query.page || 1 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) - const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], start, count) + const result = await db.AccountFollow.listAcceptedFollowerUrlsForApi([ account.id ], undefined, start, count) const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) return res.json(activityPubResult) @@ -85,7 +85,7 @@ async function accountFollowingController (req: express.Request, res: express.Re const page = req.query.page || 1 const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE) - const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], start, count) + const result = await db.AccountFollow.listAcceptedFollowingUrlsForApi([ account.id ], undefined, start, count) const activityPubResult = activityPubCollectionPagination(CONFIG.WEBSERVER.URL + req.url, page, result) return res.json(activityPubResult) diff --git a/server/controllers/activitypub/outbox.ts b/server/controllers/activitypub/outbox.ts index e2c4e9b1e..5a2d43f3d 100644 --- a/server/controllers/activitypub/outbox.ts +++ b/server/controllers/activitypub/outbox.ts @@ -38,15 +38,16 @@ async function outboxController (req: express.Request, res: express.Response, ne const videoObject = video.toActivityPubObject() // This is a shared video + const videoChannel = video.VideoChannel if (video.VideoShares !== undefined && video.VideoShares.length !== 0) { - const addActivity = await addActivityData(video.url, video.VideoChannel.Account, video, video.VideoChannel.url, videoObject) + const addActivity = await addActivityData(video.url, videoChannel.Account, video, videoChannel.url, videoObject, undefined) const url = getAnnounceActivityPubUrl(video.url, account) - const announceActivity = await announceActivityData(url, account, addActivity) + const announceActivity = await announceActivityData(url, account, addActivity, undefined) activities.push(announceActivity) } else { - const addActivity = await addActivityData(video.url, account, video, video.VideoChannel.url, videoObject) + const addActivity = await addActivityData(video.url, account, video, videoChannel.url, videoObject, undefined) activities.push(addActivity) } diff --git a/server/lib/activitypub/send/send-delete.ts b/server/lib/activitypub/send/send-delete.ts index c49cda04f..8193790b3 100644 --- a/server/lib/activitypub/send/send-delete.ts +++ b/server/lib/activitypub/send/send-delete.ts @@ -27,7 +27,7 @@ async function sendDeleteVideo (video: VideoInstance, t: Transaction) { } async function sendDeleteAccount (account: AccountInstance, t: Transaction) { - const data = await deleteActivityData(account.url, account) + const data = deleteActivityData(account.url, account) return broadcastToFollowers(data, account, [ account ], t) } diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts index 4683c91e1..3d31a7e52 100644 --- a/server/middlewares/validators/video-channels.ts +++ b/server/middlewares/validators/video-channels.ts @@ -109,7 +109,7 @@ const videoChannelsShareValidator = [ if (areValidationErrors(req, res)) return if (!await isVideoChannelExist(req.params.id, res)) return - const share = await db.VideoChannelShare.load(res.locals.video.id, req.params.accountId) + const share = await db.VideoChannelShare.load(res.locals.video.id, req.params.accountId, undefined) if (!share) { return res.status(404) .end() diff --git a/server/middlewares/validators/videos.ts b/server/middlewares/validators/videos.ts index 52b4475ce..f21680aa0 100644 --- a/server/middlewares/validators/videos.ts +++ b/server/middlewares/validators/videos.ts @@ -222,7 +222,7 @@ const videosShareValidator = [ if (areValidationErrors(req, res)) return if (!await isVideoExist(req.params.id, res)) return - const share = await db.VideoShare.load(req.params.accountId, res.locals.video.id) + const share = await db.VideoShare.load(req.params.accountId, res.locals.video.id, undefined) if (!share) { return res.status(404) .end() diff --git a/server/models/video/video-channel-share-interface.ts b/server/models/video/video-channel-share-interface.ts index 0482e8297..2fff41a1b 100644 --- a/server/models/video/video-channel-share-interface.ts +++ b/server/models/video/video-channel-share-interface.ts @@ -1,12 +1,11 @@ import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' -import { Transaction } from 'sequelize' import { AccountInstance } from '../account/account-interface' import { VideoChannelInstance } from './video-channel-interface' export namespace VideoChannelShareMethods { - export type LoadAccountsByShare = (videoChannelId: number, t: Transaction) => Bluebird - export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird + export type LoadAccountsByShare = (videoChannelId: number, t: Sequelize.Transaction) => Bluebird + export type Load = (accountId: number, videoId: number, t: Sequelize.Transaction) => Bluebird } export interface VideoChannelShareClass { diff --git a/server/models/video/video-share-interface.ts b/server/models/video/video-share-interface.ts index 8ad10e095..3946303f1 100644 --- a/server/models/video/video-share-interface.ts +++ b/server/models/video/video-share-interface.ts @@ -1,12 +1,11 @@ import * as Bluebird from 'bluebird' import * as Sequelize from 'sequelize' -import { Transaction } from 'sequelize' import { AccountInstance } from '../account/account-interface' import { VideoInstance } from './video-interface' export namespace VideoShareMethods { - export type LoadAccountsByShare = (videoId: number, t: Transaction) => Bluebird - export type Load = (accountId: number, videoId: number, t: Transaction) => Bluebird + export type LoadAccountsByShare = (videoId: number, t: Sequelize.Transaction) => Bluebird + export type Load = (accountId: number, videoId: number, t: Sequelize.Transaction) => Bluebird } export interface VideoShareClass { diff --git a/server/tests/client.ts b/server/tests/client.ts index 0d70e3451..8c4334c53 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts @@ -41,8 +41,9 @@ describe('Test a client controllers', function () { it('Should have valid Open Graph tags on the watch page with video id', async function () { const res = await request(server.url) - .get('/videos/watch/' + server.video.id) - .expect(200) + .get('/videos/watch/' + server.video.id) + .set('Accept', 'text/html') + .expect(200) expect(res.text).to.contain('') expect(res.text).to.contain('') @@ -50,8 +51,9 @@ describe('Test a client controllers', function () { it('Should have valid Open Graph tags on the watch page with video uuid', async function () { const res = await request(server.url) - .get('/videos/watch/' + server.video.uuid) - .expect(200) + .get('/videos/watch/' + server.video.uuid) + .set('Accept', 'text/html') + .expect(200) expect(res.text).to.contain('') expect(res.text).to.contain('') @@ -61,6 +63,7 @@ describe('Test a client controllers', function () { const path = '/videos/watch/' + server.video.uuid const res = await request(server.url) .get(path) + .set('Accept', 'text/html') .expect(200) const expectedLink = '