From 7b87d2d5141d0eb48db2a3fd162208d6a79b2035 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Apr 2018 10:56:27 +0200 Subject: Handle sort in rss --- server/controllers/api/users.ts | 2 +- server/controllers/feeds.ts | 31 +++++++++++++++++++------------ server/models/video/video.ts | 4 ++-- 3 files changed, 22 insertions(+), 15 deletions(-) (limited to 'server') diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index abe6b3ff7..56cbf9448 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts @@ -161,7 +161,7 @@ export { async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { const user = res.locals.oauth.token.User as UserModel - const resultList = await VideoModel.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort) + const resultList = await VideoModel.listAccountVideosForApi(user.Account.id ,req.query.start, req.query.count, req.query.sort) return res.json(getFormattedObjects(resultList.data, resultList.total)) } diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index b9d4c5d50..700c50ec8 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts @@ -1,6 +1,12 @@ import * as express from 'express' import { CONFIG } from '../initializers' -import { asyncMiddleware, feedsValidator } from '../middlewares' +import { + asyncMiddleware, + feedsValidator, + setDefaultPagination, + setDefaultSort, + videosSortValidator +} from '../middlewares' import { VideoModel } from '../models/video/video' import * as Feed from 'pfeed' import { ResultList } from '../../shared/models' @@ -9,6 +15,8 @@ import { AccountModel } from '../models/account/account' const feedsRouter = express.Router() feedsRouter.get('/feeds/videos.:format', + videosSortValidator, + setDefaultSort, asyncMiddleware(feedsValidator), asyncMiddleware(generateFeed) ) @@ -23,26 +31,25 @@ export { async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) { let feed = initFeed() - let feedStart = 0 - let feedCount = 10 - let feedSort = '-createdAt' + const paginationStart = 0 + const paginationCount = 20 let resultList: ResultList const account: AccountModel = res.locals.account if (account) { - resultList = await VideoModel.listUserVideosForApi( + resultList = await VideoModel.listAccountVideosForApi( account.id, - feedStart, - feedCount, - feedSort, + paginationStart, + paginationCount, + req.query.sort, true ) } else { resultList = await VideoModel.listForApi( - feedStart, - feedCount, - feedSort, + paginationStart, + paginationCount, + req.query.sort, req.query.filter, true ) @@ -100,7 +107,7 @@ function initFeed () { rss: `${webserverUrl}/feeds/videos.xml` }, author: { - name: 'instance admin of ' + CONFIG.INSTANCE.NAME, + name: 'Instance admin of ' + CONFIG.INSTANCE.NAME, email: CONFIG.ADMIN.EMAIL, link: `${webserverUrl}/about` } diff --git a/server/models/video/video.ts b/server/models/video/video.ts index 240a2b5a2..ffb9725b4 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -640,7 +640,7 @@ export class VideoModel extends Model { }) } - static listUserVideosForApi (userId: number, start: number, count: number, sort: string, withFiles = false) { + static listAccountVideosForApi (accountId: number, start: number, count: number, sort: string, withFiles = false) { const query: IFindOptions = { offset: start, limit: count, @@ -653,7 +653,7 @@ export class VideoModel extends Model { { model: AccountModel, where: { - userId + id: accountId }, required: true } -- cgit v1.2.3