X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo.ts;h=0e7505af5099052f835662902a4152ad973e8dc9;hb=14cbb9a65a1b2853c93df429fcc3df9004a5c940;hp=5e4b7d44c0b86f0162bbd02912a801258216276c;hpb=8319d6ae72d4da6de51bd3d4b5c68040fc8dc3b4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 5e4b7d44c..0e7505af5 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -125,6 +125,7 @@ import { VideoFile } from '@shared/models/videos/video-file.model' import { getHLSDirectory, getTorrentFileName, getTorrentFilePath, getVideoFilename, getVideoFilePath } from '@server/lib/video-paths' import { ModelCache } from '@server/models/model-cache' import { buildListQuery, BuildVideosQueryOptions, wrapForAPIResults } from './video-query-builder' +import { buildNSFWFilter } from '@server/helpers/express-utils' export enum ScopeNames { AVAILABLE_FOR_LIST_IDS = 'AVAILABLE_FOR_LIST_IDS', @@ -1301,16 +1302,25 @@ export class VideoModel extends Model { remote: false } }) - const totalVideos = await VideoModel.count() let totalLocalVideoViews = await VideoModel.sum('views', { where: { remote: false } }) + // Sequelize could return null... if (!totalLocalVideoViews) totalLocalVideoViews = 0 + const { total: totalVideos } = await VideoModel.listForApi({ + start: 0, + count: 0, + sort: '-publishedAt', + nsfw: buildNSFWFilter(), + includeLocalVideos: true, + withFiles: false + }) + return { totalLocalVideos, totalLocalVideoViews, @@ -1419,6 +1429,8 @@ export class VideoModel extends Model { } function getModels () { + if (options.count === 0) return Promise.resolve([]) + const { query, replacements, order } = buildListQuery(VideoModel, options) const queryModels = wrapForAPIResults(query, replacements, options, order) @@ -1849,7 +1861,8 @@ export class VideoModel extends Model { getVideoFileMetadataUrl (videoFile: MVideoFile, baseUrlHttp: string) { const path = '/api/v1/videos/' - return videoFile.metadata + + return this.isOwned() ? baseUrlHttp + path + this.uuid + '/metadata/' + videoFile.id : videoFile.metadataUrl }