mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 19:42:24 +02:00
Add channelUpdatedAt list subscriptions sort
This commit is contained in:
parent
56419fd515
commit
e002b6fcd6
5 changed files with 36 additions and 26 deletions
|
@ -53,7 +53,8 @@ describe('Test users subscriptions', function () {
|
|||
command = servers[0].subscriptions
|
||||
})
|
||||
|
||||
describe('Destinction between server videos and user videos', function () {
|
||||
describe('Distinction between server videos and user videos', function () {
|
||||
|
||||
it('Should display videos of server 2 on server 1', async function () {
|
||||
const { total } = await servers[0].videos.list()
|
||||
|
||||
|
@ -161,6 +162,15 @@ describe('Test users subscriptions', function () {
|
|||
expect(body.data).to.have.lengthOf(0)
|
||||
}
|
||||
})
|
||||
|
||||
it('Should sort subscriptions by channelUpdatedAt', async function () {
|
||||
const body = await command.list({ token: users[0].accessToken, sort: '-channelUpdatedAt' })
|
||||
expect(body.total).to.equal(2)
|
||||
|
||||
const subscriptions = body.data
|
||||
expect(subscriptions[0].name).to.equal('user3_channel')
|
||||
expect(subscriptions[1].name).to.equal('root_channel')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Subscription videos', function () {
|
||||
|
|
|
@ -57,7 +57,7 @@ mySubscriptionsRouter.get('/me/subscriptions',
|
|||
setDefaultSort,
|
||||
setDefaultPagination,
|
||||
userSubscriptionListValidator,
|
||||
asyncMiddleware(getUserSubscriptions)
|
||||
asyncMiddleware(listUserSubscriptions)
|
||||
)
|
||||
|
||||
mySubscriptionsRouter.post('/me/subscriptions',
|
||||
|
@ -151,7 +151,7 @@ async function deleteUserSubscription (req: express.Request, res: express.Respon
|
|||
.end()
|
||||
}
|
||||
|
||||
async function getUserSubscriptions (req: express.Request, res: express.Response) {
|
||||
async function listUserSubscriptions (req: express.Request, res: express.Response) {
|
||||
const user = res.locals.oauth.token.User
|
||||
const actorId = user.Account.Actor.id
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ export const WEBSERVER = {
|
|||
// Sortable columns per schema
|
||||
export const SORTABLE_COLUMNS = {
|
||||
ADMIN_USERS: [ 'id', 'username', 'videoQuotaUsed', 'createdAt', 'lastLoginDate', 'role' ],
|
||||
USER_SUBSCRIPTIONS: [ 'id', 'createdAt' ],
|
||||
USER_SUBSCRIPTIONS: [ 'id', 'createdAt', 'channelUpdatedAt' ],
|
||||
ACCOUNTS: [ 'createdAt' ],
|
||||
JOBS: [ 'createdAt' ],
|
||||
VIDEO_CHANNELS: [ 'id', 'name', 'updatedAt', 'createdAt' ],
|
||||
|
|
|
@ -40,7 +40,7 @@ import {
|
|||
} from '../../initializers/constants.js'
|
||||
import { AccountModel } from '../account/account.js'
|
||||
import { ServerModel } from '../server/server.js'
|
||||
import { SequelizeModel, buildSQLAttributes, createSafeIn, getSort, searchAttribute, throwIfNotValid } from '../shared/index.js'
|
||||
import { SequelizeModel, buildSQLAttributes, createSafeIn, getSubscriptionSort, searchAttribute, throwIfNotValid } from '../shared/index.js'
|
||||
import { doesExist } from '../shared/query.js'
|
||||
import { VideoChannelModel } from '../video/video-channel.js'
|
||||
import { ActorModel, unusedActorAttributesForAPI } from './actor.js'
|
||||
|
@ -428,11 +428,11 @@ export class ActorFollowModel extends SequelizeModel<ActorFollowModel> {
|
|||
return {
|
||||
attributes: forCount === true
|
||||
? []
|
||||
: SORTABLE_COLUMNS.USER_SUBSCRIPTIONS,
|
||||
: SORTABLE_COLUMNS.USER_SUBSCRIPTIONS.filter(s => s !== 'channelUpdatedAt'),
|
||||
distinct: true,
|
||||
offset: start,
|
||||
limit: count,
|
||||
order: getSort(sort),
|
||||
order: getSubscriptionSort(sort),
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { literal, OrderItem, Sequelize } from 'sequelize'
|
||||
|
||||
// Translate for example "-name" to [ [ 'name', 'DESC' ], [ 'id', 'ASC' ] ]
|
||||
function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
export function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
let finalField: string | ReturnType<typeof Sequelize.col>
|
||||
|
@ -15,7 +15,7 @@ function getSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderIt
|
|||
return [ [ finalField, direction ], lastSort ]
|
||||
}
|
||||
|
||||
function getAdminUsersSort (value: string): OrderItem[] {
|
||||
export function getAdminUsersSort (value: string): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
let finalField: string | ReturnType<typeof Sequelize.col>
|
||||
|
@ -34,7 +34,7 @@ function getAdminUsersSort (value: string): OrderItem[] {
|
|||
return [ [ finalField as any, direction, nullPolicy ], [ 'id', 'ASC' ] ]
|
||||
}
|
||||
|
||||
function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
export function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
if (field.toLowerCase() === 'name') {
|
||||
|
@ -44,7 +44,7 @@ function getPlaylistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]):
|
|||
return getSort(value, lastSort)
|
||||
}
|
||||
|
||||
function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
export function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
if (field.toLowerCase() === 'trending') { // Sort by aggregation
|
||||
|
@ -81,7 +81,7 @@ function getVideoSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): Or
|
|||
return [ firstSort, lastSort ]
|
||||
}
|
||||
|
||||
function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
export function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
const videoFields = new Set([ 'name', 'duration', 'views', 'likes', 'dislikes', 'uuid' ])
|
||||
|
@ -96,7 +96,7 @@ function getBlacklistSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ])
|
|||
return getSort(value, lastSort)
|
||||
}
|
||||
|
||||
function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
export function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'ASC' ]): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
if (field === 'redundancyAllowed') {
|
||||
|
@ -109,7 +109,7 @@ function getInstanceFollowsSort (value: string, lastSort: OrderItem = [ 'id', 'A
|
|||
return getSort(value, lastSort)
|
||||
}
|
||||
|
||||
function getChannelSyncSort (value: string): OrderItem[] {
|
||||
export function getChannelSyncSort (value: string): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
if (field.toLowerCase() === 'videochannel') {
|
||||
return [
|
||||
|
@ -119,7 +119,18 @@ function getChannelSyncSort (value: string): OrderItem[] {
|
|||
return [ [ field, direction ] ]
|
||||
}
|
||||
|
||||
function buildSortDirectionAndField (value: string) {
|
||||
export function getSubscriptionSort (value: string): OrderItem[] {
|
||||
const { direction, field } = buildSortDirectionAndField(value)
|
||||
|
||||
if (field === 'channelUpdatedAt') {
|
||||
return [
|
||||
[ literal('"ActorFollowing.VideoChannel.updatedAt"'), direction ]
|
||||
]
|
||||
}
|
||||
return [ [ field, direction ] ]
|
||||
}
|
||||
|
||||
export function buildSortDirectionAndField (value: string) {
|
||||
let field: string
|
||||
let direction: 'ASC' | 'DESC'
|
||||
|
||||
|
@ -133,14 +144,3 @@ function buildSortDirectionAndField (value: string) {
|
|||
|
||||
return { direction, field }
|
||||
}
|
||||
|
||||
export {
|
||||
buildSortDirectionAndField,
|
||||
getPlaylistSort,
|
||||
getSort,
|
||||
getAdminUsersSort,
|
||||
getVideoSort,
|
||||
getBlacklistSort,
|
||||
getChannelSyncSort,
|
||||
getInstanceFollowsSort
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue