diff options
author | Chocobozzz <me@florianbigard.com> | 2019-03-05 10:58:44 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-03-18 11:17:59 +0100 |
commit | df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa (patch) | |
tree | c4984e854f5dc18e5c27afd73b843bd52c143034 /server/models/video/video.ts | |
parent | 07b1a18aa678d260009a93e36606c5c5f585723d (diff) | |
download | PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.gz PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.tar.zst PeerTube-df0b219d36bf6852cdf2a7ad09ed4a41c6bccefa.zip |
Add playlist rest tests
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r-- | server/models/video/video.ts | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 7a102b058..a563f78ef 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -225,7 +225,7 @@ type AvailableForListIDsOptions = { | |||
225 | }, | 225 | }, |
226 | include: [ | 226 | include: [ |
227 | { | 227 | { |
228 | model: VideoChannelModel.scope(VideoChannelScopeNames.SUMMARY) | 228 | model: VideoChannelModel.scope({ method: [ VideoChannelScopeNames.SUMMARY, true ] }) |
229 | } | 229 | } |
230 | ] | 230 | ] |
231 | } | 231 | } |
@@ -1535,18 +1535,7 @@ export class VideoModel extends Model<VideoModel> { | |||
1535 | 1535 | ||
1536 | if (ids.length === 0) return { data: [], total: count } | 1536 | if (ids.length === 0) return { data: [], total: count } |
1537 | 1537 | ||
1538 | // FIXME: typings | 1538 | const secondQuery: IFindOptions<VideoModel> = { |
1539 | const apiScope: any[] = [ | ||
1540 | { | ||
1541 | method: [ ScopeNames.FOR_API, { ids, withFiles: options.withFiles } as ForAPIOptions ] | ||
1542 | } | ||
1543 | ] | ||
1544 | |||
1545 | if (options.user) { | ||
1546 | apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] }) | ||
1547 | } | ||
1548 | |||
1549 | const secondQuery = { | ||
1550 | offset: 0, | 1539 | offset: 0, |
1551 | limit: query.limit, | 1540 | limit: query.limit, |
1552 | attributes: query.attributes, | 1541 | attributes: query.attributes, |
@@ -1556,6 +1545,29 @@ export class VideoModel extends Model<VideoModel> { | |||
1556 | ) | 1545 | ) |
1557 | ] | 1546 | ] |
1558 | } | 1547 | } |
1548 | |||
1549 | // FIXME: typing | ||
1550 | const apiScope: any[] = [] | ||
1551 | |||
1552 | if (options.user) { | ||
1553 | apiScope.push({ method: [ ScopeNames.WITH_USER_HISTORY, options.user.id ] }) | ||
1554 | |||
1555 | // Even if the relation is n:m, we know that a user only have 0..1 video history | ||
1556 | // So we won't have multiple rows for the same video | ||
1557 | // A subquery adds some bugs in our query so disable it | ||
1558 | secondQuery.subQuery = false | ||
1559 | } | ||
1560 | |||
1561 | apiScope.push({ | ||
1562 | method: [ | ||
1563 | ScopeNames.FOR_API, { | ||
1564 | ids, withFiles: | ||
1565 | options.withFiles, | ||
1566 | videoPlaylistId: options.videoPlaylistId | ||
1567 | } as ForAPIOptions | ||
1568 | ] | ||
1569 | }) | ||
1570 | |||
1559 | const rows = await VideoModel.scope(apiScope).findAll(secondQuery) | 1571 | const rows = await VideoModel.scope(apiScope).findAll(secondQuery) |
1560 | 1572 | ||
1561 | return { | 1573 | return { |