From 8519cc92341545468104f0704fff64a05c84bec0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 24 Apr 2019 17:19:00 +0200 Subject: Fix overview endpoint --- server/middlewares/cache.ts | 3 ++- server/models/video/video.ts | 9 +++++++-- server/tests/api/check-params/contact-form.ts | 2 +- server/tests/api/videos/video-playlists.ts | 11 ++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) (limited to 'server') diff --git a/server/middlewares/cache.ts b/server/middlewares/cache.ts index e83d8d569..091c82d92 100644 --- a/server/middlewares/cache.ts +++ b/server/middlewares/cache.ts @@ -7,6 +7,8 @@ import { logger } from '../helpers/logger' const lock = new AsyncLock({ timeout: 5000 }) function cacheRoute (lifetimeArg: string | number) { + const lifetime = parseDurationToMs(lifetimeArg) + return async function (req: express.Request, res: express.Response, next: express.NextFunction) { const redisKey = Redis.Instance.generateCachedRouteKey(req) @@ -24,7 +26,6 @@ function cacheRoute (lifetimeArg: string | number) { res.send = (body) => { if (res.statusCode >= 200 && res.statusCode < 400) { const contentType = res.get('content-type') - const lifetime = parseDurationToMs(lifetimeArg) Redis.Instance.setCachedRoute(req, body, lifetime, contentType, res.statusCode) .then(() => done()) diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 5fb529e8d..4e6f602aa 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -207,6 +207,8 @@ type AvailableForListIDsOptions = { followerActorId: number includeLocalVideos: boolean + withoutId?: boolean + filter?: VideoFilter categoryOneOf?: number[] nsfw?: boolean @@ -268,9 +270,11 @@ type AvailableForListIDsOptions = { return query }, [ ScopeNames.AVAILABLE_FOR_LIST_IDS ]: (options: AvailableForListIDsOptions) => { + const attributes = options.withoutId === true ? [] : [ 'id' ] + const query: FindOptions = { raw: true, - attributes: [ 'id' ], + attributes, where: { id: { [ Op.and ]: [ @@ -1523,7 +1527,8 @@ export class VideoModel extends Model { const scopeOptions: AvailableForListIDsOptions = { serverAccountId: serverActor.Account.id, followerActorId, - includeLocalVideos: true + includeLocalVideos: true, + withoutId: true // Don't break aggregation } const query: FindOptions = { diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index 55004020f..dbdd3a8a6 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -87,6 +87,6 @@ describe('Test contact form API validators', function () { after(async function () { MockSmtpServer.Instance.kill() - // await cleanupTests([ server ]) + await cleanupTests([ server ]) }) }) diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 928568299..e4d817ff8 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -5,23 +5,24 @@ import 'mocha' import { addVideoChannel, addVideoInPlaylist, - checkPlaylistFilesWereRemoved, cleanupTests, + checkPlaylistFilesWereRemoved, + cleanupTests, createUser, createVideoPlaylist, deleteVideoChannel, deleteVideoPlaylist, - doubleFollow, doVideosExistInMyPlaylist, + doubleFollow, + doVideosExistInMyPlaylist, flushAndRunMultipleServers, - flushTests, getAccountPlaylistsList, - getAccountPlaylistsListWithToken, getMyUserInformation, + getAccountPlaylistsListWithToken, + getMyUserInformation, getPlaylistVideos, getVideoChannelPlaylistsList, getVideoPlaylist, getVideoPlaylistPrivacies, getVideoPlaylistsList, getVideoPlaylistWithToken, - killallServers, removeUser, removeVideoFromPlaylist, reorderVideosPlaylist, -- cgit v1.2.3